diff --git a/docs/SpacePort.pod b/docs/SpacePort.pod index a6ff0737..28d8d061 100644 --- a/docs/SpacePort.pod +++ b/docs/SpacePort.pod @@ -61,8 +61,8 @@ Shows you all your ships whatever they are doing. "name" : "Mars" } }, - { - "id" : "id-goes-here", + { + "id" : "id-goes-here", "name" : "F13", "type_human" : "Fighter", "type" : "fighter", @@ -85,11 +85,11 @@ Shows you all your ships whatever they are doing. "id" : "id-goes-here", "type" : "body", "name" : "Mars", - "x" : 4, - "y" : -3 + "x" : 4, + "y" : -3 } - }, + }, ... ], "number_of_ships" : 13, @@ -206,7 +206,87 @@ The unique id of the space port. Defaults to page 1. Shows 25 at a time. +=head2 get_fleet_for ( session_id, from_body_id, target ) + +Provides a summary of ships that can be included in a fleet action + + { + "ships" : [ + { + "type" : "sweeper", + "type_human" : "Sweeper", + "speed" : 10166, + "stealth" : 10948, + "combat" : 33372, + "quantity" : 103, + "estimated_travel_time" : "3654", + }, + { + "type" : "sweeper", + "type_human" : "Sweeper", + "speed" : 10166, + "stealth" : 10948, + "combat" : 25000, + "quantity" : 26, + "estimated_travel_time" : "3745", + }, + { + "type" : "surveyor", + "type_human" : "Surveyor", + "speed" : 9030, + "stealth" : 9030, + "combat" : 3220, + "quantity" : 24, + "estimated_travel_time" : "4123", + } + ... + ], + "status" : { ... } + } + +Ships are grouped according to type,speed,stealth and combat, the number of ships in each group is given. + +=head3 session_id + +A session id. + +=head3 from_body_id + +The unique id of the planet that should send the ships. + +=head3 target + +A hash reference that can contain one of five items to identify a star or body. + + { "body_name" : "Earth" } + + { "body_id" : "id-goes-here" } + + { "star_name" : "Sol" } + + { "star_id" : "id-goes-here" } + + { "x" : 4, "y" : -3 } + +=head4 body_name + +A string with the body's name. Case insensitive, but will throw an exception for misspelling. + +=head4 body_id +The unique id of the body. + +=head4 star_name + +A string with the star's name. Case insensitive, but will throw an exception for misspelling. + +=head4 star_id + +The unique id of the star. + +=head4 x | y + +A set of x,y coordinates to locate the star or body. =head2 get_ships_for ( session_id, from_body_id, target ) @@ -258,27 +338,27 @@ Provides a list of incoming ships and ships that are available to send to a spec ... ], "unavailable" : [ - { + { "reason" : [1009, "You can't send a detonator to a star."], - "ship" : { - "id" : "id-goes-here", - "name" : "D13", - "type_human" : "Detonator", - "type" : "detonator", - "task" : "Docked", - "speed" : "700", + "ship" : { + "id" : "id-goes-here", + "name" : "D13", + "type_human" : "Detonator", + "type" : "detonator", + "task" : "Docked", + "speed" : "700", "fleet_speed" : "0", - "stealth" : "0", - "hold_size" : "0", - "date_started" : "01 31 2010 13:09:05 +0600", - "date_available" : "01 31 2010 13:09:05 +0600" + "stealth" : "0", + "hold_size" : "0", + "date_started" : "01 31 2010 13:09:05 +0600", + "date_available" : "01 31 2010 13:09:05 +0600" } }, ... ], - "orbiting" : [ - { - "id" : "id-goes-here", + "orbiting" : [ + { + "id" : "id-goes-here", "name" : "F13", "type_human" : "Fighter", "type" : "fighter", @@ -299,13 +379,13 @@ Provides a list of incoming ships and ships that are available to send to a spec "id" : "id-goes-here", "type" : "body", "name" : "Mars", - "x" : 4, - "y" : -3, + "x" : 4, + "y" : -3, } - }, - ... - ], + }, + ... + ], "mining_platforms" : [ { empire_id => "id-goes-here", @@ -362,7 +442,6 @@ The unique id of the star. A set of x,y coordinates to locate the star or body. - =head2 send_ship ( session_id, ship_id, target ) Sends a ship to a specified body or star. Use with C. @@ -440,44 +519,138 @@ The unique id of the star. A set of x,y coordinates to locate the star or body. +=head2 send_ship_types ( session_id, from_body_id, target, types, arrival ) + +Sends a quantity of ships, of a specific type (type, speed, combat, stealth) to a target. + +Look at B for a summary of what ships can be sent. + +Returns the same as B showing how many ships are remaining to be sent. + +Throws 1002,1009,1010,1019 + +=head4 session_id + +A session ID. + +=head4 from_body_id + +The Unique ID of the body that should send the ships + +=head4 target + +A hash reference that can contain one of five items to identify a star or body. + + { "body_name" : "Earth" } + + { "body_id" : "id-goes-here" } + + { "star_name" : "Sol" } + + { "star_id" : "id-goes-here" } + + { "x" : 4, "y" : -3 } + +=head4 body_name + +A string with the body's name. Case insensitive, but will throw an exception for misspelling. + +=head4 body_id + +The unique id of the body. + +=head4 star_name + +A string with the star's name. Case insensitive, but will throw an exception for misspelling. + +=head4 star_id + +The unique id of the star. + +=head4 x | y + +A set of x,y coordinates to locate the star or body. + +=head4 types + +An array reference that contains the specification of the ships to send and the quantity. + + [ + { + "type" : "sweeper", + "speed" : 10166, + "stealth" : 10948, + "combat" : 33372, + "quantity" : 100 + }, + { + "type" : "surveyor", + "speed" : 9030, + "stealth" : 9030, + "combat" : 3220, + "quantity" : 10 + } + ] + +=head4 arrival + +A hash reference of the required arrival time. + + { + "day" : "23", + "hour" : "12", + "minute" : "01", + "second" : "30" + } + +So long as the sending body has that quantity of ships with those specifications, then the +ships will be sent. + +Ships will be set to arrive at the B time and date, which can be up to 28 days in +the future. B is the day of the month, either the remainder of the current month, or +the start of next month. e.g. if the current date is 23rd of January, then a B of 23 +will refer to today whereas 3 would refer to 3rd of February. + +If an arrival time is set which is prior to the earliest arrival time of the slowest ship, +then an exception is raised. =head2 send_fleet ( session_id, ship_ids, target, [ set_speed ] ) Sends a fleet of ships to a specified body or star. Use with C. - { + { "status" : { ... }, - "fleet" : [ - "ship" : { - "id" : "id-goes-here", - "name" : "P13", - "type_human" : "Probe", - "type" : "probe", - "task" : "Travelling", - "speed" : "1200", - "fleet_speed" : "250", - "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", - "can_recall" : "0", - "can_scuttle" : "0", - "from" : { - "id" : "id-goes-here", - "type" : "body", - "name" : "Earth" - }, - "to" : { - "id" : "id-goes-here", - "type" : "star", - "name" : "Sol" - } - }, - ... - ] - } + "fleet" : [ + "ship" : { + "id" : "id-goes-here", + "name" : "P13", + "type_human" : "Probe", + "type" : "probe", + "task" : "Travelling", + "speed" : "1200", + "fleet_speed" : "250", + "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", + "can_recall" : "0", + "can_scuttle" : "0", + "from" : { + "id" : "id-goes-here", + "type" : "body", + "name" : "Earth" + }, + "to" : { + "id" : "id-goes-here", + "type" : "star", + "name" : "Sol" + } + }, + ... + ] +} Throws 1002, 1009, 1010, 1016. @@ -485,7 +658,7 @@ Throws 1002, 1009, 1010, 1016. A session id. -=head3 ship_id +=head3 ship_ids An array reference of ship ids to send. diff --git a/lib/Lacuna/DB/Result/Ships.pm b/lib/Lacuna/DB/Result/Ships.pm index 57908408..45349bb7 100644 --- a/lib/Lacuna/DB/Result/Ships.pm +++ b/lib/Lacuna/DB/Result/Ships.pm @@ -174,7 +174,13 @@ sub can_recall { sub type_formatted { my $self = shift; - my $type = $self->type; + + return $self->type_human($self->type); +} + +sub type_human { + my ($self, $type) = @_; + $type =~ s/_/ /g; $type =~ s/\b(\w)/\u$1/g; return $type; @@ -276,7 +282,9 @@ sub send { $self->payload($options{payload} || {}); $self->roundtrip($options{roundtrip} || 0); $self->direction($options{direction} || 'out'); - $self->date_available(DateTime->now->add(seconds=>$self->calculate_travel_time($options{target}))); + my $arrival = $options{arrival} || DateTime->now->add(seconds=>$self->calculate_travel_time($options{target})); + $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}); @@ -336,11 +344,19 @@ sub land { sub calculate_travel_time { my ($self, $target) = @_; + my $distance = $self->body->calculate_distance_to_target($target); my $speed = $self->speed; if ( $self->fleet_speed > 0 && $self->fleet_speed < $self->speed ) { $speed = $self->fleet_speed; } + return $self->travel_time($self->body, $target, $speed); +} + +sub travel_time { + my ($class, $from, $target, $speed) = @_; + + my $distance = $from->calculate_distance_to_target($target); $speed ||= 1; my $hours = $distance / $speed; my $seconds = 60 * 60 * $hours; diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index f0e78911..bdfe3685 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -41,11 +41,55 @@ sub find_target { } } unless (defined $target) { - confess [ 1002, 'Could not find the target.', $target]; + confess [ 1002, 'Could not find the target.', $target]; } return $target; } +sub get_fleet_for { + my ($self, $session_id, $body_id, $target_params) = @_; + + my $empire = $self->get_empire_by_session($session_id); + my $body = $self->get_body($empire, $body_id); + my $target = $self->find_target($target_params); + + my $berth = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { + class => 'Lacuna::DB::Result::Building::SpacePort', + body_id => $body_id, + efficiency => 100, + } )->get_column('level')->max; + my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search( + { + body_id => $body->id, + task => 'docked', + },{ + '+select' => [{count => 'id'}], + '+as' => [ qw(quantity) ], + group_by => [ qw(type speed stealth combat hold_size) ], + }, + ); + my $summary; + while (my $ship_group = $ships->next) { + my $travel_time = Lacuna::DB::Result::Ships->travel_time($body,$target,$ship_group->speed); + my $type_human = Lacuna::DB::Result::Ships->type_human($ship_group->type); + my $summation = { + type => $ship_group->type, + type_human => $type_human, + speed => int($ship_group->speed), + stealth => int($ship_group->stealth), + combat => int($ship_group->combat), + quantity => $ship_group->get_column('quantity'), + estimated_travel_time => $travel_time, + }; + push @$summary, $summation; + } + my %out = ( + status => $self->format_status($empire, $body), + ships => $summary, + ); + return \%out; +} + sub get_ships_for { my ($self, $session_id, $body_id, $target_params) = @_; my $empire = $self->get_empire_by_session($session_id); @@ -55,12 +99,12 @@ sub get_ships_for { my @incoming; my $incoming_rs = $ships->search({ - task => 'Travelling', - direction => 'out', - 'body.empire_id' => $empire->id, - }, - { join => 'body' } - ); + task => 'Travelling', + direction => 'out', + 'body.empire_id' => $empire->id, + },{ + join => 'body', + }); if ($target->isa('Lacuna::DB::Result::Map::Star')) { $incoming_rs = $incoming_rs->search({foreign_star_id => $target->id}); } @@ -175,6 +219,113 @@ sub send_ship { } } +sub find_arrival { + my ($self, $arrival_params) = @_; + + my $now = DateTime->now; + my $year = $now->year, + my $month = $now->month; + my $mon_end = DateTime->last_day_of_month(year => $year, month => $month); + my $day = $arrival_params->{day}; + my $hour = $arrival_params->{hour}; + my $minute = $arrival_params->{minute}; + my $second = $arrival_params->{second}; + + if (not defined $day or $day < 1 or $day > $mon_end->day) { + confess [1009, 'Invalid day.']; + } + if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { + confess [1002, 'Invalid hour.']; + } + if (not defined $minute or $minute != int($minute) or $minute < 0 or $minute > 59) { + confess [1002, 'Invalid minute.']; + } + if (not defined $second or $second != int($second) or $second < 0 or $second > 59) { + confess [1002, 'Invalid second.']; + } + if ($day < $now->day) { + # Then it must be a day next month + $mon_end->add( days => $day); + $year = $mon_end->year; + $month = $mon_end->month; + } + my $arrival = DateTime->new( + year => $year, + month => $month, + day => $day, + hour => $hour, + minute => $minute, + second => $second, + ); + return $arrival; +} + +sub send_ship_types { + my ($self, $session_id, $from_body_id, $target_params, $type_params, $arrival) = @_; + + my $empire = $self->get_empire_by_session($session_id); + my $body = $self->get_body($empire, $body_id); + my $target = $self->find_target($target_params); + my $arrival = $self->find_arrival($arrival_params); + + # calculate the total ships before the expense of any database operations. + my $total_ships = 0; + map {$total_ships += $_->{quantity}} @$type_params; + my $max_ships = Lacuna->config->get('ships_per_fleet') || 20; + if ($total_ships > $max_ships) { + confess [1009, 'Too many ships for a fleet.']; + } + + my $ship_ref; + my $do_captcha_check = 0; + foreach my $type_param (@$type_params) { + foreach my $arg (qw(speed stealth combat quantity)) { + confess [1002, "$arg cannot be negative."] if $type_param->{$arg} < 0; + confess [1002, "$arg must be an integer."] if $type_param->{$arg} != int($type_param->{$arg}); + } + my $type = $type_param->{type}; + my $speed = $type_param->{speed}; + my $stealth = $type_param->{stealth}; + my $combat = $type_param->{combat}; + my $quantity = $type_param->{quantity}; + confess [1009, "Cannot send more than one excavator"] if ($type eq 'excavator' and $quantity > 1); + + # TODO Must check for valid berth levels + # + my $ships_rs = Lacuna->db->resultset('Ships')->search({ + body_id => $body->id, + task => 'Docked', + type => $type, + speed => $speed, + stealth => $stealth, + combat => $combat, + }); + if ($ships_rs->count < $quantity) { + confess [1009, "Cannot find $quantity of $type ships."]; + } + my @ships = $ships_rs->search(undef,{rows => $quantity}); + my $ship = $ships[0]; + # We only need to check one of the ships + $ship->can_send_to_target($target); + if (not $do_captcha_check and $ship->hostile_action) { + $do_captcha_check = 1; + } + foreach my $ship (@ships) { + my $hash = "${type}#${speed}#${stealth}#${combat}"; + $ship_ref->{$hash} = $ship; + } + } + if ($do_captcha_check) { + $empire->current_session->check_captcha; + } + # If we get here without exceptions, then all ships can be sent + foreach my $ship (values %$ship_ref) { + $ship->fleet_speed(1); + $ship->send(target => $target, arrival => $arrival); + } + +} + sub send_fleet { my ($self, $session_id, $ship_ids, $target_params, $set_speed) = @_; $set_speed //= 0; @@ -927,7 +1078,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_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 view_battle_logs)); +__PACKAGE__->register_rpc_method_names(qw(get_fleet_for 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 view_battle_logs)); no Moose; diff --git a/t/440_fleets.t b/t/440_fleets.t new file mode 100644 index 00000000..3e51eef0 --- /dev/null +++ b/t/440_fleets.t @@ -0,0 +1,32 @@ +use lib '../lib'; + +use strict; +use warnings; + +use Test::More tests => 10; +use Test::Deep; +use Data::Dumper; +use 5.010; +use DateTime; + +use TestHelper; +my $tester = TestHelper->new->use_existing_test_empire; +my $session_id = $tester->session->id; +my $empire = $tester->empire; +my $home = $empire->home_planet; +my $command = $home->command; + +my $result; + +my $space_port = Lacuna->db->resultset('Building')->search({ + class => 'Lacuna::DB::Result::Building::SpacePort', + body_id => $home->id, + },{ + rows => 1, +})->single; + +$result = $tester->post('spaceport','get_fleet_for', [$session_id, $home->id, {body_name => 'DeLambert-5-28'}]); + +END { +# TestHelper->clear_all_test_empires; +} -- 2.51.2 From a5170b1a3532500f00417efbb4e16e160f11fbb5 Mon Sep 17 00:00:00 2001 From: fireartist Date: Thu, 17 May 2012 16:32:42 +0100 Subject: [PATCH 002/105] forge: provide subsidy_cost in api forge/view --- lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm | 2 ++ lib/Lacuna/RPC/Building/TheDillonForge.pm | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm b/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm index 6fb8af5b..619ce72f 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm @@ -11,6 +11,8 @@ use Lacuna::Util qw(randint); use constant controller_class => 'Lacuna::RPC::Building::TheDillonForge'; +use constant subsidy_cost => 2; + around can_build => sub { my ($orig, $self, $body) = @_; confess [1013,"You can't build The Dillon Forge by any known process. How the hell did you manage to get a plan!?"]; diff --git a/lib/Lacuna/RPC/Building/TheDillonForge.pm b/lib/Lacuna/RPC/Building/TheDillonForge.pm index 028d54a0..a163598c 100644 --- a/lib/Lacuna/RPC/Building/TheDillonForge.pm +++ b/lib/Lacuna/RPC/Building/TheDillonForge.pm @@ -29,6 +29,7 @@ around 'view' => sub { else { $out->{tasks} = $self->_forge_tasks($building); } + $out->{subsidy_cost} = $building->subsidy_cost; return $out; }; @@ -135,12 +136,14 @@ sub subsidize { confess [1010, "Nothing is being done!"]; } - unless ($empire->essentia >= 2) { + my $subsidy_cost = $building->subsidy_cost; + + unless ($empire->essentia >= $subsidy_cost) { confess [1011, "Not enough essentia."]; } $building->finish_work->update; - $empire->spend_essentia(2, 'Dillon Forge subsidy after the fact'); + $empire->spend_essentia($subsidy_cost, 'Dillon Forge subsidy after the fact'); $empire->update; return $self->view($empire, $building); -- 2.51.2 From 5ff6681205fa0837e2e6055613f8f8ca89510670 Mon Sep 17 00:00:00 2001 From: fireartist Date: Thu, 17 May 2012 16:34:42 +0100 Subject: [PATCH 003/105] forge: update docs --- docs/TheDillonForge.pod | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/TheDillonForge.pod b/docs/TheDillonForge.pod index d7ff2e7b..3d47db58 100644 --- a/docs/TheDillonForge.pod +++ b/docs/TheDillonForge.pod @@ -15,6 +15,7 @@ This method is extended to include the list of tasks. "current_task" : "make_plan", "seconds_remaining" : 120, "can" : 0, + "subsidy_cost" : 2, "make_plan" : [ { -- 2.51.2 From 4c2f2a23735787d00ddccaaf183f756c66dc5b5d Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 13 May 2012 05:19:39 -0400 Subject: [PATCH 004/105] Started adding new fleet action API calls --- docs/SpacePort.pod | 289 +++++++++++++++++++++------ lib/Lacuna/DB/Result/Ships.pm | 20 +- lib/Lacuna/RPC/Building/SpacePort.pm | 167 +++++++++++++++- t/440_fleets.t | 32 +++ 4 files changed, 440 insertions(+), 68 deletions(-) create mode 100644 t/440_fleets.t diff --git a/docs/SpacePort.pod b/docs/SpacePort.pod index a6ff0737..28d8d061 100644 --- a/docs/SpacePort.pod +++ b/docs/SpacePort.pod @@ -61,8 +61,8 @@ Shows you all your ships whatever they are doing. "name" : "Mars" } }, - { - "id" : "id-goes-here", + { + "id" : "id-goes-here", "name" : "F13", "type_human" : "Fighter", "type" : "fighter", @@ -85,11 +85,11 @@ Shows you all your ships whatever they are doing. "id" : "id-goes-here", "type" : "body", "name" : "Mars", - "x" : 4, - "y" : -3 + "x" : 4, + "y" : -3 } - }, + }, ... ], "number_of_ships" : 13, @@ -206,7 +206,87 @@ The unique id of the space port. Defaults to page 1. Shows 25 at a time. +=head2 get_fleet_for ( session_id, from_body_id, target ) + +Provides a summary of ships that can be included in a fleet action + + { + "ships" : [ + { + "type" : "sweeper", + "type_human" : "Sweeper", + "speed" : 10166, + "stealth" : 10948, + "combat" : 33372, + "quantity" : 103, + "estimated_travel_time" : "3654", + }, + { + "type" : "sweeper", + "type_human" : "Sweeper", + "speed" : 10166, + "stealth" : 10948, + "combat" : 25000, + "quantity" : 26, + "estimated_travel_time" : "3745", + }, + { + "type" : "surveyor", + "type_human" : "Surveyor", + "speed" : 9030, + "stealth" : 9030, + "combat" : 3220, + "quantity" : 24, + "estimated_travel_time" : "4123", + } + ... + ], + "status" : { ... } + } + +Ships are grouped according to type,speed,stealth and combat, the number of ships in each group is given. + +=head3 session_id + +A session id. + +=head3 from_body_id + +The unique id of the planet that should send the ships. + +=head3 target + +A hash reference that can contain one of five items to identify a star or body. + + { "body_name" : "Earth" } + + { "body_id" : "id-goes-here" } + + { "star_name" : "Sol" } + + { "star_id" : "id-goes-here" } + + { "x" : 4, "y" : -3 } + +=head4 body_name + +A string with the body's name. Case insensitive, but will throw an exception for misspelling. + +=head4 body_id +The unique id of the body. + +=head4 star_name + +A string with the star's name. Case insensitive, but will throw an exception for misspelling. + +=head4 star_id + +The unique id of the star. + +=head4 x | y + +A set of x,y coordinates to locate the star or body. =head2 get_ships_for ( session_id, from_body_id, target ) @@ -258,27 +338,27 @@ Provides a list of incoming ships and ships that are available to send to a spec ... ], "unavailable" : [ - { + { "reason" : [1009, "You can't send a detonator to a star."], - "ship" : { - "id" : "id-goes-here", - "name" : "D13", - "type_human" : "Detonator", - "type" : "detonator", - "task" : "Docked", - "speed" : "700", + "ship" : { + "id" : "id-goes-here", + "name" : "D13", + "type_human" : "Detonator", + "type" : "detonator", + "task" : "Docked", + "speed" : "700", "fleet_speed" : "0", - "stealth" : "0", - "hold_size" : "0", - "date_started" : "01 31 2010 13:09:05 +0600", - "date_available" : "01 31 2010 13:09:05 +0600" + "stealth" : "0", + "hold_size" : "0", + "date_started" : "01 31 2010 13:09:05 +0600", + "date_available" : "01 31 2010 13:09:05 +0600" } }, ... ], - "orbiting" : [ - { - "id" : "id-goes-here", + "orbiting" : [ + { + "id" : "id-goes-here", "name" : "F13", "type_human" : "Fighter", "type" : "fighter", @@ -299,13 +379,13 @@ Provides a list of incoming ships and ships that are available to send to a spec "id" : "id-goes-here", "type" : "body", "name" : "Mars", - "x" : 4, - "y" : -3, + "x" : 4, + "y" : -3, } - }, - ... - ], + }, + ... + ], "mining_platforms" : [ { empire_id => "id-goes-here", @@ -362,7 +442,6 @@ The unique id of the star. A set of x,y coordinates to locate the star or body. - =head2 send_ship ( session_id, ship_id, target ) Sends a ship to a specified body or star. Use with C. @@ -440,44 +519,138 @@ The unique id of the star. A set of x,y coordinates to locate the star or body. +=head2 send_ship_types ( session_id, from_body_id, target, types, arrival ) + +Sends a quantity of ships, of a specific type (type, speed, combat, stealth) to a target. + +Look at B for a summary of what ships can be sent. + +Returns the same as B showing how many ships are remaining to be sent. + +Throws 1002,1009,1010,1019 + +=head4 session_id + +A session ID. + +=head4 from_body_id + +The Unique ID of the body that should send the ships + +=head4 target + +A hash reference that can contain one of five items to identify a star or body. + + { "body_name" : "Earth" } + + { "body_id" : "id-goes-here" } + + { "star_name" : "Sol" } + + { "star_id" : "id-goes-here" } + + { "x" : 4, "y" : -3 } + +=head4 body_name + +A string with the body's name. Case insensitive, but will throw an exception for misspelling. + +=head4 body_id + +The unique id of the body. + +=head4 star_name + +A string with the star's name. Case insensitive, but will throw an exception for misspelling. + +=head4 star_id + +The unique id of the star. + +=head4 x | y + +A set of x,y coordinates to locate the star or body. + +=head4 types + +An array reference that contains the specification of the ships to send and the quantity. + + [ + { + "type" : "sweeper", + "speed" : 10166, + "stealth" : 10948, + "combat" : 33372, + "quantity" : 100 + }, + { + "type" : "surveyor", + "speed" : 9030, + "stealth" : 9030, + "combat" : 3220, + "quantity" : 10 + } + ] + +=head4 arrival + +A hash reference of the required arrival time. + + { + "day" : "23", + "hour" : "12", + "minute" : "01", + "second" : "30" + } + +So long as the sending body has that quantity of ships with those specifications, then the +ships will be sent. + +Ships will be set to arrive at the B time and date, which can be up to 28 days in +the future. B is the day of the month, either the remainder of the current month, or +the start of next month. e.g. if the current date is 23rd of January, then a B of 23 +will refer to today whereas 3 would refer to 3rd of February. + +If an arrival time is set which is prior to the earliest arrival time of the slowest ship, +then an exception is raised. =head2 send_fleet ( session_id, ship_ids, target, [ set_speed ] ) Sends a fleet of ships to a specified body or star. Use with C. - { + { "status" : { ... }, - "fleet" : [ - "ship" : { - "id" : "id-goes-here", - "name" : "P13", - "type_human" : "Probe", - "type" : "probe", - "task" : "Travelling", - "speed" : "1200", - "fleet_speed" : "250", - "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", - "can_recall" : "0", - "can_scuttle" : "0", - "from" : { - "id" : "id-goes-here", - "type" : "body", - "name" : "Earth" - }, - "to" : { - "id" : "id-goes-here", - "type" : "star", - "name" : "Sol" - } - }, - ... - ] - } + "fleet" : [ + "ship" : { + "id" : "id-goes-here", + "name" : "P13", + "type_human" : "Probe", + "type" : "probe", + "task" : "Travelling", + "speed" : "1200", + "fleet_speed" : "250", + "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", + "can_recall" : "0", + "can_scuttle" : "0", + "from" : { + "id" : "id-goes-here", + "type" : "body", + "name" : "Earth" + }, + "to" : { + "id" : "id-goes-here", + "type" : "star", + "name" : "Sol" + } + }, + ... + ] +} Throws 1002, 1009, 1010, 1016. @@ -485,7 +658,7 @@ Throws 1002, 1009, 1010, 1016. A session id. -=head3 ship_id +=head3 ship_ids An array reference of ship ids to send. diff --git a/lib/Lacuna/DB/Result/Ships.pm b/lib/Lacuna/DB/Result/Ships.pm index b2637bef..f6941df7 100644 --- a/lib/Lacuna/DB/Result/Ships.pm +++ b/lib/Lacuna/DB/Result/Ships.pm @@ -174,7 +174,13 @@ sub can_recall { sub type_formatted { my $self = shift; - my $type = $self->type; + + return $self->type_human($self->type); +} + +sub type_human { + my ($self, $type) = @_; + $type =~ s/_/ /g; $type =~ s/\b(\w)/\u$1/g; return $type; @@ -279,7 +285,9 @@ sub send { $self->payload($options{payload} || {}); $self->roundtrip($options{roundtrip} || 0); $self->direction($options{direction} || 'out'); - $self->date_available(DateTime->now->add(seconds=>$self->calculate_travel_time($options{target}))); + my $arrival = $options{arrival} || DateTime->now->add(seconds=>$self->calculate_travel_time($options{target})); + $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}); @@ -339,11 +347,19 @@ sub land { sub calculate_travel_time { my ($self, $target) = @_; + my $distance = $self->body->calculate_distance_to_target($target); my $speed = $self->speed; if ( $self->fleet_speed > 0 && $self->fleet_speed < $self->speed ) { $speed = $self->fleet_speed; } + return $self->travel_time($self->body, $target, $speed); +} + +sub travel_time { + my ($class, $from, $target, $speed) = @_; + + my $distance = $from->calculate_distance_to_target($target); $speed ||= 1; my $hours = $distance / $speed; my $seconds = 60 * 60 * $hours; diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index f0e78911..bdfe3685 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -41,11 +41,55 @@ sub find_target { } } unless (defined $target) { - confess [ 1002, 'Could not find the target.', $target]; + confess [ 1002, 'Could not find the target.', $target]; } return $target; } +sub get_fleet_for { + my ($self, $session_id, $body_id, $target_params) = @_; + + my $empire = $self->get_empire_by_session($session_id); + my $body = $self->get_body($empire, $body_id); + my $target = $self->find_target($target_params); + + my $berth = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { + class => 'Lacuna::DB::Result::Building::SpacePort', + body_id => $body_id, + efficiency => 100, + } )->get_column('level')->max; + my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search( + { + body_id => $body->id, + task => 'docked', + },{ + '+select' => [{count => 'id'}], + '+as' => [ qw(quantity) ], + group_by => [ qw(type speed stealth combat hold_size) ], + }, + ); + my $summary; + while (my $ship_group = $ships->next) { + my $travel_time = Lacuna::DB::Result::Ships->travel_time($body,$target,$ship_group->speed); + my $type_human = Lacuna::DB::Result::Ships->type_human($ship_group->type); + my $summation = { + type => $ship_group->type, + type_human => $type_human, + speed => int($ship_group->speed), + stealth => int($ship_group->stealth), + combat => int($ship_group->combat), + quantity => $ship_group->get_column('quantity'), + estimated_travel_time => $travel_time, + }; + push @$summary, $summation; + } + my %out = ( + status => $self->format_status($empire, $body), + ships => $summary, + ); + return \%out; +} + sub get_ships_for { my ($self, $session_id, $body_id, $target_params) = @_; my $empire = $self->get_empire_by_session($session_id); @@ -55,12 +99,12 @@ sub get_ships_for { my @incoming; my $incoming_rs = $ships->search({ - task => 'Travelling', - direction => 'out', - 'body.empire_id' => $empire->id, - }, - { join => 'body' } - ); + task => 'Travelling', + direction => 'out', + 'body.empire_id' => $empire->id, + },{ + join => 'body', + }); if ($target->isa('Lacuna::DB::Result::Map::Star')) { $incoming_rs = $incoming_rs->search({foreign_star_id => $target->id}); } @@ -175,6 +219,113 @@ sub send_ship { } } +sub find_arrival { + my ($self, $arrival_params) = @_; + + my $now = DateTime->now; + my $year = $now->year, + my $month = $now->month; + my $mon_end = DateTime->last_day_of_month(year => $year, month => $month); + my $day = $arrival_params->{day}; + my $hour = $arrival_params->{hour}; + my $minute = $arrival_params->{minute}; + my $second = $arrival_params->{second}; + + if (not defined $day or $day < 1 or $day > $mon_end->day) { + confess [1009, 'Invalid day.']; + } + if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { + confess [1002, 'Invalid hour.']; + } + if (not defined $minute or $minute != int($minute) or $minute < 0 or $minute > 59) { + confess [1002, 'Invalid minute.']; + } + if (not defined $second or $second != int($second) or $second < 0 or $second > 59) { + confess [1002, 'Invalid second.']; + } + if ($day < $now->day) { + # Then it must be a day next month + $mon_end->add( days => $day); + $year = $mon_end->year; + $month = $mon_end->month; + } + my $arrival = DateTime->new( + year => $year, + month => $month, + day => $day, + hour => $hour, + minute => $minute, + second => $second, + ); + return $arrival; +} + +sub send_ship_types { + my ($self, $session_id, $from_body_id, $target_params, $type_params, $arrival) = @_; + + my $empire = $self->get_empire_by_session($session_id); + my $body = $self->get_body($empire, $body_id); + my $target = $self->find_target($target_params); + my $arrival = $self->find_arrival($arrival_params); + + # calculate the total ships before the expense of any database operations. + my $total_ships = 0; + map {$total_ships += $_->{quantity}} @$type_params; + my $max_ships = Lacuna->config->get('ships_per_fleet') || 20; + if ($total_ships > $max_ships) { + confess [1009, 'Too many ships for a fleet.']; + } + + my $ship_ref; + my $do_captcha_check = 0; + foreach my $type_param (@$type_params) { + foreach my $arg (qw(speed stealth combat quantity)) { + confess [1002, "$arg cannot be negative."] if $type_param->{$arg} < 0; + confess [1002, "$arg must be an integer."] if $type_param->{$arg} != int($type_param->{$arg}); + } + my $type = $type_param->{type}; + my $speed = $type_param->{speed}; + my $stealth = $type_param->{stealth}; + my $combat = $type_param->{combat}; + my $quantity = $type_param->{quantity}; + confess [1009, "Cannot send more than one excavator"] if ($type eq 'excavator' and $quantity > 1); + + # TODO Must check for valid berth levels + # + my $ships_rs = Lacuna->db->resultset('Ships')->search({ + body_id => $body->id, + task => 'Docked', + type => $type, + speed => $speed, + stealth => $stealth, + combat => $combat, + }); + if ($ships_rs->count < $quantity) { + confess [1009, "Cannot find $quantity of $type ships."]; + } + my @ships = $ships_rs->search(undef,{rows => $quantity}); + my $ship = $ships[0]; + # We only need to check one of the ships + $ship->can_send_to_target($target); + if (not $do_captcha_check and $ship->hostile_action) { + $do_captcha_check = 1; + } + foreach my $ship (@ships) { + my $hash = "${type}#${speed}#${stealth}#${combat}"; + $ship_ref->{$hash} = $ship; + } + } + if ($do_captcha_check) { + $empire->current_session->check_captcha; + } + # If we get here without exceptions, then all ships can be sent + foreach my $ship (values %$ship_ref) { + $ship->fleet_speed(1); + $ship->send(target => $target, arrival => $arrival); + } + +} + sub send_fleet { my ($self, $session_id, $ship_ids, $target_params, $set_speed) = @_; $set_speed //= 0; @@ -927,7 +1078,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_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 view_battle_logs)); +__PACKAGE__->register_rpc_method_names(qw(get_fleet_for 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 view_battle_logs)); no Moose; diff --git a/t/440_fleets.t b/t/440_fleets.t new file mode 100644 index 00000000..3e51eef0 --- /dev/null +++ b/t/440_fleets.t @@ -0,0 +1,32 @@ +use lib '../lib'; + +use strict; +use warnings; + +use Test::More tests => 10; +use Test::Deep; +use Data::Dumper; +use 5.010; +use DateTime; + +use TestHelper; +my $tester = TestHelper->new->use_existing_test_empire; +my $session_id = $tester->session->id; +my $empire = $tester->empire; +my $home = $empire->home_planet; +my $command = $home->command; + +my $result; + +my $space_port = Lacuna->db->resultset('Building')->search({ + class => 'Lacuna::DB::Result::Building::SpacePort', + body_id => $home->id, + },{ + rows => 1, +})->single; + +$result = $tester->post('spaceport','get_fleet_for', [$session_id, $home->id, {body_name => 'DeLambert-5-28'}]); + +END { +# TestHelper->clear_all_test_empires; +} -- 2.51.2 From 33662c408d87f1bbda263be3766a433edafdd92f Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 13 May 2012 13:48:35 -0400 Subject: [PATCH 005/105] Minor changes --- lib/Lacuna/RPC/Building/SpacePort.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index bdfe3685..70adba11 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -261,7 +261,7 @@ sub find_arrival { } sub send_ship_types { - my ($self, $session_id, $from_body_id, $target_params, $type_params, $arrival) = @_; + my ($self, $session_id, $body_id, $target_params, $type_params, $arrival) = @_; my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); @@ -323,7 +323,7 @@ sub send_ship_types { $ship->fleet_speed(1); $ship->send(target => $target, arrival => $arrival); } - + return $self->get_fleet_for($session, $body_id, $target_params); } sub send_fleet { -- 2.51.2 From 85e7bb7caa3851b2bca7c6565b2d28c55358388f Mon Sep 17 00:00:00 2001 From: ian docherty Date: Tue, 15 May 2012 05:09:30 -0400 Subject: [PATCH 006/105] Fix error checking for send_ship_types --- lib/Lacuna/RPC/Building/SpacePort.pm | 16 +++++++++------- t/440_fleets.t | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 70adba11..2ad54116 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -6,6 +6,8 @@ no warnings qw(uninitialized); extends 'Lacuna::RPC::Building'; use Lacuna::Constants qw(SHIP_TYPES); use Lacuna::Util qw(format_date); +use Data::Dumper; + use feature "switch"; sub app_url { @@ -232,7 +234,7 @@ sub find_arrival { my $second = $arrival_params->{second}; if (not defined $day or $day < 1 or $day > $mon_end->day) { - confess [1009, 'Invalid day.']; + confess [1009, "Invalid day. [$day][".Dumper($arrival_params)."]"]; } if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { confess [1002, 'Invalid hour.']; @@ -240,8 +242,8 @@ sub find_arrival { if (not defined $minute or $minute != int($minute) or $minute < 0 or $minute > 59) { confess [1002, 'Invalid minute.']; } - if (not defined $second or $second != int($second) or $second < 0 or $second > 59) { - confess [1002, 'Invalid second.']; + if (not defined $second or $second != 0 and $second != 15 and $second != 30 and $second != 45) { + confess [1002, 'Invalid second. Must be 0, 15, 30 or 45']; } if ($day < $now->day) { # Then it must be a day next month @@ -261,7 +263,7 @@ sub find_arrival { } sub send_ship_types { - my ($self, $session_id, $body_id, $target_params, $type_params, $arrival) = @_; + my ($self, $session_id, $body_id, $target_params, $type_params, $arrival_params) = @_; my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); @@ -323,7 +325,7 @@ sub send_ship_types { $ship->fleet_speed(1); $ship->send(target => $target, arrival => $arrival); } - return $self->get_fleet_for($session, $body_id, $target_params); + return $self->get_fleet_for($session_id, $body_id, $target_params); } sub send_fleet { @@ -331,7 +333,7 @@ sub send_fleet { $set_speed //= 0; my $empire = $self->get_empire_by_session($session_id); my $target = $self->find_target($target_params); - my $max_ships = Lacuna->config->get('ships_per_fleet') || 20; + my $max_ships = Lacuna->config->get('ships_per_fleet') || 50; if (@$ship_ids > $max_ships) { confess [1009, 'Too many ships for a fleet.']; } @@ -1078,7 +1080,7 @@ around 'view' => sub { return $out; }; -__PACKAGE__->register_rpc_method_names(qw(get_fleet_for 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 view_battle_logs)); +__PACKAGE__->register_rpc_method_names(qw(send_ship_types get_fleet_for 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 view_battle_logs)); no Moose; diff --git a/t/440_fleets.t b/t/440_fleets.t index 3e51eef0..d4113cd9 100644 --- a/t/440_fleets.t +++ b/t/440_fleets.t @@ -27,6 +27,23 @@ my $space_port = Lacuna->db->resultset('Building')->search({ $result = $tester->post('spaceport','get_fleet_for', [$session_id, $home->id, {body_name => 'DeLambert-5-28'}]); +my ($sweepers) = grep {$_->{type} eq 'sweeper'} @{$result->{result}{ships}}; + +diag Dumper(\$sweepers); + +Lacuna->cache->set('captcha', $session_id, { guid => 1111, solution => 1111 }, 60 * 30 ); +$result = $tester->post('captcha','solve', [$session_id, 1111, 1111]); +is($result->{result}, 1, 'Solved captcha'); + + +$result = $tester->post('spaceport','send_ship_types', [ + $session_id, + $home->id, + {body_name => 'DeLambert-5-28'}, + [{type => 'sweeper', speed => $sweepers->{speed}, stealth => $sweepers->{stealth}, combat => $sweepers->{combat}, quantity => 10}], + {day => 10, hour => 1, minute => 1, second => 15}, +]); + END { # TestHelper->clear_all_test_empires; } -- 2.51.2 From 5c802fe6040364591c0b84bbd10df6b580646d51 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Thu, 17 May 2012 14:30:27 -0400 Subject: [PATCH 007/105] Send all ships in the fleet, not just one. --- lib/Lacuna/RPC/Building/SpacePort.pm | 3 +-- t/440_fleets.t | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 2ad54116..63baa8d7 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -313,8 +313,7 @@ sub send_ship_types { $do_captcha_check = 1; } foreach my $ship (@ships) { - my $hash = "${type}#${speed}#${stealth}#${combat}"; - $ship_ref->{$hash} = $ship; + $ship_ref->{$ship->id} = $ship; } } if ($do_captcha_check) { diff --git a/t/440_fleets.t b/t/440_fleets.t index d4113cd9..787056fe 100644 --- a/t/440_fleets.t +++ b/t/440_fleets.t @@ -41,7 +41,7 @@ $result = $tester->post('spaceport','send_ship_types', [ $home->id, {body_name => 'DeLambert-5-28'}, [{type => 'sweeper', speed => $sweepers->{speed}, stealth => $sweepers->{stealth}, combat => $sweepers->{combat}, quantity => 10}], - {day => 10, hour => 1, minute => 1, second => 15}, + {day => 10, hour => 0, minute => 0, second => 0}, ]); END { -- 2.51.2 From e610579b7170b6d7bd981372fdabad3b031a681c Mon Sep 17 00:00:00 2001 From: fireartist Date: Thu, 17 May 2012 21:25:15 +0100 Subject: [PATCH 008/105] supply-chain: fix method-name typo --- lib/Lacuna/DB/Result/Building/Trade.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Lacuna/DB/Result/Building/Trade.pm b/lib/Lacuna/DB/Result/Building/Trade.pm index 47b82907..4c50708b 100644 --- a/lib/Lacuna/DB/Result/Building/Trade.pm +++ b/lib/Lacuna/DB/Result/Building/Trade.pm @@ -212,7 +212,7 @@ sub remove_supply_chain { if ($self->supply_chains->count == 1) { my $ships = $self->supply_ships; while (my $ship = $ships->next) { - $self->sent_supply_ship_home($supply_chain->target, $ship); + $self->send_supply_ship_home($supply_chain->target, $ship); } } $supply_chain->delete; -- 2.51.2 From 6ca7a602538221997b01fc9108e2d3ef18bfac27 Mon Sep 17 00:00:00 2001 From: fireartist Date: Fri, 18 May 2012 15:23:28 +0100 Subject: [PATCH 009/105] forge: move 'subsidy_cost' value into 'tasks' block --- lib/Lacuna/RPC/Building/TheDillonForge.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Lacuna/RPC/Building/TheDillonForge.pm b/lib/Lacuna/RPC/Building/TheDillonForge.pm index a163598c..cbab7eb6 100644 --- a/lib/Lacuna/RPC/Building/TheDillonForge.pm +++ b/lib/Lacuna/RPC/Building/TheDillonForge.pm @@ -29,7 +29,7 @@ around 'view' => sub { else { $out->{tasks} = $self->_forge_tasks($building); } - $out->{subsidy_cost} = $building->subsidy_cost; + $out->{tasks}{subsidy_cost} = $building->subsidy_cost; return $out; }; -- 2.51.2 From a6079c4356e23d4a4bb0a7c84173c818de16a910 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 20 May 2012 11:07:26 -0600 Subject: [PATCH 010/105] Had less than greater than switched. --- lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm b/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm index 6f2f3cb5..dcafff1d 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm @@ -24,7 +24,7 @@ before 'can_demolish' => sub { my $self = shift; my $body = $self->body; my $buildings = $body->buildings; - return if ($body->orbit > $body->empire->max_orbit || $body->orbit < $body->empire->min_orbit); + return if ($body->orbit < $body->empire->max_orbit || $body->orbit > $body->empire->min_orbit); my $tp_blds = $buildings->search({ class => 'Lacuna::DB::Result::Building::Permanent::TerraformingPlatform' }); -- 2.51.2 From a0dc3be12f5da5fd84c930e98601b59cbe532af8 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 20 May 2012 11:37:41 -0600 Subject: [PATCH 011/105] and... --- lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm b/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm index dcafff1d..584c3267 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm @@ -24,7 +24,7 @@ before 'can_demolish' => sub { my $self = shift; my $body = $self->body; my $buildings = $body->buildings; - return if ($body->orbit < $body->empire->max_orbit || $body->orbit > $body->empire->min_orbit); + return if ($body->orbit > $body->empire->min_orbit && $body->orbit < $body->empire->max_orbit); my $tp_blds = $buildings->search({ class => 'Lacuna::DB::Result::Building::Permanent::TerraformingPlatform' }); -- 2.51.2 From 3480f814555b7fd91f4627935ea515f8eb99224b Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 20 May 2012 12:03:20 -0600 Subject: [PATCH 012/105] Initialize undefined array. --- lib/Lacuna/Role/Container.pm | 37 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/Lacuna/Role/Container.pm b/lib/Lacuna/Role/Container.pm index ae51ba46..ad98e0c0 100644 --- a/lib/Lacuna/Role/Container.pm +++ b/lib/Lacuna/Role/Container.pm @@ -112,7 +112,7 @@ sub unload { sub format_description_of_payload { my ($self) = @_; - my $item_arr; + my $item_arr = []; my $scratch; my $payload = $self->payload; @@ -166,32 +166,35 @@ sub format_description_of_payload { undef $scratch; my $spies = Lacuna->db->resultset('Lacuna::DB::Result::Spies'); if (exists $payload->{spies}) { - foreach my $id (@{$payload->{spies}}) { - my $spy = $spies->find($id); - next unless defined $spy; - push @{$scratch}, 'Level '.$spy->level.' spy named '.$spy->name . ' (transport)'; - } + foreach my $id (@{$payload->{spies}}) { + my $spy = $spies->find($id); + next unless defined $spy; + push @{$scratch}, 'Level '.$spy->level.' spy named '.$spy->name . ' (transport)'; + } + push @{$item_arr}, @{consolidate_items($scratch)} if (defined($scratch)); } - push @{$item_arr}, @{consolidate_items($scratch)} if (defined($scratch)); # prisoners undef $scratch; if (exists $payload->{prisoners}) { - foreach my $id (@{$payload->{prisoners}}) { - my $spy = $spies->find($id); - next unless defined $spy; - push @{$scratch}, 'Level '.$spy->level.' spy named '.$spy->name . ' (prisoner) sentence expires '.$spy->format_available_on; - } + foreach my $id (@{$payload->{prisoners}}) { + my $spy = $spies->find($id); + next unless defined $spy; + push @{$scratch}, + 'Level '.$spy->level.' spy named '.$spy->name . + ' (prisoner) sentence expires '.$spy->format_available_on; + } + push @{$item_arr}, @{consolidate_items($scratch)} if (defined($scratch)); } - push @{$item_arr}, @{consolidate_items($scratch)} if (defined($scratch)); # fetch spies undef $scratch; if (exists $payload->{fetch_spies}) { - foreach my $id (@{$payload->{fetch_spies}}) { - my $spy = $spies->find($id); - push @{$scratch}, 'Level '.$spy->level.' spy named '.$spy->name . ' (fetch upon arrival)'; - } + foreach my $id (@{$payload->{fetch_spies}}) { + my $spy = $spies->find($id); + push @{$scratch}, 'Level '.$spy->level.' spy named '.$spy->name . ' (fetch upon arrival)'; + } + push @{$item_arr}, @{consolidate_items($scratch)} if (defined($scratch)); } return $item_arr; -- 2.51.2 From 5077e97a2233b869c6bb8ad69fd9e4144662f22c Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 20 May 2012 13:30:43 -0600 Subject: [PATCH 013/105] Updated to show quantity of plans returned. --- docs/PlanetaryCommand.pod | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/PlanetaryCommand.pod b/docs/PlanetaryCommand.pod index 1ef53722..ffc2ccf8 100644 --- a/docs/PlanetaryCommand.pod +++ b/docs/PlanetaryCommand.pod @@ -62,6 +62,7 @@ Returns a list of all the plans you've collected through various means. "status" : { ... }, "plans" : [ { + "quantity" : 23, "name" : "Malcud Fungus Farm", "level" : 1, "extra_build_level" : 5 @@ -82,4 +83,4 @@ A session id. The unique id of the PCC. -=cut \ No newline at end of file +=cut -- 2.51.2 From f09ddfe3d2950014794c1828ae137f1dae2e761c Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 20 May 2012 16:27:56 -0400 Subject: [PATCH 014/105] Efficiency changes Change retention policy for email Remove multiple calls to DB for supply chains --- bin/clean_up_mail.pl | 18 ++++++++++++----- bin/run_daily.sh | 1 + bin/run_weekly.sh | 1 - lib/Lacuna/DB/Result/Map/Body/Planet.pm | 26 ++++++++++++------------- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/bin/clean_up_mail.pl b/bin/clean_up_mail.pl index 2d249f80..a5247c84 100644 --- a/bin/clean_up_mail.pl +++ b/bin/clean_up_mail.pl @@ -21,15 +21,23 @@ my $date_ended = DateTime->now->subtract( days => 7 ); out('Loading DB'); our $db = Lacuna->db; -out('Deleting AI Mail Items'); +out('Deleting AI Mail Items older than a day'); +my $date_ended = DateTime->now->subtract( days => 1 ); my $mail = $db->resultset('Lacuna::DB::Result::Message'); -$mail->search({ to_id => { '<=' => 1 }})->delete; +$mail->search({ to_id => { '<=' => 1 }, date_sent => { '<' => $date_ended }})->delete; -out('Deleting Outdated Trashed Player Mail Items'); -$mail->search({ has_trashed => 1, date_sent => { '<' => $date_ended }})->delete; +out('Deleting Trashed Player Mail Items'); +$mail->search({ has_trashed => 1 })->delete; -my $date_ended = DateTime->now->subtract( days => 30 ); +$date_ended = DateTime->now->subtract( days => 3 ); +out('Deleting Outdated Parliament Items'); +$mail->search({ tag => 'Parliament', date_sent => { '<' => $date_ended }})->delete; +$date_ended = DateTime->now->subtract( days => 7 ); +out('Deleting Outdated Player Read Items'); +$mail->search({ has_read => 1, has_archived => 0, date_sent => { '<' => $date_ended }})->delete; + +$date_ended = DateTime->now->subtract( days => 30 ); out('Deleting All Outdated Player Mail Items'); $mail->search({ date_sent => { '<' => $date_ended }})->delete; diff --git a/bin/run_daily.sh b/bin/run_daily.sh index f98cc6d8..18c11e78 100755 --- a/bin/run_daily.sh +++ b/bin/run_daily.sh @@ -6,6 +6,7 @@ perl determine_lottery_winner.pl perl alert_inactive_users.pl perl rotate_taxes_paid.pl perl diablotin/send_attack.pl --randomize& +perl clean_up_mail.pl #perl saben/send_attack.pl --randomize& #perl trelvestian/check_for_total_victory.pl diff --git a/bin/run_weekly.sh b/bin/run_weekly.sh index a951329f..05d63e2f 100644 --- a/bin/run_weekly.sh +++ b/bin/run_weekly.sh @@ -3,5 +3,4 @@ export PATH=/data/apps/bin:$PATH cd /data/Lacuna-Server/bin perl weekly_medals.pl >> /tmp/weekly_medals.log 2>> /tmp/weekly_medals.log perl trelvestian/reset_essentia_veins.pl -perl clean_up_mail.pl perl clean_up_battle_log.pl diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index e7ccc21d..4296d92e 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -1370,44 +1370,42 @@ sub tick_to { } # deal with negative amounts stored # and deal with any supply-chains + my @supply_chains = $self->out_supply_chains->all; + if ($self->water_stored <= 0) { $self->water_stored(0); - $self->toggle_supply_chain('water', 1) + $self->toggle_supply_chain(\@supply_chains, 'water', 1) } else { - $self->toggle_supply_chain('water', 0); + $self->toggle_supply_chain(\@supply_chains, 'water', 0); } if ($self->energy_stored <= 0) { $self->energy_stored(0); - $self->toggle_supply_chain('energy', 1); + $self->toggle_supply_chain(\@supply_chains, 'energy', 1); } else { - $self->toggle_supply_chain('energy', 0); + $self->toggle_supply_chain(\@supply_chains, 'energy', 0); } for my $type (FOOD_TYPES, ORE_TYPES) { my $stype = $type.'_stored'; if ($self->$stype <= 0) { $self->$stype(0); - $self->toggle_supply_chain($type, 1); + $self->toggle_supply_chain(\@supply_chains, $type, 1); } else { - $self->toggle_supply_chain($type, 0); + $self->toggle_supply_chain(\@supply_chains, $type, 0); } } $self->update; } sub toggle_supply_chain { - my ($self, $resource, $new_state) = @_; + my ($self, $chains_ref, $resource, $new_state) = @_; - my $chain_rs = $self->out_supply_chains->search({ - stalled => $new_state ? 0 : 1, - resource_type => $resource, - },{ - prefetch => 'target', - }); - while (my $chain = $chain_rs->next) { + my @chains = grep {$_->stalled == $new_state ? 0 : 1, $_->resource_type eq $resource } @$chains_ref; + + foreach my $chain (@chains) { $chain->stalled($new_state); $chain->update; $chain->target->needs_recalc(1); -- 2.51.2 From d0f9a01f414a5834c9307cb234816cebdd2d849c Mon Sep 17 00:00:00 2001 From: ian docherty Date: Mon, 21 May 2012 13:15:58 -0400 Subject: [PATCH 015/105] More efficiency savings with buildings cache --- lib/Lacuna/AI.pm | 4 +- lib/Lacuna/DB/Result/Building.pm | 11 +- lib/Lacuna/DB/Result/Building/Archaeology.pm | 7 +- .../Building/Permanent/HallsOfVrbansk.pm | 5 +- lib/Lacuna/DB/Result/Map/Body.pm | 36 +++++- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 112 ++++++++---------- lib/Lacuna/RPC/Body.pm | 3 + lib/Lacuna/RPC/Building/HallsOfVrbansk.pm | 3 +- lib/Lacuna/Role/Ship/Arrive/DeployProbe.pm | 2 +- lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm | 31 +++-- 10 files changed, 119 insertions(+), 95 deletions(-) diff --git a/lib/Lacuna/AI.pm b/lib/Lacuna/AI.pm index 8b8c8c27..7cbcf004 100644 --- a/lib/Lacuna/AI.pm +++ b/lib/Lacuna/AI.pm @@ -343,7 +343,7 @@ sub train_spies { sub build_ships { my ($self, $colony) = @_; say 'BUILD SHIPS'; - my @shipyards = $colony->get_buildings_of_class('Lacuna::DB::Result::Building::Shipyard')->search(undef,{order_by => 'work_ends'})->all; + my @shipyards = sort {$a->work_ends cmp $b->work_ends} $colony->get_buildings_of_class('Lacuna::DB::Result::Building::Shipyard'); my @priorities = $self->ship_building_priorities($colony); my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships'); foreach my $priority (@priorities) { @@ -376,7 +376,7 @@ sub build_ships { sub build_ships_max { my ($self, $colony) = @_; say 'BUILD SHIPS'; - my @ship_yards = $colony->get_buildings_of_class('Lacuna::DB::Result::Building::Shipyard')->search(undef,{order_by => 'work_ends'})->all; + my @ship_yards = sort {$a->work_ends cmp $b->work_ends} $colony->get_buildings_of_class('Lacuna::DB::Result::Building::Shipyard'); my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships'); my $ship_yard = shift @ship_yards; my $free_docks = $ship_yard->level - $ships->search({shipyard_id => $ship_yard->id, task => 'Building'}); diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index ffc00769..c5c58d02 100755 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -575,11 +575,13 @@ sub can_build { } # check building prereqs - my $buildings = Lacuna->db->resultset('Lacuna::DB::Result::Building'); +# my $buildings = Lacuna->db->resultset('Lacuna::DB::Result::Building'); my $prereqs = $self->building_prereq; foreach my $key (keys %{$prereqs}) { - my $count = $buildings->search({body_id=>$body->id, class=>$key, level=>{'>=',$prereqs->{$key}}}); - if ($count < 1) { + my $prereq_buildings = $body->prereq_buildings($key, $prereqs->{$key}); + if (@$prereq_buildings < 1) { +# my $count = $buildings->search({body_id=>$body->id, class=>$key, level=>{'>=',$prereqs->{$key}}}); +# if ($count < 1) { confess [1013, "You need a level ".$prereqs->{$key}." ".$key->name.".",[$key->name, $prereqs->{$key}]]; } } @@ -752,7 +754,8 @@ sub cost_to_upgrade { my ($self) = @_; my $upgrade_cost = $self->upgrade_cost; my $upgrade_cost_reduction = $self->construction_cost_reduction_bonus; - my $plan = $self->body->get_plan($self->class, $self->level + 1); + my $plan; +# my $plan = $self->body->get_plan($self->class, $self->level + 1); if (defined $plan) { $upgrade_cost_reduction = 0; } diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index c995f99e..bf367709 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -220,7 +220,7 @@ sub dig_it { 'Oh no, not again.', 'Oops? What oops? No oops!', 'Ph\'nglui Mglw\'nafh Cthulhu R\'lyeh wgah\'nagi fhtagn.', - 'Push the buttom Max!', + 'Push the button Max!', 'That\'s it man, game over man, game over!', 'The brazen temple doors open...', 'There are things in the mist.', @@ -295,8 +295,7 @@ sub found_artifact { my $plan_types = plans_of_type(); my $artifacts; - my $buildings = $body->buildings; - while (my $building = $buildings->next) { + foreach my $building (@{$body->building_cache}) { unless ( grep { $building->class eq $_ } @{$plan_types->{disallow}}) { push @{$artifacts}, $building; } @@ -377,7 +376,7 @@ sub can_you_dig_it { my $glyph = int($mult * $level * $ore_total/20_000)+1; my $resource = int(5/2 * $level); my $artifact = 0; - if (!$arch && $body->buildings->count) { + if (!$arch && $body->building_cache) { $artifact = 14; } my $destroy = $arch ? 0 : 1; diff --git a/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm b/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm index b20900ee..2bba65dc 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm @@ -35,9 +35,8 @@ after finish_upgrade => sub { sub get_halls { my $self = shift; - return $self->body->get_buildings_of_class('Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk')->search({ - is_upgrading => 0, - }); + my @halls = grep {$_->is_upgrading == 0} $self->body->get_buildings_of_class('Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk'); + return @halls; } sub get_upgradable_buildings { diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index 09837f4d..bce8cf81 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -2,6 +2,8 @@ package Lacuna::DB::Result::Map::Body; use Moose; use utf8; +use List::Util qw(max); + no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Map'; @@ -217,6 +219,19 @@ __PACKAGE__->belongs_to('alliance', 'Lacuna::DB::Result::Alliance', 'alliance_id __PACKAGE__->belongs_to('empire', 'Lacuna::DB::Result::Empire', 'empire_id'); __PACKAGE__->has_many('buildings','Lacuna::DB::Result::Building','body_id'); +has building_cache => ( + is => 'rw', + lazy => 1, + builder => '_build_building_cache', +); + +sub _build_building_cache { + my ($self) = @_; + + my @buildings = $self->buildings; + return \@buildings; +} + sub abandon { my $self = shift; } @@ -255,13 +270,26 @@ sub get_type { return $type; } +sub prereq_buildings { + my ($self, $class, $level) = @_; + + my @buildings = grep { $_->class eq $class and $_->level >= $level } @{$self->building_cache}; + return \@buildings; +} + +sub get_a_building { + my ($self,$class) = @_; + + my ($building) = grep { $_->class eq "Lacuna::DB::Result::Building::$class" } @{$self->building_cache}; + return $building; +} + sub max_berth { my ($self) = @_; - my $max_berth = $self->buildings->search({ - class => 'Lacuna::DB::Result::Building::SpacePort', - efficiency => 100, - } )->get_column('level')->max; + + my $max_berth = max map {$_->level} grep {$_->class eq 'Lacuna::DB::Result::Building::SpacePort' and $_->efficiency == 100} @{$self->building_cache}; + return $max_berth ? $max_berth : 0; } diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 4296d92e..8370c595 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -19,6 +19,19 @@ __PACKAGE__->has_many('waste_chains', 'Lacuna::DB::Result::WasteChain','planet_i __PACKAGE__->has_many('out_supply_chains', 'Lacuna::DB::Result::SupplyChain','planet_id'); __PACKAGE__->has_many('in_supply_chains', 'Lacuna::DB::Result::SupplyChain','target_id'); +has plan_cache => ( + is => 'rw', + lazy => 1, + builder => '_build_plan_cache', +); + +sub _build_plan_cache { + my ($self) = @_; + + my @plans = $self->plans; + return \@plans; +} + sub surface { my $self = shift; return 'surface-'.$self->image; @@ -90,20 +103,24 @@ sub add_glyph { # PLANS sub get_plan { my ($self, $class, $level) = @_; - return $self->plans->search({class => $class, level => $level},{order_by => { -desc => 'extra_build_level' },rows => 1})->single; + + my ($plan) = sort {$b->extra_build_level <=> $a->extra_build_level} grep {$_->class eq $class and $_->level == $level} @{$self->plan_cache}; + return $plan; } sub add_plan { my ($self, $class, $level, $extra_build_level) = @_; - my $plans = $self->plans; # add it - return $plans->new({ + my $plan->new({ body_id => $self->id, class => $class, level => $level, extra_build_level => $extra_build_level, })->insert; + + push @{$self->plan_cache}, $plan; + return $plan; } sub sanitize { @@ -381,60 +398,42 @@ use constant water => 0; has population => ( is => 'ro', lazy => 1, - default => sub { - my $self = shift; - return $self->buildings->search( - { - class => { 'not like' => 'Lacuna::DB::Result::Building::Permanent%', - '!=' => 'Lacuna::DB::Result::Building::DeployedBleeder' }, - } - )->get_column('level')->sum * 10_000; - }, + builder => '_build_population', ); +sub _build_population { + my ($self) = @_; + + my $population = 0; + foreach my $building (@{$self->building_cache}) { + next if $building->class =~ /Lacuna::DB::Result::Building::Permanent/; + next if $building->class eq 'Lacuna::DB::Result::Building::DeployedBleeder'; + $population += $building->level * 10_000; + } + return $population; +} + has building_count => ( is => 'rw', lazy => 1, default => sub { my $self = shift; # Bleeders count toward building count, but supply pods don't since they can't be shot down. - return $self->buildings->search( - { - class => { 'not like' => 'Lacuna::DB::Result::Building::Permanent%', - '!=' => 'Lacuna::DB::Result::Building::SupplyPod' }, - } - )->count; + my $count = grep { $_->class !~ /Permanent$|SupplyPod$/} @{$self->building_cache}; }, ); sub get_buildings_of_class { my ($self, $class) = @_; - return Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( - { - body_id => $self->id, - class => $class, - }, - { - order_by => { -desc => 'level' }, - } - ); + + my @buildings = sort {$b->level <=> $a->level} grep {$_->class eq $class} @{$self->building_cache}; + + return @buildings; } sub get_building_of_class { my ($self, $class) = @_; - my $building = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( - { - body_id => $self->id, - class => $class, - }, - { - order_by => { -desc => 'level' }, - rows => 1, - } - )->single; - if (defined $building ) { - $building->body($self); - } + my ($building) = sort {$b->level <=> $a->level} grep {$_->class eq $class} @{$self->building_cache}; return $building; } @@ -716,9 +715,10 @@ sub has_resources_to_build { sub has_max_instances_of_building { my ($self, $building) = @_; return 0 if $building->max_instances_per_planet == 9999999; - my $count = $self->get_buildings_of_class($building->class)->count; - if ($count >= $building->max_instances_per_planet) { - confess [1009, sprintf("You are only allowed %s of these buildings per planet.",$building->max_instances_per_planet), [$building->max_instances_per_planet, $count]]; + my @buildings = grep {$_->class eq $building->class} @{$self->building_cache}; + + if (scalar @buildings >= $building->max_instances_per_planet) { + confess [1009, sprintf("You are only allowed %s of these buildings per planet.",$building->max_instances_per_planet)]; } } @@ -796,8 +796,8 @@ sub found_colony { $self->build_building($command); $command->finish_upgrade; - my $craters = $self->get_buildings_of_class('Lacuna::DB::Result::Building::Permanent::Crater')->search({ work => '{}', }); - while (my $crater = $craters->next) { + my @craters = grep {$_->work eq '{}'} $self->get_buildings_of_class('Lacuna::DB::Result::Building::Permanent::Crater'); + foreach my $crater (@craters) { $crater->finish_work->update; } @@ -922,9 +922,8 @@ sub recalc_chains { my ($self) = @_; # find the Trade Ministry - my ($trade_min) = $self->buildings->search({ - class => 'Lacuna::DB::Result::Building::Trade', - }); + my $trade_min = $self->get_a_building('Trade'); + if ($trade_min) { $trade_min->recalc_supply_production; $trade_min->recalc_waste_production; @@ -935,8 +934,7 @@ sub recalc_stats { my ($self) = @_; my %stats = ( needs_recalc => 0 ); - my $buildings = $self->buildings; - #reset foods + #reset foods and ores foreach my $type (FOOD_TYPES) { $stats{$type.'_production_hour'} = 0; } @@ -945,7 +943,7 @@ sub recalc_stats { } #calculate building production my ($gas_giant_platforms, $terraforming_platforms, $station_command, $pantheon_of_hagness, $total_ore_production_hour, $ore_production_hour, $ore_consumption_hour) = 0; - while (my $building = $buildings->next) { + foreach my $building (@{$self->building_cache}) { $stats{waste_capacity} += $building->waste_capacity; $stats{water_capacity} += $building->water_capacity; $stats{energy_capacity} += $building->energy_capacity; @@ -2152,7 +2150,7 @@ sub spend_waste { if (!$empire->check_for_repeat_message('complaint_lack_of_waste'.$self->id)) { my $building_name; foreach my $class (qw(Lacuna::DB::Result::Building::Energy::Waste Lacuna::DB::Result::Building::Waste::Treatment Lacuna::DB::Result::Building::Waste::Digester Lacuna::DB::Result::Building::Water::Reclamation Lacuna::DB::Result::Building::Waste::Exchanger)) { - my $building = $self->get_buildings_of_class($class)->search({efficiency => {'>' => 0}},{rows => 1})->single; + my ($building) = grep {$_->efficiency > 0} $self->get_buildings_of_class($class); if (defined $building) { $building_name = $building->name; $building->spend_efficiency(25)->update; @@ -2184,13 +2182,7 @@ sub complain_about_lack_of_resources { # Special conditions for space stations if ($self->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { if ($class eq 'Lacuna::DB::Result::Building::Module::Parliament' || $class eq 'Lacuna::DB::Result::Building::Module::StationCommand') { - my $others = $self->buildings->search( { - class => { 'not in' => [ - 'Lacuna::DB::Result::Building::Module::Parliament', - 'Lacuna::DB::Result::Building::Module::StationCommand', - 'Lacuna::DB::Result::Building::Permanent::Crater' - ] } - } )->count; + my $others = grep {$_->class !~ /Parliament$|StationCommand$|Crater$/} @{$self->building_cache}; if ( $others ) { # If there are other buildings, divert power from them to keep Parliament and Station Command running as long as possible next; @@ -2242,7 +2234,7 @@ sub complain_about_lack_of_resources { } } } - my $building = $self->get_buildings_of_class($class)->search({efficiency => {'>' => 0}},{rows => 1})->single; + my ($building) = grep {$_->efficiency > 0} self->get_buildings_of_class($class); if (defined $building) { $building_name = $building->name; $building->spend_efficiency(25)->update; diff --git a/lib/Lacuna/RPC/Body.pm b/lib/Lacuna/RPC/Body.pm index c6b499f9..fb378387 100644 --- a/lib/Lacuna/RPC/Body.pm +++ b/lib/Lacuna/RPC/Body.pm @@ -409,6 +409,9 @@ sub get_buildable { if ($can_build) { push @tags, 'Now'; } + elsif (ref $reason ne 'ARRAY') { + confess $reason; + } elsif ($reason->[0] == 1011) { push @tags, 'Soon'; } diff --git a/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm b/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm index 47134bc3..7debbd73 100644 --- a/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm +++ b/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm @@ -53,7 +53,8 @@ sub sacrifice_to_upgrade { $upgrade->body($body); $upgrade->start_upgrade; # get the number of built halls - my @halls = $building->get_halls->search(undef, {rows => $upgrade->level + 1}); + my @halls = $building->get_halls; + @halls = splice(@halls, 0, $upgrade->level + 1); # get the remaining plans my $plans_needed = $upgrade->level + 1 - scalar @halls; my @plans; diff --git a/lib/Lacuna/Role/Ship/Arrive/DeployProbe.pm b/lib/Lacuna/Role/Ship/Arrive/DeployProbe.pm index 45b6a592..e81b697e 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DeployProbe.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DeployProbe.pm @@ -25,7 +25,7 @@ after can_send_to_target => sub { my $count = Lacuna->db->resultset('Lacuna::DB::Result::Probes')->search({ body_id => $body->id })->count; $count += Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search({ body_id => $body->id, type=>'probe', task=>'Travelling' })->count; my $max_probes = 0; - my $observatory = $body->get_buildings_of_class('Lacuna::DB::Result::Building::Observatory')->next; + my ($observatory) = $body->get_buildings_of_class('Lacuna::DB::Result::Building::Observatory'); if (defined $observatory) { $max_probes = $observatory->max_probes; } diff --git a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm index ba8cd4d0..aeed430c 100644 --- a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm +++ b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm @@ -347,22 +347,21 @@ sub system_saw_combat { } sub saw_stats { - my ($self, $body) = @_; - - my $saws = $body->get_buildings_of_class('Lacuna::DB::Result::Building::SAW'); - - my $planet_combat = 0; - my @saws; - my $cnt = 0; - while (my $saw = $saws->next) { - $cnt++; - next if $saw->level < 1; - next if $saw->efficiency < 1; - $planet_combat += int( (5 * ($saw->level + 1) * ($saw->level+1) * $saw->efficiency)/2 + 0.5); - push @saws, $saw; - last if $cnt >= 10; - } - return \@saws, $planet_combat; + my ($self, $body) = @_; + + my @saws = $body->get_buildings_of_class('Lacuna::DB::Result::Building::SAW'); + + my $planet_combat = 0; + my $cnt = 0; + foreach my $saw (@saws) { + $cnt++; + next if $saw->level < 1; + next if $saw->efficiency < 1; + $planet_combat += int( (5 * ($saw->level + 1) * ($saw->level+1) * $saw->efficiency)/2 + 0.5); + push @saws, $saw; + last if $cnt >= 10; + } + return \@saws, $planet_combat; } sub saw_combat { -- 2.51.2 From 9aa3fcb4ae0dd85ea37d94b8d2cfa388fdd0e5f9 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Mon, 21 May 2012 16:27:57 -0400 Subject: [PATCH 016/105] Fixed problem with building count --- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 8370c595..6c3a854f 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -112,7 +112,7 @@ sub add_plan { my ($self, $class, $level, $extra_build_level) = @_; # add it - my $plan->new({ + my $plan = $self->plans->new({ body_id => $self->id, class => $class, level => $level, @@ -416,13 +416,16 @@ sub _build_population { has building_count => ( is => 'rw', lazy => 1, - default => sub { - my $self = shift; -# Bleeders count toward building count, but supply pods don't since they can't be shot down. - my $count = grep { $_->class !~ /Permanent$|SupplyPod$/} @{$self->building_cache}; - }, + builder => '_build_building_count', ); +sub _build_building_count { + my ($self) = @_; +# Bleeders count toward building count, but supply pods don't since they can't be shot down. + my $count = grep { $_->class !~ /Permanent$|SupplyPod$/} @{$self->building_cache}; + return $count; +} + sub get_buildings_of_class { my ($self, $class) = @_; -- 2.51.2 From 0c4116fdbcbcec5c878e3e30ec6a96857541b949 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Mon, 21 May 2012 16:38:27 -0400 Subject: [PATCH 017/105] Can upgrade a building with a plan --- lib/Lacuna/DB/Result/Building.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index c5c58d02..063df51a 100755 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -755,7 +755,7 @@ sub cost_to_upgrade { my $upgrade_cost = $self->upgrade_cost; my $upgrade_cost_reduction = $self->construction_cost_reduction_bonus; my $plan; -# my $plan = $self->body->get_plan($self->class, $self->level + 1); + my $plan = $self->body->get_plan($self->class, $self->level + 1); if (defined $plan) { $upgrade_cost_reduction = 0; } -- 2.51.2 From 76de03aabb10e56a377812f92fbc218c6f801523 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 21 May 2012 17:26:48 -0600 Subject: [PATCH 018/105] Missing next. --- lib/Lacuna/DB/Result/Spies.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index f1d17a99..aff47c73 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -1412,6 +1412,7 @@ sub steal_planet { 'colony_ship', 'short_range_colony_ship', ]})) { + next; } $ship->delete; } -- 2.51.2 From f424d70b49a09f7b456e500d95be67fc222bb8f1 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 07:41:33 -0600 Subject: [PATCH 019/105] More efficient berth check. --- lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Building/Trade.pm | 24 +++------- lib/Lacuna/DB/Result/Map/Body.pm | 17 +++---- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 4 ++ lib/Lacuna/RPC/Building/MiningMinistry.pm | 9 +--- lib/Lacuna/RPC/Building/SpacePort.pm | 54 +++++++---------------- var/upgrades/3.0852.sql | 1 + var/www/public/changes.txt | 3 ++ 8 files changed, 42 insertions(+), 72 deletions(-) create mode 100644 var/upgrades/3.0852.sql diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 1bcb383b..ae501422 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0851; +our $VERSION = 3.0852; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1}); diff --git a/lib/Lacuna/DB/Result/Building/Trade.pm b/lib/Lacuna/DB/Result/Building/Trade.pm index 4c50708b..1f0722d0 100644 --- a/lib/Lacuna/DB/Result/Building/Trade.pm +++ b/lib/Lacuna/DB/Result/Building/Trade.pm @@ -97,18 +97,14 @@ sub waste_ships { # All ships that are either in a supply chain, or available to be so sub all_supply_ships { my $self = shift; - my $max_level = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search({ - class => 'Lacuna::DB::Result::Building::SpacePort', - body_id => $self->body_id, - efficiency => 100, - })->get_column('level')->max || 0; + my $body = $self->planet; return Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search({ body_id => $self->body_id, -or => { task => 'Supply Chain', -and => [ task => 'Docked', - berth_level => {'<=' => $max_level}, + berth_level => {'<=' => $body->max_berth}, type => { '=', [SHIP_TRADE_TYPES]}, ] } @@ -120,18 +116,14 @@ sub all_supply_ships { # All ships that are either in a waste chain, or available to be so sub all_waste_ships { my $self = shift; - my $max_level = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search({ - class => 'Lacuna::DB::Result::Building::SpacePort', - body_id => $self->body_id, - efficiency => 100, - })->get_column('level')->max || 0; + my $body = $self->planet; return Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search({ body_id => $self->body_id, -or => { task => 'Waste Chain', -and => [ task => 'Docked', - berth_level => {'<=' => $max_level}, + berth_level => {'<=' => $body->max_berth}, type => { '=', [SHIP_WASTE_TYPES]}, ] } @@ -371,16 +363,12 @@ sub available_market { sub trade_ships { my $self = shift; - my $max_level = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { - class => 'Lacuna::DB::Result::Building::SpacePort', - body_id => $self->body_id, - efficiency => 100, - } )->get_column('level')->max || 0; + my $body = $self->body; return Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search({ task => 'Docked', type => { 'in' => [SHIP_TRADE_TYPES] }, body_id => $self->body_id, - berth_level => {'<=' => $max_level } + berth_level => {'<=' => $body->max_berth } }, { order_by=> {-desc => ['hold_size']} diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index 09837f4d..43738719 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -122,6 +122,7 @@ __PACKAGE__->add_columns( restrict_coverage => { data_type => 'tinyint', default_value => 0 }, plots_available => { data_type => 'tinyint', default_value => 0 }, surface_version => { data_type => 'tinyint', default_value => 0 }, + max_berth => { data_type => 'tinyint', default_value => 1 }, ); after 'sqlt_deploy_hook' => sub { @@ -255,15 +256,15 @@ sub get_type { return $type; } -sub max_berth { - my ($self) = @_; +# sub max_berth { +# my ($self) = @_; - my $max_berth = $self->buildings->search({ - class => 'Lacuna::DB::Result::Building::SpacePort', - efficiency => 100, - } )->get_column('level')->max; - return $max_berth ? $max_berth : 0; -} +# my $max_berth = $self->buildings->search({ +# class => 'Lacuna::DB::Result::Building::SpacePort', +# efficiency => 100, +# } )->get_column('level')->max; +# return $max_berth ? $max_berth : 0; +# } sub get_status { my ($self) = @_; diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index e7ccc21d..62e79560 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -943,6 +943,7 @@ sub recalc_stats { foreach my $type (ORE_TYPES) { $stats{$type.'_hour'} = 0; } + $stats{max_berth} = 1; #calculate building production my ($gas_giant_platforms, $terraforming_platforms, $station_command, $pantheon_of_hagness, $total_ore_production_hour, $ore_production_hour, $ore_consumption_hour) = 0; while (my $building = $buildings->next) { @@ -962,6 +963,9 @@ sub recalc_stats { my $method = $type.'_production_hour'; $stats{$method} += $building->$method(); } + if ($building->isa('Lacuna::DB::Result::Building::SpacePort') and $building->efficiency == 100) { + $stats{max_berth} = $building->level if ($building->level > $stats{max_berth}); + } if ($building->isa('Lacuna::DB::Result::Building::Ore::Ministry')) { my $platforms = Lacuna->db->resultset('Lacuna::DB::Result::MiningPlatforms')->search({planet_id => $self->id}); while (my $platform = $platforms->next) { diff --git a/lib/Lacuna/RPC/Building/MiningMinistry.pm b/lib/Lacuna/RPC/Building/MiningMinistry.pm index e0b2e663..2e792756 100644 --- a/lib/Lacuna/RPC/Building/MiningMinistry.pm +++ b/lib/Lacuna/RPC/Building/MiningMinistry.pm @@ -114,13 +114,8 @@ sub add_cargo_ship_to_fleet { unless ($ship->body_id eq $building->body_id) { confess [1013, "You can't manage a ship that is not yours."]; } - my $max_level = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { - class => 'Lacuna::DB::Result::Building::SpacePort', - body_id => $building->body_id, - efficiency => 100, - } )->get_column('level')->max; - unless ($max_level >= $ship->berth_level) { - confess [1009, 'Max Berth Level is '.$max_level.' for ships on this planet.' ]; + unless ($building->body->max_berth >= $ship->berth_level) { + confess [1009, 'Max Berth Level is '.$building->body->max_berth.' for ships on this planet.' ]; } $building->add_ship($ship); return { diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index f0e78911..f6ce7b94 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -72,11 +72,7 @@ sub get_ships_for { push @incoming, $ship->get_status; } - my $max_level = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { - class => 'Lacuna::DB::Result::Building::SpacePort', - body_id => $body_id, - efficiency => 100, - } )->get_column('level')->max; + my $max_berth = $body->max_berth; my @unavailable; my @available; @@ -90,8 +86,8 @@ sub get_ships_for { push @unavailable, { ship => $ship->get_status, reason => $reason }; next; } - if ($ship->berth_level > $max_level) { - $reason = [ 1009, 'Max Berth Level to send from this planet is '.$max_level ]; + if ($ship->berth_level > $max_berth) { + $reason = [ 1009, 'Max Berth Level to send from this planet is '.$max_berth ]; push @unavailable, { ship => $ship->get_status, reason => $reason }; next; } @@ -308,20 +304,16 @@ sub prepare_send_spies { } $empire->current_session->check_captcha; - my $max_level = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { - class => 'Lacuna::DB::Result::Building::SpacePort', - body_id => $on_body_id, - efficiency => 100, - } )->get_column('level')->max; - unless ($max_level) { - $max_level = 1; -# confess [1009, "Cannot send spies without any ships."]; + + my $max_berth = $on_body->max_berth; + unless ($max_berth) { + $max_berth = 1; } my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search( {type => { in => [qw(spy_pod cargo_ship smuggler_ship dory spy_shuttle barge)]}, task=>'Docked', body_id => $on_body_id, - berth_level => {'<=' => $max_level } }, + berth_level => {'<=' => $max_berth } }, {order_by => 'name', rows=>100} ); my @ships; @@ -372,12 +364,8 @@ sub send_spies { unless ($ship->is_available) { confess [1010, "That ship is not available."]; } - my $max_level = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { - class => 'Lacuna::DB::Result::Building::SpacePort', - body_id => $ship->body_id, - efficiency => 100, - } )->get_column('level')->max; - unless ($ship->berth_level <= $max_level) { + my $max_berth = $on_body->max_berth; + unless ($ship->berth_level <= $max_berth) { confess [1010, "Your spaceport level is not high enough to support a ship with a Berth Level of ".$ship->berth_level."."]; } @@ -440,21 +428,15 @@ sub prepare_fetch_spies { confess [1013, "Cannot fetch spies from an uninhabited planet."]; } - my $max_level = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { - class => 'Lacuna::DB::Result::Building::SpacePort', - body_id => $to_body_id, - efficiency => 100, - } )->get_column('level')->max; - - unless ($max_level) { - $max_level = 1; -# confess [1009, "Cannot fetch spies without any ships."]; + my $max_berth = $to_body->max_berth; + unless ($max_berth) { + $max_berth = 1; } my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search( {type => { in => [qw(spy_pod cargo_ship smuggler_ship dory spy_shuttle barge)]}, task=>'Docked', body_id => $to_body_id, - berth_level => {'<=' => $max_level } }, + berth_level => {'<=' => $max_berth } }, {order_by => 'name', rows=>100} ); my @ships; @@ -497,11 +479,7 @@ sub fetch_spies { my $to_body = $self->get_body($empire, $to_body_id); my $on_body = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($on_body_id); - my $max_level = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { - class => 'Lacuna::DB::Result::Building::SpacePort', - body_id => $to_body_id, - efficiency => 100, - } )->get_column('level')->max; + my $max_berth = $to_body->max_berth; # get the ship my $ship = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->find($ship_id); @@ -512,7 +490,7 @@ sub fetch_spies { confess [1010, "That ship is not available."]; } - unless ($ship->berth_level <= $max_level) { + unless ($ship->berth_level <= $max_berth) { confess [1010, "Your spaceport level is not high enough to support a ship with a Berth Level of ".$ship->berth_level."."]; } diff --git a/var/upgrades/3.0852.sql b/var/upgrades/3.0852.sql new file mode 100644 index 00000000..17aae13e --- /dev/null +++ b/var/upgrades/3.0852.sql @@ -0,0 +1 @@ +alter table body add column max_berth tinyint default 1; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 4f347683..194777e2 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,6 @@ +3.0852: + - Mod: Efficiency modifications. + 3.0851: - Mod: Multiple plans buildable with one call from Archaeology Ministry. - Mod: view_plans from Planetary and Station Commands consolidated. UI updated to reflect. -- 2.51.2 From cef2443a0f2f6f0d6179053b2218a483d7665488 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 07:55:36 -0600 Subject: [PATCH 020/105] body, not planet. --- lib/Lacuna/DB/Result/Building/Trade.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Trade.pm b/lib/Lacuna/DB/Result/Building/Trade.pm index 1f0722d0..3664ae9b 100644 --- a/lib/Lacuna/DB/Result/Building/Trade.pm +++ b/lib/Lacuna/DB/Result/Building/Trade.pm @@ -97,7 +97,7 @@ sub waste_ships { # All ships that are either in a supply chain, or available to be so sub all_supply_ships { my $self = shift; - my $body = $self->planet; + my $body = $self->body; return Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search({ body_id => $self->body_id, -or => { @@ -116,7 +116,7 @@ sub all_supply_ships { # All ships that are either in a waste chain, or available to be so sub all_waste_ships { my $self = shift; - my $body = $self->planet; + my $body = $self->body; return Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search({ body_id => $self->body_id, -or => { -- 2.51.2 From 297c017b2030b9fc5c69cc1e1b16dd0d057ec6aa Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 11:57:16 -0600 Subject: [PATCH 021/105] More flip fixing. --- lib/Lacuna/DB/Result/Spies.pm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index aff47c73..ffefa985 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -1384,6 +1384,7 @@ sub steal_planet { $trade->withdraw; } } +# Remove Supply chains to and from planet my $defender_capitol_id = $self->on_body->empire->home_planet_id; Lacuna->db->resultset('Lacuna::DB::Result::Spies')->search({ @@ -1398,6 +1399,7 @@ sub steal_planet { task => { '!=' => 'Docked' } }); while (my $ship = $ships->next) { next if ($ship->task eq 'Waiting On Trade'); + next if ($ship->task eq 'Waste Chain'); if ($ship->task eq 'Travelling' and (grep { $ship->type eq $_ } @{['cargo_ship', @@ -1409,12 +1411,19 @@ sub steal_planet { 'hulk_huge', 'dory', 'barge', - 'colony_ship', - 'short_range_colony_ship', ]})) { next; } - $ship->delete; + elsif ($ship->task eq 'Travelling' and + (grep { $ship->type eq $_ } + @{[ 'colony_ship', + 'short_range_colony_ship', + ]})) { + $ship->body_id($defender_capitol_id); + } + else { + $ship->delete; + } } Lacuna->db->resultset('Lacuna::DB::Result::Probes') -- 2.51.2 From e9cd28d10b8b487eb5d81379d6432abf7e08c437 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 12:09:55 -0600 Subject: [PATCH 022/105] Supply chains to and from removed from flipped planet. --- lib/Lacuna/DB/Result/Spies.pm | 176 ++++++++++++++++++---------------- var/www/public/changes.txt | 1 + 2 files changed, 92 insertions(+), 85 deletions(-) diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index ffefa985..4323a010 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -1334,111 +1334,117 @@ sub can_conduct_advanced_missions { # OUTCOMES sub steal_planet { - my ($self, $defender) = @_; - my $next_colony_cost = $self->empire->next_colony_cost; - my $planet_happiness = $self->on_body->happiness; - my $chance = abs($planet_happiness * 100) / $next_colony_cost; - my $failure = randint(1,100) > $chance; - if ($planet_happiness > 0 || $failure) { # lose - $self->on_body->empire->send_predefined_message( + my ($self, $defender) = @_; + my $next_colony_cost = $self->empire->next_colony_cost; + my $planet_happiness = $self->on_body->happiness; + my $chance = abs($planet_happiness * 100) / $next_colony_cost; + my $failure = randint(1,100) > $chance; + if ($planet_happiness > 0 || $failure) { # lose + $self->on_body->empire->send_predefined_message( tags => ['Spies','Alert'], filename => 'insurrection_luck.txt', params => [$self->on_body_id, $self->on_body->name], - ); - return $self->empire->send_predefined_message( + ); + return $self->empire->send_predefined_message( tags => ['Intelligence'], filename => 'insurrection_failed.txt', params => [$self->on_body->x, $self->on_body->y, $self->on_body->name, $self->format_from], - )->id; - } - else { # win - $self->on_body->empire->send_predefined_message( + )->id; + } + else { # win + $self->on_body->empire->send_predefined_message( tags => ['Spies','Alert'], filename => 'lost_planet_to_insurrection.txt', params => [$self->on_body->name, $self->on_body->x, $self->on_body->y, $self->on_body->name], + ); + $self->on_body->add_news(100, + 'Led by %s, the citizens of %s have overthrown %s!', + $self->name, + $self->on_body->name, + $self->on_body->empire->name); + + # withdraw trades + for my $market ( Lacuna->db->resultset('Lacuna::DB::Result::Market'), + Lacuna->db->resultset('Lacuna::DB::Result::MercenaryMarket') ) { + my @to_be_deleted = $market->search({body_id => $self->on_body_id})->get_column('id')->all; + foreach my $id (@to_be_deleted) { + my $trade = $market->find($id); + next unless defined $trade; + $trade->body->empire->send_predefined_message( + filename => 'trade_withdrawn.txt', + params => [join("\n",@{$trade->format_description_of_payload}), $trade->ask.' essentia'], + tags => ['Trade','Alert'], ); - $self->on_body->add_news(100, - 'Led by %s, the citizens of %s have overthrown %s!', - $self->name, - $self->on_body->name, - $self->on_body->empire->name); - - # withdraw trades - for my $market ( Lacuna->db->resultset('Lacuna::DB::Result::Market'), - Lacuna->db->resultset('Lacuna::DB::Result::MercenaryMarket') ) { - my @to_be_deleted = $market->search({body_id => $self->on_body_id})->get_column('id')->all; - foreach my $id (@to_be_deleted) { - my $trade = $market->find($id); - next unless defined $trade; - $trade->body->empire->send_predefined_message( - filename => 'trade_withdrawn.txt', - params => [join("\n",@{$trade->format_description_of_payload}), $trade->ask.' essentia'], - tags => ['Trade','Alert'], - ); - $trade->withdraw; - } - } + $trade->withdraw; + } + } # Remove Supply chains to and from planet + foreach my $chain ($self->on_body->out_supply_chains) { + $chain->delete; + } + foreach my $chain ($self->on_body->in_supply_chains) { + $chain->delete; + } - my $defender_capitol_id = $self->on_body->empire->home_planet_id; - Lacuna->db->resultset('Lacuna::DB::Result::Spies')->search({ - from_body_id => $self->on_body_id, on_body_id => $self->on_body_id, task => 'Training', - })->delete_all; # All spies in training are executed - Lacuna->db->resultset('Lacuna::DB::Result::Spies') - ->search({from_body_id => $self->on_body_id}) - ->update({from_body_id => $defender_capitol_id }); - - my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships') - ->search({body_id => $self->on_body_id, - task => { '!=' => 'Docked' } }); - while (my $ship = $ships->next) { - next if ($ship->task eq 'Waiting On Trade'); - next if ($ship->task eq 'Waste Chain'); - if ($ship->task eq 'Travelling' and - (grep { $ship->type eq $_ } - @{['cargo_ship', - 'smuggler_ship', - 'galleon', - 'freighter', - 'hulk', - 'hulk_fast', - 'hulk_huge', - 'dory', - 'barge', - ]})) { - next; - } - elsif ($ship->task eq 'Travelling' and - (grep { $ship->type eq $_ } - @{[ 'colony_ship', - 'short_range_colony_ship', - ]})) { - $ship->body_id($defender_capitol_id); - } - else { - $ship->delete; - } - } + my $defender_capitol_id = $self->on_body->empire->home_planet_id; + Lacuna->db->resultset('Lacuna::DB::Result::Spies')->search({ + from_body_id => $self->on_body_id, on_body_id => $self->on_body_id, task => 'Training', + })->delete_all; # All spies in training are executed + Lacuna->db->resultset('Lacuna::DB::Result::Spies') + ->search({from_body_id => $self->on_body_id}) + ->update({from_body_id => $defender_capitol_id }); + + my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships') + ->search({body_id => $self->on_body_id, + task => { '!=' => 'Docked' } }); + while (my $ship = $ships->next) { + next if ($ship->task eq 'Waiting On Trade'); + next if ($ship->task eq 'Waste Chain'); + if ($ship->task eq 'Travelling' and + (grep { $ship->type eq $_ } + @{['cargo_ship', + 'smuggler_ship', + 'galleon', + 'freighter', + 'hulk', + 'hulk_fast', + 'hulk_huge', + 'dory', + 'barge', + ]})) { + next; + } + elsif ($ship->task eq 'Travelling' and + (grep { $ship->type eq $_ } + @{[ 'colony_ship', + 'short_range_colony_ship', + ]})) { + $ship->body_id($defender_capitol_id); + } + else { + $ship->delete; + } + } - Lacuna->db->resultset('Lacuna::DB::Result::Probes') - ->search({body_id => $self->on_body_id}) - ->update({empire_id => $self->empire_id, alliance_id => $self->empire->alliance_id}); + Lacuna->db->resultset('Lacuna::DB::Result::Probes') + ->search({body_id => $self->on_body_id}) + ->update({empire_id => $self->empire_id, alliance_id => $self->empire->alliance_id}); - $self->on_body->empire_id($self->empire_id); - $self->on_body->add_happiness(int(abs($planet_happiness) / 10)); - $self->on_body->update; - return $self->empire->send_predefined_message( - tags => ['Intelligence'], - filename => 'insurrection_complete.txt', - params => [$self->on_body_id, $self->on_body->name, $self->format_from], - )->id; - } + $self->on_body->empire_id($self->empire_id); + $self->on_body->add_happiness(int(abs($planet_happiness) / 10)); + $self->on_body->update; + return $self->empire->send_predefined_message( + tags => ['Intelligence'], + filename => 'insurrection_complete.txt', + params => [$self->on_body_id, $self->on_body->name, $self->format_from], + )->id; + } } diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 194777e2..2ca4c728 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,5 +1,6 @@ 3.0852: - Mod: Efficiency modifications. + - Mod: Various bug fixes. 3.0851: - Mod: Multiple plans buildable with one call from Archaeology Ministry. -- 2.51.2 From eb92067aa64007ed505f32f254223901e15aae7e Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 13:53:15 -0600 Subject: [PATCH 023/105] more flipping --- lib/Lacuna/DB/Result/Spies.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 4323a010..8ececae0 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -1406,7 +1406,10 @@ sub steal_planet { while (my $ship = $ships->next) { next if ($ship->task eq 'Waiting On Trade'); next if ($ship->task eq 'Waste Chain'); - if ($ship->task eq 'Travelling' and + if ($ship->task eq 'Supply Chain') { + $ship->task('Docked')->update; + } + elsif ($ship->task eq 'Travelling' and (grep { $ship->type eq $_ } @{['cargo_ship', 'smuggler_ship', @@ -1418,6 +1421,9 @@ sub steal_planet { 'dory', 'barge', ]})) { + if ($ship->direction eq 'out') { + $ship->body_id($defender_capitol_id)->update; + } next; } elsif ($ship->task eq 'Travelling' and @@ -1425,7 +1431,7 @@ sub steal_planet { @{[ 'colony_ship', 'short_range_colony_ship', ]})) { - $ship->body_id($defender_capitol_id); + $ship->body_id($defender_capitol_id)->update; } else { $ship->delete; -- 2.51.2 From 064de5e7c2e37d9c94565540153c916662d62155 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 13:56:25 -0600 Subject: [PATCH 024/105] Another testing error. --- lib/Lacuna/DB/Result/Spies.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 8ececae0..b6a5d0f8 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -1422,7 +1422,8 @@ sub steal_planet { 'barge', ]})) { if ($ship->direction eq 'out') { - $ship->body_id($defender_capitol_id)->update; + $ship->body_id($defender_capitol_id); + $ship->update; } next; } @@ -1431,7 +1432,8 @@ sub steal_planet { @{[ 'colony_ship', 'short_range_colony_ship', ]})) { - $ship->body_id($defender_capitol_id)->update; + $ship->body_id($defender_capitol_id); + $ship->update; } else { $ship->delete; -- 2.51.2 From acb1f7ac3de2c6a8ab37ad548a599535b9a4e79e Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 13:58:43 -0600 Subject: [PATCH 025/105] Missed one. --- lib/Lacuna/DB/Result/Spies.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index b6a5d0f8..7e5d3504 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -1407,7 +1407,8 @@ sub steal_planet { next if ($ship->task eq 'Waiting On Trade'); next if ($ship->task eq 'Waste Chain'); if ($ship->task eq 'Supply Chain') { - $ship->task('Docked')->update; + $ship->task('Docked'); + $ship->update; } elsif ($ship->task eq 'Travelling' and (grep { $ship->type eq $_ } -- 2.51.2 From f50e2bf00f52ba78b591b201b52252f647b3c7fa Mon Sep 17 00:00:00 2001 From: ian docherty Date: Tue, 22 May 2012 17:28:27 -0400 Subject: [PATCH 026/105] Added a swathe more changes to use the building_cache --- bin/delambert/add_colonies.pl | 7 +- bin/trelvestian/add_colonies.pl | 2 +- lib/Lacuna/AI.pm | 4 +- lib/Lacuna/DB/Result/Building.pm | 18 ++-- lib/Lacuna/DB/Result/Building/Development.pm | 9 +- .../Building/Permanent/GasGiantPlatform.pm | 12 +-- .../Building/Permanent/HallsOfVrbansk.pm | 25 +++--- .../Permanent/TerraformingPlatform.pm | 16 ++-- lib/Lacuna/DB/Result/Building/Stockpile.pm | 6 +- .../DB/Result/Building/SubspaceSupplyDepot.pm | 3 +- lib/Lacuna/DB/Result/Map/Body.pm | 1 + lib/Lacuna/DB/Result/Map/Body/Planet.pm | 86 +++++++++++-------- .../DB/Result/Map/Body/Planet/Station.pm | 45 ++++++---- .../DB/Result/Propositions/DemolishModule.pm | 2 +- .../DB/Result/Propositions/DowngradeModule.pm | 2 +- lib/Lacuna/DB/Result/Propositions/FireBfg.pm | 3 +- .../DB/Result/Propositions/InstallModule.pm | 4 +- .../DB/Result/Propositions/RepairModule.pm | 2 +- .../DB/Result/Propositions/UpgradeModule.pm | 4 +- lib/Lacuna/DB/Result/Spies.pm | 71 ++++----------- lib/Lacuna/RPC/Body.pm | 7 +- lib/Lacuna/RPC/Building/BlackHoleGenerator.pm | 29 +++---- lib/Lacuna/RPC/Building/HallsOfVrbansk.pm | 10 +-- .../RPC/Building/TempleOfTheDrajilites.pm | 4 +- lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm | 46 +++++----- lib/Lacuna/Role/Ship/Arrive/ScanSurface.pm | 3 +- lib/Lacuna/Role/Ship/Arrive/SurveySurface.pm | 3 +- t/TestHelper.pm | 10 ++- 28 files changed, 210 insertions(+), 224 deletions(-) diff --git a/bin/delambert/add_colonies.pl b/bin/delambert/add_colonies.pl index 31f71bca..ff74fcda 100644 --- a/bin/delambert/add_colonies.pl +++ b/bin/delambert/add_colonies.pl @@ -45,7 +45,8 @@ if ($respawn) { # First ensure we have demolished all glyph resource buildings for my $planet ($empire->planets->all) { out("Removing sensitive buildings from ".$planet->name); - $planet->buildings->delete_all; + $planet->delete_buildings(@{$planet->building_cache}); + # Rename the planet $planet->name($planet->star->name." ".$planet->orbit); $planet->update; @@ -183,7 +184,7 @@ for my $level(@build_levels) { } die "Cannot find a star in zone $add_to_zone" unless $body; - $body->buildings->delete_all; + $body->delete_buildings(@{$body->building_cache}); $body->found_colony($empire); create_colony($level, $body); $delamberti_in->{$add_to_zone} = $delamberti_in_lowest_zone + 1; @@ -242,7 +243,7 @@ sub create_empire { },{rows=>1})->single; $empire->insert; - $home->buildings->delete_all; + $home->delete_buildings(@{$home->building_cache}); $empire->found($home); $empire->university_level(30); $empire->update; diff --git a/bin/trelvestian/add_colonies.pl b/bin/trelvestian/add_colonies.pl index 1a092181..08eebc1d 100644 --- a/bin/trelvestian/add_colonies.pl +++ b/bin/trelvestian/add_colonies.pl @@ -65,7 +65,7 @@ if ($tournament) { } else { say 'Clearing '.$body->name; - $body->buildings->delete_all; + $body->delete_buildings(@{$body->building_cache}); say 'Colonizing '.$body->name; $body->found_colony($ai->empire); $ai->build_colony($body); diff --git a/lib/Lacuna/AI.pm b/lib/Lacuna/AI.pm index 7cbcf004..533c4300 100644 --- a/lib/Lacuna/AI.pm +++ b/lib/Lacuna/AI.pm @@ -58,7 +58,7 @@ sub create_empire { my $empire = $db->resultset('Lacuna::DB::Result::Empire')->new(\%attributes)->insert; my $zone = $db->resultset('Lacuna::DB::Result::Map::Body')->get_column('zone')->max; my $home = $self->viable_colonies->search({zone => $zone},{rows=>1})->single; - $home->buildings->delete_all; + $home->delete_buildings(@{$home->building_cache}); $empire->found($home); $self->build_colony($home); return $empire; @@ -149,7 +149,7 @@ sub add_colonies { my $body = $self->viable_colonies->search({zone => $zone},{rows=>1})->single; if (defined $body) { say 'Clearing '.$body->name; - $body->buildings->delete_all; + $body->delete_buildings(@{$body->building_cache}); say 'Colonizing '.$body->name; $body->found_colony($empire); $self->build_colony($body); diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index 063df51a..98b10302 100755 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -6,6 +6,8 @@ no warnings qw(uninitialized); extends 'Lacuna::DB::Result'; use Lacuna::Constants ':all'; use List::Util qw(shuffle); +use List::MoreUtils qw(first_index); + use Lacuna::Util qw(format_date); __PACKAGE__->load_components('DynamicSubclass'); @@ -575,13 +577,10 @@ sub can_build { } # check building prereqs -# my $buildings = Lacuna->db->resultset('Lacuna::DB::Result::Building'); my $prereqs = $self->building_prereq; foreach my $key (keys %{$prereqs}) { my $prereq_buildings = $body->prereq_buildings($key, $prereqs->{$key}); if (@$prereq_buildings < 1) { -# my $count = $buildings->search({body_id=>$body->id, class=>$key, level=>{'>=',$prereqs->{$key}}}); -# if ($count < 1) { confess [1013, "You need a level ".$prereqs->{$key}." ".$key->name.".",[$key->name, $prereqs->{$key}]]; } } @@ -614,6 +613,13 @@ sub demolish { my $body = $self->body; $body->add_waste(sprintf('%.0f',$self->ore_to_build * $self->upgrade_cost)); $body->spend_happiness(sprintf('%.0f',$self->food_to_build * $self->upgrade_cost)); + + # Remove the building from the cache + my $idx = first_index {$_->id == $self->id} @{$body->building_cache}; + if (defined $idx) { + my @buildings = splice @{$body->building_cache},$idx,1; + $body->building_cache(\@buildings); + } $self->delete; $body->needs_recalc(1); $body->needs_surface_refresh(1); @@ -699,8 +705,9 @@ sub is_not_max_level { } else { confess [1013, - sprintf("The maximum level of this building is %d with your University level and stockpile.", - $max_level + $stockpile->extra_resource_levels) ]; + sprintf("The maximum level of this building is %d with your University level and stockpile.", + $max_level + $stockpile->extra_resource_levels), + ]; } } confess [1013, 'Resource buildings cannot upgrade above level '.$max_level.' without a Stockpile.']; @@ -754,7 +761,6 @@ sub cost_to_upgrade { my ($self) = @_; my $upgrade_cost = $self->upgrade_cost; my $upgrade_cost_reduction = $self->construction_cost_reduction_bonus; - my $plan; my $plan = $self->body->get_plan($self->class, $self->level + 1); if (defined $plan) { $upgrade_cost_reduction = 0; diff --git a/lib/Lacuna/DB/Result/Building/Development.pm b/lib/Lacuna/DB/Result/Building/Development.pm index aa9f0c01..619cf191 100644 --- a/lib/Lacuna/DB/Result/Building/Development.pm +++ b/lib/Lacuna/DB/Result/Building/Development.pm @@ -8,8 +8,7 @@ extends 'Lacuna::DB::Result::Building'; sub subsidize_build_queue { my ($self) = @_; $self->body->tick; - my $builds = $self->body->builds; - while (my $build = $builds->next) { + foreach my $build (@{$self->body->builds}) { $build->body($self->body); $build->finish_upgrade; } @@ -18,8 +17,7 @@ sub subsidize_build_queue { sub calculate_subsidy { my ($self) = @_; my $levels = 0; - my $builds = $self->body->builds; - while (my $build = $builds->next) { + foreach my $build (@{$self->body->builds}) { $levels += $build->level + 1; } my $cost = int($levels / 3); @@ -30,9 +28,8 @@ sub calculate_subsidy { sub format_build_queue { my ($self) = @_; my @queue; - my $builds = $self->body->builds; my $now = time; - while (my $build = $builds->next) { + foreach my $build (@{$self->body->builds}) { push @queue, { building_id => $build->id, name => $build->name, diff --git a/lib/Lacuna/DB/Result/Building/Permanent/GasGiantPlatform.pm b/lib/Lacuna/DB/Result/Building/Permanent/GasGiantPlatform.pm index 7df52e77..ac1d7234 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/GasGiantPlatform.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/GasGiantPlatform.pm @@ -27,13 +27,11 @@ before 'can_demolish' => sub { my $body = $self->body; return if ($body->get_type ne "gas giant"); - my $buildings = $body->buildings; - - my $gg_blds = $buildings->search({ class => 'Lacuna::DB::Result::Building::Permanent::GasGiantPlatform' }); my $gg_plots = 0; my $gg_cnt = 0; - while (my $gg_bld = $gg_blds->next) { + my @buildings = grep {$_->class eq 'Lacuna::DB::Result::Building::Permanent::GasGiantPlatform'} @{$body->building_cache}; + foreach my $gg_bld (@buildings) { $gg_cnt++; $gg_plots += int($gg_bld->level * $gg_bld->efficiency/100); } @@ -52,13 +50,11 @@ before 'can_downgrade' => sub { my $self = shift; my $body = $self->body; return if ($body->get_type ne "gas giant"); - my $buildings = $body->buildings; - - my $gg_blds = $buildings->search({ class => 'Lacuna::DB::Result::Building::Permanent::GasGiantPlatform' }); my $gg_plots = 0; my $gg_cnt = 0; - while (my $gg_bld = $gg_blds->next) { + my @buildings = grep {$_->class eq 'Lacuna::DB::Result::Building::Permanent::GasGiantPlatform'} @{$body->building_cache}; + foreach my $gg_bld (@buildings) { $gg_cnt++; $gg_plots += int($gg_bld->level * $gg_bld->efficiency/100); } diff --git a/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm b/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm index 2bba65dc..53142308 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm @@ -51,22 +51,19 @@ sub get_upgradable_buildings { body_id => $body->id, class => 'Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk', })->count; - my $buildings = Lacuna->db->resultset('Building')->search({ - body_id => $body->id, - })->count; - my $max_level = $halls + min(( 121 - $buildings), $plans); + + my $building_count = @{$self->body->building_cache}; + my $max_level = $halls + min(( 121 - $building_count), $plans); $max_level = 30 if $max_level > 30; - my $rs = $body->buildings->search({ - level => { '<' => $max_level }, - -and => [ - class => {like => 'Lacuna::DB::Result::Building::Permanent::%'}, - class => {'!=' => 'Lacuna::DB::Result::Building::Permanent::TheDillonForge'}, - class => {'!=' => 'Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk'}, - ], - is_upgrading => 0, - }); - return $rs; + my @buildings = grep { + ($_->level < $max_level) and + ($_->class =~ /Permanent/) and + ($_->class ne 'Lacuna::DB::Result::Building::Permanent::TheDillonForge') and + ($_->class ne 'Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk') and + ($_->is_upgrading == 0) + } @{$self->body->building_cache}; + return \@buildings; } use constant name => 'Halls of Vrbansk'; diff --git a/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm b/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm index 584c3267..88ed5f1e 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm @@ -23,15 +23,13 @@ around can_build => sub { before 'can_demolish' => sub { my $self = shift; my $body = $self->body; - my $buildings = $body->buildings; - return if ($body->orbit > $body->empire->min_orbit && $body->orbit < $body->empire->max_orbit); - - my $tp_blds = $buildings->search({ class => 'Lacuna::DB::Result::Building::Permanent::TerraformingPlatform' }); + return if ($body->orbit >= $body->empire->min_orbit && $body->orbit <= $body->empire->max_orbit); my $tp_plots = 0; my $tp_cnt = 0; - while (my $tp_bld = $tp_blds->next) { + my @buildings = grep {$_->class eq 'Lacuna::DB::Result::Building::Permanent::TerraformingPlatform'} @{$body->building_cache}; + foreach my $tp_bld (@buildings) { $tp_cnt++; $tp_plots += int($tp_bld->level * $tp_bld->efficiency/100); } @@ -49,15 +47,13 @@ before 'can_demolish' => sub { before 'can_downgrade' => sub { my $self = shift; my $body = $self->body; - my $buildings = $body->buildings; - return if ($body->orbit > $body->empire->max_orbit || $body->orbit < $body->empire->min_orbit); - - my $tp_blds = $buildings->search({ class => 'Lacuna::DB::Result::Building::Permanent::TerraformingPlatform' }); + return if ($body->orbit >= $body->empire->min_orbit && $body->orbit <= $body->empire->max_orbit); my $tp_plots = 0; my $tp_cnt = 0; - while (my $tp_bld = $tp_blds->next) { + my @buildings = grep {$_->class eq 'Lacuna::DB::Result::Building::Permanent::TerraformingPlatform'} @{$body->building_cache}; + foreach my $tp_bld (@buildings) { $tp_cnt++; $tp_plots += int($tp_bld->level * $tp_bld->efficiency/100); } diff --git a/lib/Lacuna/DB/Result/Building/Stockpile.pm b/lib/Lacuna/DB/Result/Building/Stockpile.pm index 55d13acd..94351d71 100644 --- a/lib/Lacuna/DB/Result/Building/Stockpile.pm +++ b/lib/Lacuna/DB/Result/Building/Stockpile.pm @@ -52,8 +52,7 @@ use constant water_storage => 300; before 'can_downgrade' => sub { my $self = shift; - my $buildings = $self->body->buildings; - while (my $building = $buildings->next) { + foreach my $building (@{$self->building_cache}) { if ($building->level > 15 + (($self->level - 1)/3) && 'Resources' ~~ [$building->build_tags] && !('Storage' ~~ [$building->build_tags])) { confess [1013, 'You have to downgrade your level '.$building->level.' '.$building->name.' to level 15 before you can downgrade the Stockpile.']; } @@ -62,8 +61,7 @@ before 'can_downgrade' => sub { before 'can_demolish' => sub { my $self = shift; - my $buildings = $self->body->buildings; - while (my $building = $buildings->next) { + foreach my $building (@{$self->building_cache}) { if ($building->level > 15 && 'Resources' ~~ [$building->build_tags] && !('Storage' ~~ [$building->build_tags])) { confess [1013, 'You have to downgrade your level '.$building->level.' '.$building->name.' to level 15 before you can demolish the Stockpile.']; } diff --git a/lib/Lacuna/DB/Result/Building/SubspaceSupplyDepot.pm b/lib/Lacuna/DB/Result/Building/SubspaceSupplyDepot.pm index 831bc10b..47c5c74a 100644 --- a/lib/Lacuna/DB/Result/Building/SubspaceSupplyDepot.pm +++ b/lib/Lacuna/DB/Result/Building/SubspaceSupplyDepot.pm @@ -93,8 +93,7 @@ sub complete_build_queue { } $self->work_ends($self->work_ends->subtract(seconds => $time_to_complete)); $self->update; - my $builds = $self->body->builds; - while (my $build = $builds->next) { + foreach my $build (@{$self->body->builds}) { $build->body($self->body); $build->finish_upgrade; } diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index bce8cf81..7c04eb7e 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -223,6 +223,7 @@ has building_cache => ( is => 'rw', lazy => 1, builder => '_build_building_cache', + clearer => 'clear_building_cache', ); sub _build_building_cache { diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 6c3a854f..ca9ec11b 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -6,7 +6,7 @@ use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Map::Body'; use Lacuna::Constants qw(FOOD_TYPES ORE_TYPES BUILDABLE_CLASSES SPACE_STATION_MODULES); -use List::Util qw(shuffle max); +use List::Util qw(shuffle max min); use Lacuna::Util qw(randint format_date); use DateTime; use Data::Dumper; @@ -32,6 +32,25 @@ sub _build_plan_cache { return \@plans; } +sub delete_building { + my ($self, $building) = @_; + + my $index = first_index {$_->id == $building->id} @{$self->building_cache}; + if (defined $index) { + my @buildings = splice(@{$self->building_cache}, $index, 1); + $self->building_cache(\@buildings); + } + $building->delete; +} + +sub delete_buildings { + my ($self, $buildings) = @_; + + foreach my $building (@$buildings) { + $self->delete_building($building); + } +} + sub surface { my $self = shift; return 'surface-'.$self->image; @@ -125,7 +144,10 @@ sub add_plan { sub sanitize { my ($self) = @_; - my $buildings = $self->buildings->search({class => { 'not like' => 'Lacuna::DB::Result::Building::Permanent%' } })->delete_all; + my @buildings = grep {$_->class !~ /Permanent$/} @{$self->building_cache}; + foreach my $building (@buildings) { + $self->delete_building($building); + } my @attributes = qw( happiness_hour happiness waste_hour waste_stored waste_capacity energy_hour energy_stored energy_capacity water_hour water_stored water_capacity ore_capacity rutile_stored chromite_stored chalcopyrite_stored galena_stored gold_stored uraninite_stored bauxite_stored @@ -550,7 +572,7 @@ has embassy => ( sub is_space_free { my ($self, $x, $y) = @_; - my $count = $self->buildings->search({x=>$x, y=>$y})->count; + my $count = grep {$_->x == $x and $_->y == $y} @{$self->building_cache}; return 0 if $count > 0; return 1; } @@ -624,7 +646,7 @@ sub has_room_in_build_queue { if (defined $dev_ministry) { $max += $dev_ministry->level; } - my $count = $self->builds->count; + my $count = @{$self->builds}; if ($count >= $max) { confess [1009, "There's no room left in the build queue.", $max]; } @@ -647,8 +669,8 @@ has future_operating_resources => ( } # adjust for what's already in build queue - my $queued_builds = $self->builds; - while (my $build = $queued_builds->next) { + my @queued_builds = @{$self->builds}; + foreach my $build (@queued_builds) { $build->body($self); my $other = $build->stats_after_upgrade; foreach my $method ($self->operating_resource_names) { @@ -727,19 +749,16 @@ sub has_max_instances_of_building { sub builds { my ($self, $reverse) = @_; - my $order = '-asc'; - if ($reverse) { - $order = '-desc'; - } - return Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( - { body_id => $self->id, is_upgrading => 1 }, - { order_by => { $order => 'upgrade_ends' } } - ); + + + my @buildings = sort {$a->upgrade_ends cmp $b->upgrade_ends} grep {$_->is_upgrading == 1} @{$self->building_cache}; + @buildings = reverse @buildings if $reverse; + return \@buildings; } sub get_existing_build_queue_time { my $self = shift; - my $building = $self->builds(1)->search(undef, {rows=>1})->single; + my ($building) = @{$self->builds(1)}; return (defined $building) ? $building->upgrade_ends : DateTime->now; } @@ -766,6 +785,7 @@ sub build_building { $building->insert; $building->body($self); $building->start_upgrade(undef, $in_parallel); + $self->building_cache([@{$self->building_cache}, $building]); } sub found_colony { @@ -782,11 +802,9 @@ sub found_colony { $type =~ s/^.*::(\w\d+)$/$1/; $empire->add_medal($type); - my $buildings = $self->buildings; - while (my $building = $buildings->next) { - if ($building->x == 0 and $building->y == 0) { + my ($building) = grep {$_->x == 0 and $_->y == 0} @{$self->building_cache}; + if (defined $building) { $building->delete; - } } # add command building @@ -834,7 +852,9 @@ sub convert_to_station { $empire->add_medal('space_station_deployed'); # clean it - $self->buildings->delete_all; + foreach my $building (@{$self->building_cache}) { + $self->delete_building($building); + } # add command building my $command = Lacuna->db->resultset('Lacuna::DB::Result::Building')->new({ @@ -936,6 +956,8 @@ sub recalc_chains { sub recalc_stats { my ($self) = @_; + $self->clear_building_cache; + my %stats = ( needs_recalc => 0 ); #reset foods and ores foreach my $type (FOOD_TYPES) { @@ -1072,14 +1094,14 @@ sub recalc_stats { # deal with plot usage my $max_plots = $self->size + $pantheon_of_hagness; if ($self->isa('Lacuna::DB::Result::Map::Body::Planet::GasGiant')) { - $max_plots = $gas_giant_platforms < $max_plots ? $gas_giant_platforms : $max_plots; + $max_plots = min($gas_giant_platforms, $max_plots); } if ($self->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { $max_plots = $stats{size} = $station_command * 3; } elsif ($self->isa('Lacuna::DB::Result::Map::Body::Planet')) { if ($self->orbit > $self->empire->max_orbit || $self->orbit < $self->empire->min_orbit) { - $max_plots = $terraforming_platforms < $max_plots ? $terraforming_platforms : $max_plots; + $max_plots = min($terraforming_platforms, $max_plots); } } $stats{plots_available} = $max_plots - $self->building_count; @@ -1151,20 +1173,12 @@ sub tick { my $i; # in case 2 things finish at exactly the same time # get building tasks - my $buildings = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search({ - body_id => $self->id, - -or => [ - -and => [ - is_upgrading => 1, - upgrade_ends => {'<=' => $now}, - ], - -and => [ - is_working => 1, - work_ends => {'<=' => $now}, - ], - ], - }); - while (my $building = $buildings->next) { + my @buildings = grep { + ($_->is_upgrading and $_->upgrade_ends->epoch <= $now_epoch) + or ($_->is_working and $_->work_ends->epoch <= $now_epoch) + } @{$self->building_cache}; + + foreach my $building (@buildings) { if ($building->is_upgrading && $building->upgrade_ends->epoch <= $now_epoch) { $todo{format_date($building->upgrade_ends).$i} = { object => $building, diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm index 8ebad2e8..cbe0a148 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm @@ -123,15 +123,26 @@ sub in_jurisdiction { has total_influence => ( is => 'rw', lazy => 1, - default => sub { - my $self = shift; - return $self->buildings - ->search({ class => { in => ['Lacuna::DB::Result::Building::Module::IBS','Lacuna::DB::Result::Building::Module::OperaHouse','Lacuna::DB::Result::Building::Module::CulinaryInstitute','Lacuna::DB::Result::Building::Module::ArtMuseum'] }}) - ->get_column('level') - ->sum; - }, + builder => '_build_total_influence', ); +sub _build_total_influence { + my ($self) = @_; + + my $influence = 0; + foreach my $building (@{$self->building_cache}) { + if ( + $building->class eq 'Lacuna::DB::Result::Building::Module::IBS' or + $building->class eq 'Lacuna::DB::Result::Building::Module::OperaHouse' or + $building->class eq 'Lacuna::DB::Result::Building::Module::CulinaryInstitute' or + $building->class eq 'Lacuna::DB::Result::Building::Module::ArtMuseum' + ) { + $influence += $building->level; + } + } + return $influence; +} + has influence_spent => ( is => 'rw', lazy => 1, @@ -149,16 +160,20 @@ sub influence_remaining { has range_of_influence => ( is => 'rw', lazy => 1, - default => sub { - my $self = shift; - return $self->buildings - ->search({ class => 'Lacuna::DB::Result::Building::Module::IBS'}) - ->get_column('level') - ->sum - * 1000; - }, + builder => '_build_range_of_influence', ); +sub _build_range_of_influence { + my ($self) = @_; + + my $range = 0; + my ($ibs) = grep {$_->class eq 'Lacuna::DB::Result::Building::Module::IBS'} @{$self->building_cache}; + if (defined $ibs) { + $range = $ibs->level * 1000; + } + return $range; +} + sub in_range_of_influence { my ($self, $star) = @_; if ($self->calculate_distance_to_target($star) > $self->range_of_influence) { diff --git a/lib/Lacuna/DB/Result/Propositions/DemolishModule.pm b/lib/Lacuna/DB/Result/Propositions/DemolishModule.pm index 6da9aa46..528b2e10 100644 --- a/lib/Lacuna/DB/Result/Propositions/DemolishModule.pm +++ b/lib/Lacuna/DB/Result/Propositions/DemolishModule.pm @@ -8,7 +8,7 @@ extends 'Lacuna::DB::Result::Propositions'; before pass => sub { my ($self) = @_; my $station = $self->station; - my $building = $station->buildings->find($self->scratch->{building_id}); + my ($building) = grep {$self->scratch->{building_id}} @{$station->building_cache}; if (defined $building) { $building->demolish; } diff --git a/lib/Lacuna/DB/Result/Propositions/DowngradeModule.pm b/lib/Lacuna/DB/Result/Propositions/DowngradeModule.pm index 7f468bcc..dbb26509 100644 --- a/lib/Lacuna/DB/Result/Propositions/DowngradeModule.pm +++ b/lib/Lacuna/DB/Result/Propositions/DowngradeModule.pm @@ -8,7 +8,7 @@ extends 'Lacuna::DB::Result::Propositions'; before pass => sub { my ($self) = @_; my $station = $self->station; - my $building = $station->buildings->find($self->scratch->{building_id}); + my ($building) = grep {$self->scratch->{building_id}} @{$station->building_cache}; if (defined $building) { $building->downgrade; } diff --git a/lib/Lacuna/DB/Result/Propositions/FireBfg.pm b/lib/Lacuna/DB/Result/Propositions/FireBfg.pm index bb0662c3..3d0581e6 100644 --- a/lib/Lacuna/DB/Result/Propositions/FireBfg.pm +++ b/lib/Lacuna/DB/Result/Propositions/FireBfg.pm @@ -11,8 +11,7 @@ before pass => sub { if (defined $body && $body->isa('Lacuna::DB::Result::Map::Body::Planet')) { if (eval {$self->station->in_jurisdiction($body)}) { if (defined $body->empire_id && $body->empire_id) { - my $buildings = $body->buildings; - while (my $building = $buildings->next) { + foreach my $building (@{$body->building_cache}) { next unless ('Infrastructure' ~~ [$building->build_tags]); next if ( $building->class eq 'Lacuna::DB::Result::Building::PlanetaryCommand' ); $building->efficiency(0); diff --git a/lib/Lacuna/DB/Result/Propositions/InstallModule.pm b/lib/Lacuna/DB/Result/Propositions/InstallModule.pm index 5106399e..577b3a99 100644 --- a/lib/Lacuna/DB/Result/Propositions/InstallModule.pm +++ b/lib/Lacuna/DB/Result/Propositions/InstallModule.pm @@ -8,7 +8,7 @@ extends 'Lacuna::DB::Result::Propositions'; before pass => sub { my ($self) = @_; my $station = $self->station; - my $building = $station->buildings->find($self->scratch->{building_id}); + my ($building) = grep {$self->scratch->{building_id}} @{$station->building_cache}; if (defined $building) { if ($building->is_upgrading && $building->level < $self->scratch->{to_level}) { $building->finish_upgrade; @@ -22,7 +22,7 @@ before pass => sub { before fail => sub { my ($self) = @_; my $station = $self->station; - my $building = $station->buildings->find($self->scratch->{building_id}); + my ($building) = grep {$self->scratch->{building_id}} @{$station->building_cache}; if (defined $building) { $station->add_plan($building->class, 1, $building->level); $building->demolish; diff --git a/lib/Lacuna/DB/Result/Propositions/RepairModule.pm b/lib/Lacuna/DB/Result/Propositions/RepairModule.pm index e4337cfd..a0cb64fb 100644 --- a/lib/Lacuna/DB/Result/Propositions/RepairModule.pm +++ b/lib/Lacuna/DB/Result/Propositions/RepairModule.pm @@ -8,7 +8,7 @@ extends 'Lacuna::DB::Result::Propositions'; before pass => sub { my ($self) = @_; my $station = $self->station; - my $building = $station->buildings->find($self->scratch->{building_id}); + my ($building) = grep {$self->scratch->{building_id}} @{$station->building_cache}; if (defined $building) { my $costs = $building->get_repair_costs; if (eval{$building->can_repair($costs)}) { diff --git a/lib/Lacuna/DB/Result/Propositions/UpgradeModule.pm b/lib/Lacuna/DB/Result/Propositions/UpgradeModule.pm index 9a246ec4..be905521 100644 --- a/lib/Lacuna/DB/Result/Propositions/UpgradeModule.pm +++ b/lib/Lacuna/DB/Result/Propositions/UpgradeModule.pm @@ -8,7 +8,7 @@ extends 'Lacuna::DB::Result::Propositions'; before pass => sub { my ($self) = @_; my $station = $self->station; - my $building = $station->buildings->find($self->scratch->{building_id}); + my ($building) = grep {$_->id == $self->scratch->{building_id}} @{$station->building_cache}; if (defined $building) { if ($building->is_upgrading && $building->level < $self->scratch->{to_level}) { $building->finish_upgrade; @@ -22,7 +22,7 @@ before pass => sub { before fail => sub { my ($self) = @_; my $station = $self->station; - my $building = $station->buildings->find($self->scratch->{building_id}); + my ($building) = grep {$_->id == $self->scratch->{building_id}} @{$station->building_cache}; if (defined $building) { $station->add_plan($building->class, $building->level + 1); if ($building->level == 0 ) { diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index f1d17a99..432a4a38 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -1724,15 +1724,12 @@ sub thwart_rebel { sub destroy_infrastructure { my ($self, $defender) = @_; - my $building = $self->on_body->buildings->search( - { efficiency => { '>' => 0 }, -# class => { 'not like' => 'Lacuna::DB::Result::Bulding::Permanent%' }, - }, - { rows=>1, order_by => 'rand()' } - )->single; + + my ($building) = sort {rand() <=> rand()} grep {$_->efficiency > 0} @{$self->on_body->building_cache}; + return $self->building_not_found->id unless defined $building; return $self->building_not_found->id if ($building->class eq 'Lacuna::DB::Result::PlanetaryCommand'); - $building->body($self->on_body); + $self->on_body->empire->send_predefined_message( tags => ['Spies','Alert'], filename => 'building_kablooey.txt', @@ -1757,36 +1754,6 @@ sub destroy_infrastructure { )->id; } -#sub destroy_upgrade { -# my ($self, $defender) = @_; -# my $builds = $self->on_body->builds(1); -# my $building = $builds->next; -# return $self->building_not_found->id unless defined $building; -# $building->body($self->on_body); -# $self->on_body->empire->send_predefined_message( -# tags => ['Spies','Alert'], -# filename => 'building_kablooey.txt', -# params => [$building->level + 1, $building->name, $self->on_body->id, $self->on_body->name], -# ); -# $self->things_destroyed( $self->things_destroyed + 1 ); -# $self->empire->send_predefined_message( -# tags => ['Intelligence'], -# filename => 'sabotage_report.txt', -# params => ['a level of their level '.($building->level + 1).' '.$building->name, $self->on_body->x, $self->on_body->y, $self->on_body->name, $self->name, $self->from_body->id, $self->from_body->name], -# ); -# $self->on_body->add_news(90,'%s was rocked today when a construction crane toppled into the %s.', $self->on_body->name, $building->name); -# if ($building->level == 0) { -# $building->delete; -# } -# else { -# $building->is_upgrading(0); -# $building->update; -# } -# $self->on_body->needs_surface_refresh(1); -# $self->on_body->needs_recalc(1); -# $self->on_body->update; -#} - sub destroy_ship { my ($self, $defender) = @_; my $ship = $self->on_body->ships->search( @@ -2140,24 +2107,22 @@ sub steal_ships { sub steal_building { my ($self, $defender) = @_; my $on_body = $self->on_body; - my $building = $on_body->buildings->search( - { - level => { '>' => 1 }, - class => { 'not in' => [ - 'Lacuna::DB::Result::Building::Permanent::EssentiaVein', - 'Lacuna::DB::Result::Building::Permanent::TheDillonForge', - 'Lacuna::DB::Result::Building::DeployedBleeder', - ], - }, - }, - { rows=>1, order_by => 'rand()' } - )->single; + my ($building) = sort { + rand() <=> rand() + } + grep { + ($_->class ne 'Lacuna::DB::Result::Building::Permanent::EssentiaVein') and + ($_->class ne 'Lacuna::DB::Result::Building::Permanent::TheDillonForge') and + ($_->class ne 'Lacuna::DB::Result::Building::DeployedBleeder') + } + @{$on_body->building_cache}; + return $self->building_not_found->id unless defined $building; $self->things_stolen( $self->things_stolen + 1 ); my $max = ($self->level > 30) ? 30 : $self->level; my $level = randint(1, $max); $level = $building->level if ($level > $building->level); - $building->body($on_body); + $building->downgrade(1); $self->from_body->add_plan($building->class, $level); $on_body->empire->send_predefined_message( @@ -2490,8 +2455,7 @@ sub colony_report { sub surface_report { my ($self, $defender) = @_; my @map; - my $buildings = $self->on_body->buildings; - while (my $building = $buildings->next) { + foreach my $building (@{$self->on_body->building_cache}) { push @map, { image => $building->image_level, x => $building->x, @@ -2633,8 +2597,7 @@ sub ship_report { sub build_queue_report { my ($self, $defender) = @_; my @report = (['Building', 'Level', 'Expected Completion']); - my $builds = $self->on_body->builds; - while (my $build = $builds->next) { + foreach my $build (@{$self->on_body->builds}) { push @report, [ $build->name, $build->level + 1, diff --git a/lib/Lacuna/RPC/Body.pm b/lib/Lacuna/RPC/Body.pm index fb378387..2aac8616 100644 --- a/lib/Lacuna/RPC/Body.pm +++ b/lib/Lacuna/RPC/Body.pm @@ -88,8 +88,8 @@ sub get_buildings { $body->update; } my %out; - my $buildings = $body->buildings; - while (my $building = $buildings->next) { + my @buildings = @{$body->building_cache}; + foreach my $building (@buildings) { $out{$building->id} = { url => $building->controller_class->app_url, image => $building->image_level, @@ -118,7 +118,6 @@ sub rearrange_buildings { my ($self, $session_id, $body_id, $arrangement) = @_; my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); - my $cur_bld = $body->buildings; my %cur_lay; my %new_lay; my %cur_ids; my %new_ids; my @miss_in_new; my @miss_in_cur; @@ -131,7 +130,7 @@ sub rearrange_buildings { y => $y, }; } - while (my $building = $cur_bld->next) { + foreach my $building (@{$body->building_cache}) { my $id = $building->id; my $x = $building->x; my $y = $building->y; diff --git a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm index 8ae8a299..b54fc7fc 100644 --- a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm +++ b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm @@ -562,7 +562,7 @@ sub bhg_make_asteroid { my ($building, $body) = @_; my $old_class = $body->class; my $old_size = $body->size; - $body->buildings->delete_all; + $body->delete_buildings(@{$body->building_cache}); my $new_size = int($building->level/5); $new_size = 10 if $new_size > 10; $body->update({ @@ -731,23 +731,22 @@ sub bhg_self_destruct { my ($building) = @_; my $body = $building->body; my $return = { - id => $body->id, - name => $body->name, + id => $body->id, + name => $body->name, }; $body->waste_stored(0); - my $bombed = $body->buildings; - my $bombs = $building->level; - for my $cnt (1..$bombs) { - my $placement = $bombed->search( - { class => { 'not in' => [ - 'Lacuna::DB::Result::Building::Permanent::Crater', - 'Lacuna::DB::Result::Building::DeployedBleeder', - ], - }, - }, - {order_by => { -desc => ['efficiency', 'rand()'] }, rows=>1} - )->single; + for (1..$building->level) { + my ($placement) = + sort { + $b->efficiency <=> $a->efficiency || + rand() <=> rand() + } + grep { + ($_->class ne 'Lacuna::DB::Result::Building::Permanent::Crater') and + ($_->class ne 'Lacuna::DB::Result::Building::DeployedBleeder') + } @{$body->building_cache}; + last unless defined($placement); my $amount = randint(10, 100); $placement->spend_efficiency($amount)->update; diff --git a/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm b/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm index 7debbd73..f052267b 100644 --- a/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm +++ b/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm @@ -18,8 +18,8 @@ sub get_upgradable_buildings { my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); my @buildings; - my $upgradable = $building->get_upgradable_buildings; - while (my $building = $upgradable->next) { + my @upgradable = @{$building->get_upgradable_buildings}; + foreach my $building (@upgradable) { next if ($building->level > $empire->university_level); push @buildings, { id => $building->id, @@ -41,12 +41,12 @@ sub sacrifice_to_upgrade { my ($self, $session_id, $building_id, $upgrade_id) = @_; my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - my $upgrade = $building->body->buildings->find($upgrade_id); + my ($upgrade) = grep {$_->id == $upgrade_id} @{$building->body->building_cache}; unless (defined $upgrade) { confess [1002, 'Could not find the building to upgrade.']; } - my @upgradable = $building->get_upgradable_buildings->get_column('id')->all; - unless ($upgrade->id ~~ \@upgradable) { + my $is_upgradable = grep {$_->id == $upgrade->id} @{$building->get_upgradable_buildings}; + unless ($is_upgradable) { confess [1009, 'The Halls of Vrbansk do not have the knowledge necessary to upgrade the '.$upgrade->name]; } my $body = $building->body; diff --git a/lib/Lacuna/RPC/Building/TempleOfTheDrajilites.pm b/lib/Lacuna/RPC/Building/TempleOfTheDrajilites.pm index 0292a6a8..6eba4ca4 100644 --- a/lib/Lacuna/RPC/Building/TempleOfTheDrajilites.pm +++ b/lib/Lacuna/RPC/Building/TempleOfTheDrajilites.pm @@ -31,8 +31,8 @@ sub view_planet { } my @map; - my $buildings = $planet->buildings; - while (my $building = $buildings->next) { + my @buildings = @{$planet->building_cache}; + foreach my $building (@buildings) { push @map, { image => $building->image_level, x => $building->x, diff --git a/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm b/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm index bb4c0781..9ff21d89 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm @@ -15,10 +15,9 @@ after handle_arrival_procedures => sub { my $amount = randint(10,70); # determine target building - my $body_attacked = $self->foreign_body; - my $buildings = $body_attacked->buildings; my $building; - my $citadel = $buildings->search({class=>'Lacuna::DB::Result::Building::Permanent::CitadelOfKnope'},{rows=>1})->single; + my $body_attacked = $self->foreign_body; + my ($citadel) = grep {$_->class eq 'Lacuna::DB::Result::Building::Permanent::CitadelOfKnope'} @{$body_attacked->building_cache}; if (defined $citadel) { $building = $citadel; } @@ -27,18 +26,19 @@ after handle_arrival_procedures => sub { $building ||= $body_attacked->get_building_of_class($tb); } } - $building ||= $buildings->search( - { - class => { 'not in' => [ - 'Lacuna::DB::Result::Building::Permanent::Crater', - 'Lacuna::DB::Result::Building::DeployedBleeder', - ], - }, - }, - {order_by => { -desc => ['efficiency', 'rand()'] }, rows=>1} - )->single; - return unless defined $building; - $building->body($body_attacked); + if (not defined $building) { + ($building) = + sort { + $b->efficiency <=> $a->efficiency || + rand() <=> rand() + } + grep { + ($_->class ne 'Lacuna::DB::Result::Building::Permanent::Crater') and + ($_->class ne 'Lacuna::DB::Result::Building::DeployedBleeder') and + ($_->class ne 'Lacuna::DB::Result::Building::TheDillonForge') + } @{$body_attacked->building_cache}; + } + return if not defined $building; # let everyone know what's going on unless ($body_attacked->empire->skip_attack_messages) { @@ -108,11 +108,17 @@ after handle_arrival_procedures => sub { if ($self->splash_radius) { foreach my $i (1..$self->splash_radius) { $amount /= $i + 1; - my $splashed = $buildings->search({ - x => { between => [$building->x - $i, $building->x + $i] }, - y => { between => [$building->y - $i, $building->y + $i] }, - }); - while (my $damaged = $splashed->next) { + my @splashed = + grep { + ($_->x > $building->x - $i) and + ($_->x < $building->x + $i) and + ($_->y > $building->y - $i) and + ($_->y < $building->y + $i) and + ($_->class ne 'Lacuna::DB::Result::Building::Permanent::Crater') and + ($_->class ne 'Lacuna::DB::Result::Building::DeployedBleeder') and + ($_->class ne 'Lacuna::DB::Result::Building::TheDillonForge') + } @{$body_attacked->building_cache}; + foreach my $damaged (@splashed) { $damaged->body($body_attacked); $damaged->spend_efficiency($amount)->update; } diff --git a/lib/Lacuna/Role/Ship/Arrive/ScanSurface.pm b/lib/Lacuna/Role/Ship/Arrive/ScanSurface.pm index 4bf2442e..4a1f5e17 100644 --- a/lib/Lacuna/Role/Ship/Arrive/ScanSurface.pm +++ b/lib/Lacuna/Role/Ship/Arrive/ScanSurface.pm @@ -23,8 +23,7 @@ after handle_arrival_procedures => sub { # do the scan my @map; - my $buildings = $body_attacked->buildings; - while (my $building = $buildings->next) { + foreach my $building (@{$body_attacked->building_cache}) { push @map, { image => $building->image_level, x => $building->x, diff --git a/lib/Lacuna/Role/Ship/Arrive/SurveySurface.pm b/lib/Lacuna/Role/Ship/Arrive/SurveySurface.pm index 3100229f..6540cf4d 100644 --- a/lib/Lacuna/Role/Ship/Arrive/SurveySurface.pm +++ b/lib/Lacuna/Role/Ship/Arrive/SurveySurface.pm @@ -25,8 +25,7 @@ after handle_arrival_procedures => sub { # do the scan my @map; my @table = ([qw(Name Level X Y Efficiency)]); - my $buildings = $body_attacked->buildings->search(undef,{order_by => ['x','y']}); - while (my $building = $buildings->next) { + foreach my $building (sort {$a->x <=> $b->x || $a->y <=> $b->y} @{$body_attacked->building_cache}) { push @map, { image => $building->image_level, x => $building->x, diff --git a/t/TestHelper.pm b/t/TestHelper.pm index 6c126229..32007a26 100644 --- a/t/TestHelper.pm +++ b/t/TestHelper.pm @@ -64,7 +64,8 @@ sub clear_all_test_empires { my $planets = $empire->planets; while ( my $planet = $planets->next ) { - $planet->buildings->search({class => { 'like' => 'Lacuna::DB::Result::Building::Permanent%' } })->delete_all; + my @buildings = grep {$_->class =~ /Permanent/} @{$planet->building_cache}; + $planet->delete_buildings(\@buildings); } @@ -234,7 +235,8 @@ sub cleanup { my $planets = $empire->planets; while ( my $planet = $planets->next ) { - $planet->buildings->search({class => { 'like' => 'Lacuna::DB::Result::Building::Permanent%' } })->delete_all; + my @buildings = grep {$_->class =~ /Permanent/} @{$planet->building_cache}; + $planet->delete_buildings(\@buildings); } $empire->delete; @@ -252,7 +254,7 @@ sub build_big_colony { my ($self, $planet) = @_; my $empire = $planet->empire; - $planet->buildings->search({})->delete_all; + $planet->delete_buildings(@{$planet->building_cache}); $planet->ships->delete_all; Lacuna->db->resultset('Spies')->search({from_body_id => $planet->id})->delete_all; @@ -401,7 +403,7 @@ sub build_big_colony { $planet->update; $planet->tick; - my ($shipyard) = $planet->buildings->search({ class => 'Lacuna::DB::Result::Building::Shipyard' }); + my ($shipyard) = grep {$_->class eq 'Lacuna::DB::Result::Building::Shipyard'} @{$planet->building_cache}; diag("Generating ships [".$self->session->id."][".$shipyard->id."]"); my $ships = { excavator => 30, -- 2.51.2 From 36a33446437e18cb8d185b984520685b494f63be Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 15:57:24 -0600 Subject: [PATCH 027/105] Trades in transit now pass under control of capitol. --- lib/Lacuna/DB/Result/Spies.pm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 7e5d3504..b2fd582b 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -1404,9 +1404,14 @@ sub steal_planet { ->search({body_id => $self->on_body_id, task => { '!=' => 'Docked' } }); while (my $ship = $ships->next) { - next if ($ship->task eq 'Waiting On Trade'); next if ($ship->task eq 'Waste Chain'); - if ($ship->task eq 'Supply Chain') { + if ($ship->task eq 'Waiting On Trade') { +# Ships being delivered from trades or pushes. + $ship->body_id($defender_capitol_id); + $ship->update; + } + elsif ($ship->task eq 'Supply Chain') { +# Supply chains from planet were deleted so we dock ships $ship->task('Docked'); $ship->update; } @@ -1422,17 +1427,18 @@ sub steal_planet { 'dory', 'barge', ]})) { +# Trade ship was outgoing, it will change homeport to capitol if ($ship->direction eq 'out') { $ship->body_id($defender_capitol_id); $ship->update; } - next; } elsif ($ship->task eq 'Travelling' and (grep { $ship->type eq $_ } @{[ 'colony_ship', 'short_range_colony_ship', ]})) { +# Colony ships show from capitol. $ship->body_id($defender_capitol_id); $ship->update; } -- 2.51.2 From 382c68fe8ec599c97ea01397bfbf6b0f7cb79bc4 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 16:43:02 -0600 Subject: [PATCH 028/105] Withdraw trades associated with demolished buildings --- .../DB/Result/Building/MercenariesGuild.pm | 17 ++++++++++++++ lib/Lacuna/DB/Result/Building/SpacePort.pm | 22 ++++++++++++++++--- lib/Lacuna/DB/Result/Building/Trade.pm | 13 +++++++++++ lib/Lacuna/RPC/Building/MercenariesGuild.pm | 6 ++--- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm b/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm index 1012053a..566bd59e 100644 --- a/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm +++ b/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm @@ -116,5 +116,22 @@ sub next_available_trade_ship { } } +before delete => sub { + my ($self) = @_; + for my $market ( Lacuna->db->resultset('Lacuna::DB::Result::MercenaryMarket') ) { + my @to_be_deleted = $market->search({body_id => $self->body_id})->get_column('id')->all; + foreach my $id (@to_be_deleted) { + my $trade = $market->find($id); + next unless defined $trade; + $trade->body->empire->send_predefined_message( + filename => 'trade_withdrawn.txt', + params => [join("\n",@{$trade->format_description_of_payload}), $trade->ask.' essentia'], + tags => ['Trade','Alert'], + ); + $trade->withdraw; + } + } +}; + no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Building/SpacePort.pm b/lib/Lacuna/DB/Result/Building/SpacePort.pm index f11b5023..2aa53716 100644 --- a/lib/Lacuna/DB/Result/Building/SpacePort.pm +++ b/lib/Lacuna/DB/Result/Building/SpacePort.pm @@ -104,10 +104,26 @@ sub find_ship { } before delete => sub { - my ($self) = @_; - unless (Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { class => $self->class, body_id => $self->body_id, id => {'!=', $self->id } } )->count) { - $self->ships->delete_all; + my ($self) = @_; + unless (Lacuna->db->resultset('Lacuna::DB::Result::Building') + ->search( { class => $self->class, + body_id => $self->body_id, + id => {'!=', $self->id } } )->count) { + for my $market ( Lacuna->db->resultset('Lacuna::DB::Result::Market') ) { + my @to_be_deleted = $market->search({body_id => $self->body_id, transfer_type => 'trade'})->get_column('id')->all; + foreach my $id (@to_be_deleted) { + my $trade = $market->find($id); + next unless defined $trade; + $trade->body->empire->send_predefined_message( + filename => 'trade_withdrawn.txt', + params => [join("\n",@{$trade->format_description_of_payload}), $trade->ask.' essentia'], + tags => ['Trade','Alert'], + ); + $trade->withdraw; + } } + $self->ships->delete_all; + } }; before 'can_downgrade' => sub { diff --git a/lib/Lacuna/DB/Result/Building/Trade.pm b/lib/Lacuna/DB/Result/Building/Trade.pm index 3664ae9b..84eb3dd7 100644 --- a/lib/Lacuna/DB/Result/Building/Trade.pm +++ b/lib/Lacuna/DB/Result/Building/Trade.pm @@ -278,6 +278,19 @@ sub recalc_waste_production { before delete => sub { my ($self) = @_; + for my $market ( Lacuna->db->resultset('Lacuna::DB::Result::Market') ) { + my @to_be_deleted = $market->search({body_id => $self->body_id, transfer_type => 'trade'})->get_column('id')->all; + foreach my $id (@to_be_deleted) { + my $trade = $market->find($id); + next unless defined $trade; + $trade->body->empire->send_predefined_message( + filename => 'trade_withdrawn.txt', + params => [join("\n",@{$trade->format_description_of_payload}), $trade->ask.' essentia'], + tags => ['Trade','Alert'], + ); + $trade->withdraw; + } + } $self->waste_ships->update({task=>'Docked'}); $self->waste_chains->delete_all; $self->body->needs_recalc(1); diff --git a/lib/Lacuna/RPC/Building/MercenariesGuild.pm b/lib/Lacuna/RPC/Building/MercenariesGuild.pm index 5ee83398..8ef8b159 100644 --- a/lib/Lacuna/RPC/Building/MercenariesGuild.pm +++ b/lib/Lacuna/RPC/Building/MercenariesGuild.pm @@ -91,11 +91,11 @@ sub accept_from_market { if ($trade->body->empire->id == $empire->id) { # Selling to oneself - $empire->spend_essentia(0, 'Mercanary Price', 0, $trade->body->empire->id, $trade->body->empire->name )->update; + $empire->spend_essentia(0, 'Mercenary Price', 0, $trade->body->empire->id, $trade->body->empire->name )->update; } else { - $empire->spend_essentia($trade->ask, 'Mercanary Price', 0, $trade->body->empire->id, $trade->body->empire->name )->update; - $trade->body->empire->add_essentia($trade->ask, 'Mercanary Income', 0, $empire->id, $empire->name)->update; + $empire->spend_essentia($trade->ask, 'Mercenary Price', 0, $trade->body->empire->id, $trade->body->empire->name )->update; + $trade->body->empire->add_essentia($trade->ask, 'Mercenary Income', 0, $empire->id, $empire->name)->update; } #my $cargo_log = Lacuna->db->resultset('Lacuna::DB::Result::Log::Cargo'); #$cargo_log->new({ -- 2.51.2 From 75585a120cd253b65d39fcbcc4403fd7f89c368d Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 17:26:43 -0600 Subject: [PATCH 029/105] Couple logic errors fixed, and hopefully a cleaner method. --- .../DB/Result/Building/MercenariesGuild.pm | 27 +++++++------- lib/Lacuna/DB/Result/Building/SpacePort.pm | 14 ++++++- lib/Lacuna/DB/Result/Building/Trade.pm | 37 ++++++++++--------- lib/Lacuna/DB/Result/Building/Transporter.pm | 18 +++++++++ 4 files changed, 62 insertions(+), 34 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm b/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm index 566bd59e..f63ab3f4 100644 --- a/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm +++ b/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm @@ -117,20 +117,19 @@ sub next_available_trade_ship { } before delete => sub { - my ($self) = @_; - for my $market ( Lacuna->db->resultset('Lacuna::DB::Result::MercenaryMarket') ) { - my @to_be_deleted = $market->search({body_id => $self->body_id})->get_column('id')->all; - foreach my $id (@to_be_deleted) { - my $trade = $market->find($id); - next unless defined $trade; - $trade->body->empire->send_predefined_message( - filename => 'trade_withdrawn.txt', - params => [join("\n",@{$trade->format_description_of_payload}), $trade->ask.' essentia'], - tags => ['Trade','Alert'], - ); - $trade->withdraw; - } - } + my ($self) = @_; + my $market = Lacuna->db->resultset('Lacuna::DB::Result::MercenaryMarket'); + my @to_be_deleted = $market->search({body_id => $self->body_id})->get_column('id')->all; + foreach my $id (@to_be_deleted) { + my $trade = $market->find($id); + next unless defined $trade; + $trade->body->empire->send_predefined_message( + filename => 'trade_withdrawn.txt', + params => [$trade->format_description_of_payload, $trade->ask.' essentia'], + tags => ['Trade','Alert'], + ); + $trade->withdraw($self->body); + } }; no Moose; diff --git a/lib/Lacuna/DB/Result/Building/SpacePort.pm b/lib/Lacuna/DB/Result/Building/SpacePort.pm index 2aa53716..e97fdf18 100644 --- a/lib/Lacuna/DB/Result/Building/SpacePort.pm +++ b/lib/Lacuna/DB/Result/Building/SpacePort.pm @@ -109,8 +109,18 @@ before delete => sub { ->search( { class => $self->class, body_id => $self->body_id, id => {'!=', $self->id } } )->count) { - for my $market ( Lacuna->db->resultset('Lacuna::DB::Result::Market') ) { - my @to_be_deleted = $market->search({body_id => $self->body_id, transfer_type => 'trade'})->get_column('id')->all; + my @markets = [ + { market => 'Lacuna::DB::Result::Market', + search => { body_id => $self->body_id, transfer_type => 'trade' } + }, + { market => 'Lacuna::DB::Result::MercenaryMarket', + search => { body_id => $self->body_id } + }, + ]; + + + for my $market ( @markets ) { + my @to_be_deleted = $market->{market}->search($market->{search})->get_column('id')->all; foreach my $id (@to_be_deleted) { my $trade = $market->find($id); next unless defined $trade; diff --git a/lib/Lacuna/DB/Result/Building/Trade.pm b/lib/Lacuna/DB/Result/Building/Trade.pm index 84eb3dd7..5d4d668a 100644 --- a/lib/Lacuna/DB/Result/Building/Trade.pm +++ b/lib/Lacuna/DB/Result/Building/Trade.pm @@ -277,24 +277,25 @@ sub recalc_waste_production { } before delete => sub { - my ($self) = @_; - for my $market ( Lacuna->db->resultset('Lacuna::DB::Result::Market') ) { - my @to_be_deleted = $market->search({body_id => $self->body_id, transfer_type => 'trade'})->get_column('id')->all; - foreach my $id (@to_be_deleted) { - my $trade = $market->find($id); - next unless defined $trade; - $trade->body->empire->send_predefined_message( - filename => 'trade_withdrawn.txt', - params => [join("\n",@{$trade->format_description_of_payload}), $trade->ask.' essentia'], - tags => ['Trade','Alert'], - ); - $trade->withdraw; - } - } - $self->waste_ships->update({task=>'Docked'}); - $self->waste_chains->delete_all; - $self->body->needs_recalc(1); - $self->body->update; + my ($self) = @_; + + my $market = Lacuna->db->resultset('Lacuna::DB::Result::Market'); + my @to_be_deleted = $market->search( { body_id => $self->body_id, + transfer_type => 'trade'} )->get_column('id')->all; + foreach my $id (@to_be_deleted) { + my $trade = $market->find($id); + next unless defined $trade; + $trade->body->empire->send_predefined_message( + filename => 'trade_withdrawn.txt', + params => [join("\n",@{$trade->format_description_of_payload}), $trade->ask.' essentia'], + tags => ['Trade','Alert'], + ); + $trade->withdraw; + } + $self->waste_ships->update({task=>'Docked'}); + $self->waste_chains->delete_all; + $self->body->needs_recalc(1); + $self->body->update; }; before 'can_downgrade' => sub { diff --git a/lib/Lacuna/DB/Result/Building/Transporter.pm b/lib/Lacuna/DB/Result/Building/Transporter.pm index 94d8bbd5..29523b71 100644 --- a/lib/Lacuna/DB/Result/Building/Transporter.pm +++ b/lib/Lacuna/DB/Result/Building/Transporter.pm @@ -146,5 +146,23 @@ sub push_items { $container->unload($target); } +before delete => sub { + my ($self) = @_; + + my $market = Lacuna->db->resultset('Lacuna::DB::Result::Market'); + my @to_be_deleted = $market->search( { body_id => $self->body_id, + transfer_type => 'transporter'} )->get_column('id')->all; + foreach my $id (@to_be_deleted) { + my $trade = $market->find($id); + next unless defined $trade; + $trade->body->empire->send_predefined_message( + filename => 'trade_withdrawn.txt', + params => [join("\n",@{$trade->format_description_of_payload}), $trade->ask.' essentia'], + tags => ['Trade','Alert'], + ); + $trade->withdraw; + } +}; + no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); -- 2.51.2 From 58eaef760f9a0058d7341cfd5a83920c5c9a9aa5 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 17:47:36 -0600 Subject: [PATCH 030/105] Hash fix. --- lib/Lacuna/DB/Result/Building/SpacePort.pm | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/SpacePort.pm b/lib/Lacuna/DB/Result/Building/SpacePort.pm index e97fdf18..ec717954 100644 --- a/lib/Lacuna/DB/Result/Building/SpacePort.pm +++ b/lib/Lacuna/DB/Result/Building/SpacePort.pm @@ -109,25 +109,25 @@ before delete => sub { ->search( { class => $self->class, body_id => $self->body_id, id => {'!=', $self->id } } )->count) { - my @markets = [ - { market => 'Lacuna::DB::Result::Market', - search => { body_id => $self->body_id, transfer_type => 'trade' } - }, - { market => 'Lacuna::DB::Result::MercenaryMarket', - search => { body_id => $self->body_id } - }, - ]; - - - for my $market ( @markets ) { - my @to_be_deleted = $market->{market}->search($market->{search})->get_column('id')->all; + my @markets = [ + { market => 'Lacuna::DB::Result::Market', + search => { body_id => $self->body_id, transfer_type => 'trade' } + }, + { market => 'Lacuna::DB::Result::MercenaryMarket', + search => { body_id => $self->body_id } + }, + ]; + + for my $market_hash ( @markets ) { + my $market = Lacuna->db->resultset($market_hash->{market}); + my @to_be_deleted = $market->search($market_hash->{search})->get_column('id')->all; foreach my $id (@to_be_deleted) { my $trade = $market->find($id); next unless defined $trade; $trade->body->empire->send_predefined_message( - filename => 'trade_withdrawn.txt', - params => [join("\n",@{$trade->format_description_of_payload}), $trade->ask.' essentia'], - tags => ['Trade','Alert'], + filename => 'trade_withdrawn.txt', + params => [join("\n",@{$trade->format_description_of_payload}), $trade->ask.' essentia'], + tags => ['Trade','Alert'], ); $trade->withdraw; } -- 2.51.2 From 5d35ea92d467af71c9c163349432a35473c153c0 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 17:58:12 -0600 Subject: [PATCH 031/105] brain hash --- lib/Lacuna/DB/Result/Building/SpacePort.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/SpacePort.pm b/lib/Lacuna/DB/Result/Building/SpacePort.pm index ec717954..e901bd86 100644 --- a/lib/Lacuna/DB/Result/Building/SpacePort.pm +++ b/lib/Lacuna/DB/Result/Building/SpacePort.pm @@ -109,7 +109,7 @@ before delete => sub { ->search( { class => $self->class, body_id => $self->body_id, id => {'!=', $self->id } } )->count) { - my @markets = [ + my $markets = [ { market => 'Lacuna::DB::Result::Market', search => { body_id => $self->body_id, transfer_type => 'trade' } }, @@ -118,7 +118,7 @@ before delete => sub { }, ]; - for my $market_hash ( @markets ) { + for my $market_hash ( @{$markets} ) { my $market = Lacuna->db->resultset($market_hash->{market}); my @to_be_deleted = $market->search($market_hash->{search})->get_column('id')->all; foreach my $id (@to_be_deleted) { -- 2.51.2 From 71ee71ab749c58150c4a413bff33c4644eca378b Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 18:23:39 -0600 Subject: [PATCH 032/105] Standardizing payload format for mercs. --- .../DB/Result/Building/MercenariesGuild.pm | 2 +- lib/Lacuna/DB/Result/MercenaryMarket.pm | 25 +++++++++---------- lib/Lacuna/RPC/Building/MercenariesGuild.pm | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm b/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm index f63ab3f4..a51489d4 100644 --- a/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm +++ b/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm @@ -125,7 +125,7 @@ before delete => sub { next unless defined $trade; $trade->body->empire->send_predefined_message( filename => 'trade_withdrawn.txt', - params => [$trade->format_description_of_payload, $trade->ask.' essentia'], + params => [join("\n",@{$trade->format_description_of_payload}), $trade->ask.' essentia'], tags => ['Trade','Alert'], ); $trade->withdraw($self->body); diff --git a/lib/Lacuna/DB/Result/MercenaryMarket.pm b/lib/Lacuna/DB/Result/MercenaryMarket.pm index fb68cabf..e7bc6e17 100644 --- a/lib/Lacuna/DB/Result/MercenaryMarket.pm +++ b/lib/Lacuna/DB/Result/MercenaryMarket.pm @@ -26,21 +26,20 @@ sub date_offered_formatted { } sub format_description_of_payload { - my ($self) = @_; - my $payload = $self->payload; + my ($self) = @_; + my $payload = $self->payload; - my $item = ''; - if (exists $payload->{mercenary}) { - my $spy = Lacuna->db->resultset('Lacuna::DB::Result::Spies')->find($payload->{mercenary}); - if (defined $spy) { - $item = sprintf("Level %d spy named %s (Mercenary Transport) Offense: %d, Defense: %d, Intel: %d, Mayhem: %d, Politics: %d, Theft: %d, Mission Count Offensive: %d Defensive: %d)", - $spy->level, $spy->name, $spy->offense, $spy->defense, - $spy->intel_xp, $spy->mayhem_xp, $spy->politics_xp, $spy->theft_xp, - $spy->offense_mission_count, $spy->defense_mission_count); - } + my $item_arr = []; + if (exists $payload->{mercenary}) { + my $spy = Lacuna->db->resultset('Lacuna::DB::Result::Spies')->find($payload->{mercenary}); + if (defined $spy) { + $item_arr = [ sprintf( "Level %d spy named %s (Mercenary Transport) Offense: %d, Defense: %d, Intel: %d, Mayhem: %d, Politics: %d, Theft: %d, Mission Count Offensive: %d Defensive: %d)", + $spy->level, $spy->name, $spy->offense, $spy->defense, + $spy->intel_xp, $spy->mayhem_xp, $spy->politics_xp, $spy->theft_xp, + $spy->offense_mission_count, $spy->defense_mission_count) ]; } - - return $item; + } + return $item_arr; } sub withdraw { diff --git a/lib/Lacuna/RPC/Building/MercenariesGuild.pm b/lib/Lacuna/RPC/Building/MercenariesGuild.pm index 8ef8b159..e9dc7d69 100644 --- a/lib/Lacuna/RPC/Building/MercenariesGuild.pm +++ b/lib/Lacuna/RPC/Building/MercenariesGuild.pm @@ -122,7 +122,7 @@ sub accept_from_market { $trade->body->empire->send_predefined_message( tags => ['Trade','Alert'], filename => 'trade_accepted.txt', - params => [$trade->format_description_of_payload, $trade->ask.' essentia', $empire->id, $empire->name], + params => [join("\n",@{$trade->format_description_of_payload}), $trade->ask.' essentia', $empire->id, $empire->name], ); } $trade->delete; -- 2.51.2 From 23f61edfc8e8b9eab2c4caf590ce403a7f2afd0f Mon Sep 17 00:00:00 2001 From: ian docherty Date: Wed, 23 May 2012 13:34:42 -0400 Subject: [PATCH 033/105] Further places where the code can use the buildings cache --- bin/saben/create_colony.pl | 3 +-- bin/saben/create_colony2.pl | 3 +-- bin/saben/create_colony3.pl | 3 +-- bin/summarize_server.pl | 6 +++--- lib/Lacuna/AI.pm | 3 +-- lib/Lacuna/DB/Result/Empire.pm | 3 +-- lib/Lacuna/DB/Result/Map/Body.pm | 31 ++++++++++++++++++++++++++++--- lib/Lacuna/Web/Admin.pm | 9 +++------ t/bugs/0022_SurfaceRefresh.t | 2 +- t/bugs/0028_PlansInRandomOrder.t | 2 +- 10 files changed, 41 insertions(+), 24 deletions(-) diff --git a/bin/saben/create_colony.pl b/bin/saben/create_colony.pl index d956e480..784f612a 100644 --- a/bin/saben/create_colony.pl +++ b/bin/saben/create_colony.pl @@ -41,8 +41,7 @@ die 'Could not find a colony to occupy.' unless defined $body; say $body->name; out('Clearing unneeded structures...'); -my $buildings = $body->buildings; -while (my $building = $buildings->next) { +foreach my $building (@{$body->building_cache}) { $building->delete; } diff --git a/bin/saben/create_colony2.pl b/bin/saben/create_colony2.pl index 218cd523..29d56258 100644 --- a/bin/saben/create_colony2.pl +++ b/bin/saben/create_colony2.pl @@ -43,8 +43,7 @@ die 'Could not find a colony to occupy.' unless defined $body; say $body->name; out('Clearing unneeded structures...'); -my $buildings = $body->buildings; -while (my $building = $buildings->next) { +foreach my $building (@{$body->building_cache}) { $building->delete; } diff --git a/bin/saben/create_colony3.pl b/bin/saben/create_colony3.pl index e3bf4f54..66f536d2 100644 --- a/bin/saben/create_colony3.pl +++ b/bin/saben/create_colony3.pl @@ -43,8 +43,7 @@ die 'Could not find a colony to occupy.' unless defined $body; say $body->name; out('Clearing unneeded structures...'); -my $buildings = $body->buildings; -while (my $building = $buildings->next) { +foreach my $building (@{$body->building_cache}) { $building->delete; } diff --git a/bin/summarize_server.pl b/bin/summarize_server.pl index 0dee78ed..8fe9735d 100644 --- a/bin/summarize_server.pl +++ b/bin/summarize_server.pl @@ -434,11 +434,11 @@ sub summarize_colonies { my %colony_data = ( date_stamp => DateTime->now, planet_name => $planet->name, - building_count => $planet->buildings->count, + building_count => @{ $planet->building_cache }, population => $planet->population, population_delta => (defined $log ? $log->population_delta + $planet->population - $log->population : $planet->population ), - average_building_level => $planet->buildings->get_column('level')->func('avg'), - highest_building_level => $planet->buildings->get_column('level')->max, + average_building_level => $planet->building_avg_level, + highest_building_level => $planet->building_max_level, food_hour => $planet->food_hour, water_hour => $planet->water_hour, waste_hour => $planet->waste_hour, diff --git a/lib/Lacuna/AI.pm b/lib/Lacuna/AI.pm index 533c4300..7f4fcc66 100644 --- a/lib/Lacuna/AI.pm +++ b/lib/Lacuna/AI.pm @@ -185,8 +185,7 @@ sub run_missions { sub repair_buildings { my ($self, $colony) = @_; say 'REPAIR DAMAGED BUILDINGS'; - my $buildings = $colony->buildings; - while (my $building = $buildings->next) { + foreach my $building (@{$colony->building_cache}) { if ($building->efficiency < 100) { say " ".$building->name." needs repairing"; my $costs = $building->get_repair_costs; diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index c8057d72..63ce633c 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -483,8 +483,7 @@ sub found { Lacuna::DB::Result::Building::Permanent::RockyOutcrop Lacuna::DB::Result::Building::Permanent::Sand )]; - my $buildings = $home_planet->buildings->search; - while (my $building = $buildings->next) { + foreach my $building (@{$home_planet->building_cache}) { unless ( grep { $building->class eq $_ } @{$decor}) { $building->delete; } diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index 7c04eb7e..4a312b57 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -2,7 +2,7 @@ package Lacuna::DB::Result::Map::Body; use Moose; use utf8; -use List::Util qw(max); +use List::Util qw(max reduce); no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Map'; @@ -217,7 +217,7 @@ after 'sqlt_deploy_hook' => sub { __PACKAGE__->belongs_to('star', 'Lacuna::DB::Result::Map::Star', 'star_id'); __PACKAGE__->belongs_to('alliance', 'Lacuna::DB::Result::Alliance', 'alliance_id', { on_delete => 'set null' }); __PACKAGE__->belongs_to('empire', 'Lacuna::DB::Result::Empire', 'empire_id'); -__PACKAGE__->has_many('buildings','Lacuna::DB::Result::Building','body_id'); +__PACKAGE__->has_many('_buildings','Lacuna::DB::Result::Building','body_id'); has building_cache => ( is => 'rw', @@ -229,10 +229,35 @@ has building_cache => ( sub _build_building_cache { my ($self) = @_; - my @buildings = $self->buildings; + my @buildings = $self->_buildings; return \@buildings; } +sub building_max_level { + my ($self) = @_; + + return reduce {$a->level > $b->level ? $a->level : $b->level} 0, @{$self->building_cache} +} + +sub building_avg_level { + my ($self) = @_; + + if (scalar @{$self->building_cache}) { + return (reduce {$a->level + $b->level} 0, @{$self->building_cache} ) / @{$self->building_cache}; + } + return 0; +} + +sub buildings_of_class { + my ($self,$class) = @_; + + $class =~ s/Lacuna::DB::Result::Building:://; + $class = "Lacuna::DB::Result::Building::$class"; + + my @buildings = grep {$_-> class eq $class} @{$self->building_cache}; + return @buildings; +} + sub abandon { my $self = shift; } diff --git a/lib/Lacuna/Web/Admin.pm b/lib/Lacuna/Web/Admin.pm index 947f19f7..50b08d60 100644 --- a/lib/Lacuna/Web/Admin.pm +++ b/lib/Lacuna/Web/Admin.pm @@ -199,8 +199,7 @@ sub www_complete_builds { my ($self, $request, $body_id) = @_; $body_id ||= $request->param('body_id'); my $body = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($body_id); - my $buildings = $body->buildings; - while (my $building = $buildings->next) { + foreach my $building (@{$body->building_cache}) { next unless ( $building->is_upgrading ); $building->is_upgrading(0); $building->upgrade_ends($building->upgrade_started); @@ -217,8 +216,7 @@ sub www_send_stellar_flare { my ($self, $request, $body_id) = @_; $body_id ||= $request->param('body_id'); my $body = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($body_id); - my $buildings = $body->buildings; - while (my $building = $buildings->next) { + foreach my $building (@{$body->building_cache}) { next unless ('Infrastructure' ~~ [$building->build_tags]); next if ( $building->class eq 'Lacuna::DB::Result::Building::PlanetaryCommand' ); $building->efficiency(0); @@ -240,8 +238,7 @@ sub www_send_meteor_shower { my ($self, $request, $body_id) = @_; $body_id ||= $request->param('body_id'); my $body = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($body_id); - my $buildings = $body->buildings; - while (my $building = $buildings->next) { + foreach my $building (@{$body->building_cache}) { next unless ('Infrastructure' ~~ [$building->build_tags]); next if ( $building->class eq 'Lacuna::DB::Result::Building::PlanetaryCommand' ); $building->class('Lacuna::DB::Result::Building::Permanent::Crater'); diff --git a/t/bugs/0022_SurfaceRefresh.t b/t/bugs/0022_SurfaceRefresh.t index 2f7c8c6e..a4ba8f23 100644 --- a/t/bugs/0022_SurfaceRefresh.t +++ b/t/bugs/0022_SurfaceRefresh.t @@ -16,7 +16,7 @@ my $tester_session_id = $tester->session->id; my $empire = $tester->empire; my $home = $empire->home_planet; -my ($pcc) = $home->buildings->search({class => 'Lacuna::DB::Result::Building::PlanetaryCommand'}); +my ($pcc) = $home->buildings_of_class('PlanetaryCommand'); $tester->post('planetarycommand', 'view_plans', [$tester_session_id, $pcc->id]); diff --git a/t/bugs/0028_PlansInRandomOrder.t b/t/bugs/0028_PlansInRandomOrder.t index 3d76bb12..cb0997e0 100644 --- a/t/bugs/0028_PlansInRandomOrder.t +++ b/t/bugs/0028_PlansInRandomOrder.t @@ -27,7 +27,7 @@ $home->add_plan('Lacuna::DB::Result::Building::Permanent::Ravine', 1,1); $home->add_plan('Lacuna::DB::Result::Building::Permanent::Lake', 1); $home->add_plan('Lacuna::DB::Result::Building::Permanent::AlgaePond', 1); -my ($pcc) = $home->buildings->search({class => 'Lacuna::DB::Result::Building::PlanetaryCommand'}); +my ($pcc) = $home->buildings_of_class('PlanetaryCommand'); $tester->post('planetarycommand', 'view_plans', [$session_id, $shipyard->id, 'dory']); -- 2.51.2 From 1b1eac53a86a131ea4f5cfbcea9e3855377cfe3c Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 23 May 2012 14:49:37 -0400 Subject: [PATCH 034/105] Fixed plot count calculation --- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index dae44e47..7476ab97 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -443,8 +443,8 @@ has building_count => ( sub _build_building_count { my ($self) = @_; -# Bleeders count toward building count, but supply pods don't since they can't be shot down. - my $count = grep { $_->class !~ /Permanent$|SupplyPod$/} @{$self->building_cache}; + # Bleeders count toward building count, but supply pods don't since they can't be shot down. + my $count = grep {$_->class !~ /Permanent/ and $_->class !~ /SupplyPod/} @{$self->building_cache}; return $count; } -- 2.51.2 From 18ed43567ed68c874df2faadf5adc73bf4af0fcd Mon Sep 17 00:00:00 2001 From: ian docherty Date: Wed, 23 May 2012 16:41:53 -0400 Subject: [PATCH 035/105] Fix for Halls of Vrbnsk exception when sacrificing. --- lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm b/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm index 53142308..1b74a41e 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm @@ -46,7 +46,7 @@ sub get_upgradable_buildings { # The max_level is represented by the number of halls already # built, plus the minimum of the number of free building spaces or # the number of hall plans - my $halls = $self->get_halls->count; + my $halls = $self->get_halls; my $plans = Lacuna->db->resultset('Plans')->search({ body_id => $body->id, class => 'Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk', -- 2.51.2 From 5d3db59c23ef166ff5c49eb25848e9bfa7e2e516 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Thu, 24 May 2012 11:42:42 -0400 Subject: [PATCH 036/105] Fix to allow colony to be abandoned --- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 26 +++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 7476ab97..58a05b9a 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -35,12 +35,18 @@ sub _build_plan_cache { sub delete_building { my ($self, $building) = @_; - my $index = first_index {$_->id == $building->id} @{$self->building_cache}; - if (defined $index) { - my @buildings = splice(@{$self->building_cache}, $index, 1); - $self->building_cache(\@buildings); + print STDERR "<<< building=[$building] building_id=[".$building->id."]>>>>\n"; + my $i = 0; + BUILDING: + foreach my $b (@{$self->building_cache}) { + if ($b->id == $building->id) { + my @buildings = splice(@{$self->building_cache}, $i, 1); + $self->building_cache(\@buildings); + $b->delete; + last BUILDING; + } + $i++; } - $building->delete; } sub delete_buildings { @@ -144,10 +150,8 @@ sub add_plan { sub sanitize { my ($self) = @_; - my @buildings = grep {$_->class !~ /Permanent$/} @{$self->building_cache}; - foreach my $building (@buildings) { - $self->delete_building($building); - } + my @buildings = grep {$_->class !~ /Permanent/} @{$self->building_cache}; + $self->delete_buildings(\@buildings); my @attributes = qw( happiness_hour happiness waste_hour waste_stored waste_capacity energy_hour energy_stored energy_capacity water_hour water_stored water_capacity ore_capacity rutile_stored chromite_stored chalcopyrite_stored galena_stored gold_stored uraninite_stored bauxite_stored @@ -852,9 +856,7 @@ sub convert_to_station { $empire->add_medal('space_station_deployed'); # clean it - foreach my $building (@{$self->building_cache}) { - $self->delete_building($building); - } + $self->delete_buildings($self->building_cache); # add command building my $command = Lacuna->db->resultset('Lacuna::DB::Result::Building')->new({ -- 2.51.2 From 6c9976fe86a10604af913d079ca71a5b0a12a5fe Mon Sep 17 00:00:00 2001 From: ian docherty Date: Thu, 24 May 2012 12:25:47 -0400 Subject: [PATCH 037/105] Move reading emails out of empire status --- lib/Lacuna/DB/Result/Empire.pm | 8 ++++++-- lib/Lacuna/RPC/Body.pm | 2 ++ var/upgrades/3.0852.sql | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 63ce633c..85591ad1 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -80,6 +80,8 @@ __PACKAGE__->add_columns( skip_attack_messages => { data_type => 'tinyint', default_value => 0 }, skip_excavator_artifact => { data_type => 'tinyint', default_value => 0 }, skip_excavator_destroyed => { data_type => 'tinyint', default_value => 0 }, + most_recent_message => { data_type => 'varchar', size => 30, is_nullable => 0, default_value => '' }, + has_new_messages => { data_type => 'tinyint', default_value => 0 }, ); sub sqlt_deploy_hook { @@ -316,6 +318,8 @@ sub get_status { while (my $planet = $planet_rs->next) { $planets{$planet->id} = $planet->name; } + my $has_new_messages = 0; + my $status = { rpc_count => $self->rpc_count, is_isolationist => $self->is_isolationist, @@ -323,8 +327,8 @@ sub get_status { name => $self->name, id => $self->id, essentia => $self->essentia, - has_new_messages => $self->get_new_message_count, - most_recent_message => $self->get_newest_message, + has_new_messages => $self->has_new_messages, + most_recent_message => $self->most_recent_message, home_planet_id => $self->home_planet_id, planets => \%planets, self_destruct_active=> $self->self_destruct_active, diff --git a/lib/Lacuna/RPC/Body.pm b/lib/Lacuna/RPC/Body.pm index 2aac8616..3a0f46e5 100644 --- a/lib/Lacuna/RPC/Body.pm +++ b/lib/Lacuna/RPC/Body.pm @@ -378,6 +378,8 @@ sub get_buildable { if (defined $dev) { $max_items_in_build_queue += $dev->level; } + + my $items_in_build_queue = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search({body_id => $body_id, is_upgrading=>1})->count; if ($body->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { diff --git a/var/upgrades/3.0852.sql b/var/upgrades/3.0852.sql index 17aae13e..7cd58bef 100644 --- a/var/upgrades/3.0852.sql +++ b/var/upgrades/3.0852.sql @@ -1 +1,4 @@ alter table body add column max_berth tinyint default 1; +alter table empire add column most_recent_message varchar(30) not null default ''; +alter table empire add column has_new_messages tinyint(4) not null default 0; + -- 2.51.2 From fefa6cb01161cc5bc162d304c3695d2875b3e2b8 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 24 May 2012 13:48:34 -0600 Subject: [PATCH 038/105] Waste Exchangers checked for stockpile demolish/downgrade. --- lib/Lacuna/DB/Result/Building/Stockpile.pm | 39 ++++++++++++++++------ 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Stockpile.pm b/lib/Lacuna/DB/Result/Building/Stockpile.pm index 94351d71..236cbec4 100644 --- a/lib/Lacuna/DB/Result/Building/Stockpile.pm +++ b/lib/Lacuna/DB/Result/Building/Stockpile.pm @@ -51,21 +51,40 @@ use constant ore_storage => 300; use constant water_storage => 300; before 'can_downgrade' => sub { - my $self = shift; - foreach my $building (@{$self->building_cache}) { - if ($building->level > 15 + (($self->level - 1)/3) && 'Resources' ~~ [$building->build_tags] && !('Storage' ~~ [$building->build_tags])) { - confess [1013, 'You have to downgrade your level '.$building->level.' '.$building->name.' to level 15 before you can downgrade the Stockpile.']; - } + my $self = shift; + my $max_level = 15; + if ($self->body->empire->university_level > 25) { + $max_level += ($self->body->empire->university_level - 25); + } + foreach my $building (@{$self->building_cache}) { + if ($building->level > $max_level + (($self->level - 1)/3) && + 'Resources' ~~ [$building->build_tags] && + ( !('Storage' ~~ [$self->build_tags]) || + $self->isa('Lacuna::DB::Result::Building::Waste::Exchanger'))) { + confess [1013, 'You have to downgrade your level '. + $building->level.' '.$building->name.' to level '. + $max_level.' before you can downgrade the Stockpile.']; } + } }; before 'can_demolish' => sub { - my $self = shift; - foreach my $building (@{$self->building_cache}) { - if ($building->level > 15 && 'Resources' ~~ [$building->build_tags] && !('Storage' ~~ [$building->build_tags])) { - confess [1013, 'You have to downgrade your level '.$building->level.' '.$building->name.' to level 15 before you can demolish the Stockpile.']; - } + my $self = shift; + my $max_level = 15; + if ($self->body->empire->university_level > 25) { + $max_level += ($self->body->empire->university_level - 25); + } + foreach my $building (@{$self->building_cache}) { + if ($building->level > $max_level + (($self->level - 1)/3) && + 'Resources' ~~ [$building->build_tags] && + ( !('Storage' ~~ [$self->build_tags]) || + $self->isa('Lacuna::DB::Result::Building::Waste::Exchanger'))) { + confess [1013, 'You have to downgrade your level '. + $building->level.' '.$building->name. + ' to level '.$max_level. + ' before you can demolish the Stockpile.']; } + } }; sub extra_resource_levels { -- 2.51.2 From 6170043f921aaaca4a9729f19df0730911c6b7e5 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Thu, 24 May 2012 16:59:11 -0400 Subject: [PATCH 039/105] Move message query out of empire status --- lib/Lacuna/DB/Result/Empire.pm | 58 ++++++++++++++----------- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 5 +-- lib/Lacuna/DB/Result/Message.pm | 9 ++++ lib/Lacuna/RPC/Body.pm | 4 +- var/upgrades/3.0852.sql | 5 ++- 5 files changed, 47 insertions(+), 34 deletions(-) diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 85591ad1..da7df568 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -80,8 +80,9 @@ __PACKAGE__->add_columns( skip_attack_messages => { data_type => 'tinyint', default_value => 0 }, skip_excavator_artifact => { data_type => 'tinyint', default_value => 0 }, skip_excavator_destroyed => { data_type => 'tinyint', default_value => 0 }, - most_recent_message => { data_type => 'varchar', size => 30, is_nullable => 0, default_value => '' }, has_new_messages => { data_type => 'tinyint', default_value => 0 }, + latest_message_id => { data_type => 'int', is_nullable => 1 }, + see_incoming_ships => { data_type => 'tinyint', default_value => 0 }, ); sub sqlt_deploy_hook { @@ -104,6 +105,7 @@ __PACKAGE__->has_many('sent_messages', 'Lacuna::DB::Result::Message', 'from_id') __PACKAGE__->has_many('received_messages', 'Lacuna::DB::Result::Message', 'to_id'); __PACKAGE__->has_many('medals', 'Lacuna::DB::Result::Medals', 'empire_id'); __PACKAGE__->has_many('probes', 'Lacuna::DB::Result::Probes', 'empire_id'); +__PACKAGE__->belongs_to('latest_message', 'Lacuna::DB::Result::Message', 'latest_message_id', { on_delete => 'set null' }); sub self_destruct_date_formatted { my $self = shift; @@ -260,34 +262,39 @@ sub add_essentia { return $self; } +sub recalc_messages { + my ($self) = @_; + + $self->update({ + has_new_messages => $self->get_new_message_count, + latest_message_id => $self->get_latest_message_id, + }); +} + sub get_new_message_count { - my $self = shift; - return Lacuna->db->resultset('Lacuna::DB::Result::Message')->search({ - to_id => $self->id, + my ($self) = @_; + + my $count = $self->received_messages->search({ has_archived => 0, has_read => 0, - })->count; + }); + + print "[[[[ message count = [$count] ]]]]\n"; + return $count; } -sub get_newest_message { - my $self = shift; - my $message = Lacuna->db->resultset('Lacuna::DB::Result::Message')->search( - { - to_id => $self->id, - has_archived => 0, - has_read => 0, - }, - { - order_by => { -desc => 'date_sent' }, - rows => 1, - } - )->single; - if (defined $message) { - return { id => $message->id, date_received => $message->date_sent_formatted, subject => $message->subject }; - } - else { - return undef; - } +sub get_latest_message_id { + my ($self) = @_; + + my $message = $self->received_messages->search({ + has_archived => 0, + has_read => 0, + },{ + order_by => { -desc => 'date_sent' }, + rows => 1, + })->single; + my $message_id = defined $message ? $message->id : 0; + return $message_id; } has rpc_count => ( @@ -318,7 +325,6 @@ sub get_status { while (my $planet = $planet_rs->next) { $planets{$planet->id} = $planet->name; } - my $has_new_messages = 0; my $status = { rpc_count => $self->rpc_count, @@ -328,7 +334,7 @@ sub get_status { id => $self->id, essentia => $self->essentia, has_new_messages => $self->has_new_messages, - most_recent_message => $self->most_recent_message, + latest_message_id => $self->latest_message_id, home_planet_id => $self->home_planet_id, planets => \%planets, self_destruct_active=> $self->self_destruct_active, diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 58a05b9a..05423b65 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -35,7 +35,6 @@ sub _build_plan_cache { sub delete_building { my ($self, $building) = @_; - print STDERR "<<< building=[$building] building_id=[".$building->id."]>>>>\n"; my $i = 0; BUILDING: foreach my $b (@{$self->building_cache}) { @@ -237,7 +236,8 @@ around get_status => sub { if ($self->needs_recalc) { $self->tick; # in case what we just did is going to change our stats } - if (not $empire->is_isolationist) { # don't need to warn about incoming ships if can't be attacked + # ISO empires, and empires who have disabled the option, don't need to see incoming ships + if ($empire->see_incoming_ships and not $empire->is_isolationist) { my $now = time; my $foreign_bodies; @@ -754,7 +754,6 @@ sub has_max_instances_of_building { sub builds { my ($self, $reverse) = @_; - my @buildings = sort {$a->upgrade_ends cmp $b->upgrade_ends} grep {$_->is_upgrading == 1} @{$self->building_cache}; @buildings = reverse @buildings if $reverse; return \@buildings; diff --git a/lib/Lacuna/DB/Result/Message.pm b/lib/Lacuna/DB/Result/Message.pm index 8f22034e..79a5ea13 100644 --- a/lib/Lacuna/DB/Result/Message.pm +++ b/lib/Lacuna/DB/Result/Message.pm @@ -43,6 +43,15 @@ sub date_sent_formatted { return format_date($self->date_sent); } +for my $func (qw(insert update delete)) { + after $func => sub { + my $self = shift; + + $self->sender->recalc_messages; + $self->receiver->recalc_messages; + }; +} + no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/RPC/Body.pm b/lib/Lacuna/RPC/Body.pm index 3a0f46e5..8fc3c1db 100644 --- a/lib/Lacuna/RPC/Body.pm +++ b/lib/Lacuna/RPC/Body.pm @@ -378,9 +378,7 @@ sub get_buildable { if (defined $dev) { $max_items_in_build_queue += $dev->level; } - - - my $items_in_build_queue = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search({body_id => $body_id, is_upgrading=>1})->count; + my $items_in_build_queue = scalar @{$body->builds}; if ($body->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { @buildable = (); diff --git a/var/upgrades/3.0852.sql b/var/upgrades/3.0852.sql index 7cd58bef..81d0f7af 100644 --- a/var/upgrades/3.0852.sql +++ b/var/upgrades/3.0852.sql @@ -1,4 +1,5 @@ alter table body add column max_berth tinyint default 1; -alter table empire add column most_recent_message varchar(30) not null default ''; -alter table empire add column has_new_messages tinyint(4) not null default 0; +alter table empire add column has_new_messages integer(11) not null default 0; +alter table empire add column see_incoming_ships tinyint(4) not null default 1; +alter table empire add column latest_message_id integer(11); -- 2.51.2 From 987b51729fb1f33429728ae88c9ab7be7e178567 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 24 May 2012 17:23:42 -0600 Subject: [PATCH 040/105] Fixed a couple bad merges. --- lib/Lacuna/DB/Result/Building.pm | 1 - lib/Lacuna/RPC/Building/BlackHoleGenerator.pm | 9 --------- 2 files changed, 10 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index 14c581ed..ffc00769 100755 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -752,7 +752,6 @@ sub cost_to_upgrade { my ($self) = @_; my $upgrade_cost = $self->upgrade_cost; my $upgrade_cost_reduction = $self->construction_cost_reduction_bonus; - my $plan; my $plan = $self->body->get_plan($self->class, $self->level + 1); if (defined $plan) { $upgrade_cost_reduction = 0; diff --git a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm index 57c6feb2..8ae8a299 100644 --- a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm +++ b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm @@ -503,7 +503,6 @@ sub bhg_swap { orbit => $old_data->{orbit}, }); $waste_chain = Lacuna->db->resultset('Lacuna::DB::Result::WasteChain') -<<<<<<< HEAD ->search({ planet_id => $target->id }); if ($waste_chain->count > 0) { while (my $chain = $waste_chain->next) { @@ -513,14 +512,6 @@ sub bhg_swap { } } $target->recalc_chains; -======= - ->search({ planet_id => $target->body_id }); - if ($waste_chain->count > 0) { - while (my $chain = $waste_chain->next) { - $chain->star_id($old_data->{star}); - } - } ->>>>>>> 8a8af47... Fix for waste chains after bhg swap } return { id => $body->id, -- 2.51.2 From 346278f33e12c3bb1c8fb4a44dafea9d62eebebb Mon Sep 17 00:00:00 2001 From: ian docherty Date: Fri, 25 May 2012 08:26:53 -0400 Subject: [PATCH 041/105] Removed multiple calls to get body from database --- lib/Lacuna/RPC.pm | 25 +++++++++++++++++++------ t/220_Parliament.t | 4 ++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/Lacuna/RPC.pm b/lib/Lacuna/RPC.pm index 9c259c7c..f53a1c9f 100644 --- a/lib/Lacuna/RPC.pm +++ b/lib/Lacuna/RPC.pm @@ -57,7 +57,17 @@ sub get_empire_by_session { sub get_body { # makes for uniform error handling, and prevents staleness my ($self, $empire, $body_id) = @_; - my $body = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($body_id); + my $body; + if (ref $body_id && $body_id->isa('Lacuna::DB::Result::Map::Body')) { + $body = $body_id; + } + else { + ($body) = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->search({ + body_id => $body_id, + },{ + prefetch => 'empire', + }); + } unless (defined $body) { confess [1002, 'Body does not exist.', $body_id]; } @@ -70,7 +80,6 @@ sub get_body { # makes for uniform error handling, and prevents staleness } confess [1010, "Can't manipulate a planet you don't inhabit."]; } - $body->empire($empire); if ($body->id eq $empire->home_planet_id) { $empire->home_planet($body); } @@ -84,7 +93,11 @@ sub get_building { # makes for uniform error handling, and prevents staleness return $building_id; } else { - my $building = Lacuna->db->resultset('Lacuna::DB::Result::Building')->find($building_id); + my ($building) = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search({ + id => $building_id, + },{ prefetch => 'body' } + ); + unless (defined $building) { confess [1002, 'Building does not exist.', $building_id]; } @@ -92,18 +105,18 @@ sub get_building { # makes for uniform error handling, and prevents staleness confess [1002, 'That building is not a '.$self->model_class->name]; } $building->is_offline unless ($options{skip_offline}); - my $body = $self->get_body($empire, $building->body_id); + my $body = $self->get_body($empire, $building->body); if ($body->empire_id ne $empire->id) { if ($body->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { if ($body->empire->alliance_id eq $empire->alliance_id) { - $building->get_from_storage; # in case it changed due to the tick + $building->discard_changes; # in case it changed due to the tick $building->body($body); return $building; } } confess [1010, "Can't manipulate a building that you don't own.", $building_id]; } - $building->get_from_storage; # in case it changed due to the tick + $building->discard_changes; # in case it changed due to the tick $building->body($body); return $building; } diff --git a/t/220_Parliament.t b/t/220_Parliament.t index 3fc8c909..b961562a 100644 --- a/t/220_Parliament.t +++ b/t/220_Parliament.t @@ -33,7 +33,7 @@ $result = $tester->post('embassy', 'create_alliance', [$session_id, $emb->id, 't ok(exists $result->{result}, 'can create alliance'); $result = $tester->post('embassy', 'get_alliance_status', [$session_id, $emb->id]); ok(scalar@{$result->{result}{alliance}{members}}, 'alliance has members'); -$empire = $empire->get_from_storage; +$empire->discard_changes; ok $empire->alliance_id, 'empire has alliance'; $friend->empire->alliance_id($empire->alliance_id); @@ -41,7 +41,7 @@ $friend->empire->update; my $station = Lacuna->db->resultset('Map::Body')->search({class => {like => 'Lacuna::DB::Result::Map::Body::Planet::P%'}, empire_id => undef},{rows=>1})->single; $station->convert_to_station($empire); -$station = $station->get_from_storage; # just in case +$station->discard_changes; # just in case ok $station->alliance_id, 'alliance assigned to station'; -- 2.51.2 From 205b7e3f1d6dfce8af771e5775c9c9a905cacecf Mon Sep 17 00:00:00 2001 From: lemming552 Date: Fri, 25 May 2012 15:02:38 -0600 Subject: [PATCH 042/105] Don't recalc chains unless chains are present. --- lib/Lacuna/RPC/Building/BlackHoleGenerator.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm index 8ae8a299..02ec3365 100644 --- a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm +++ b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm @@ -490,8 +490,8 @@ sub bhg_swap { star_id => $new_data->{star_id} }); } + $body->recalc_chains; } - $body->recalc_chains; unless ($new_data->{type} eq "empty") { $target->update({ @@ -505,13 +505,13 @@ sub bhg_swap { $waste_chain = Lacuna->db->resultset('Lacuna::DB::Result::WasteChain') ->search({ planet_id => $target->id }); if ($waste_chain->count > 0) { - while (my $chain = $waste_chain->next) { - $chain->update({ - star_id => $old_data->{star_id} - }); - } + while (my $chain = $waste_chain->next) { + $chain->update({ + star_id => $old_data->{star_id} + }); + } + $target->recalc_chains; } - $target->recalc_chains; } return { id => $body->id, -- 2.51.2 From 81afbbe17620bc7af2c3ccc015f61349cec02d72 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Mon, 28 May 2012 02:45:53 -0400 Subject: [PATCH 043/105] Fixed bug with obtaining body id --- lib/Lacuna/RPC.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/RPC.pm b/lib/Lacuna/RPC.pm index f53a1c9f..d4ebb24f 100644 --- a/lib/Lacuna/RPC.pm +++ b/lib/Lacuna/RPC.pm @@ -63,7 +63,7 @@ sub get_body { # makes for uniform error handling, and prevents staleness } else { ($body) = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->search({ - body_id => $body_id, + 'me.id' => $body_id, },{ prefetch => 'empire', }); @@ -94,7 +94,7 @@ sub get_building { # makes for uniform error handling, and prevents staleness } else { my ($building) = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search({ - id => $building_id, + 'me.id' => $building_id, },{ prefetch => 'body' } ); -- 2.51.2 From 9e5fe925277fd776425738e83c8e2d70b5abf4b9 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Wed, 30 May 2012 16:04:36 -0400 Subject: [PATCH 044/105] Fixed issues with building/demolishing SS modules --- lib/Lacuna/DB/Result/Map/Body.pm | 11 +----- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 12 +++++- .../DB/Result/Map/Body/Planet/Station.pm | 37 +++++++++++-------- .../DB/Result/Propositions/DemolishModule.pm | 2 +- .../DB/Result/Propositions/DowngradeModule.pm | 2 +- .../DB/Result/Propositions/InstallModule.pm | 6 ++- .../DB/Result/Propositions/RepairModule.pm | 2 +- .../DB/Result/Propositions/UpgradeModule.pm | 5 +-- lib/Lacuna/Web/Admin.pm | 4 +- 9 files changed, 44 insertions(+), 37 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index 86e9e6fb..2b58fe4b 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -219,6 +219,7 @@ __PACKAGE__->belongs_to('star', 'Lacuna::DB::Result::Map::Star', 'star_id'); __PACKAGE__->belongs_to('alliance', 'Lacuna::DB::Result::Alliance', 'alliance_id', { on_delete => 'set null' }); __PACKAGE__->belongs_to('empire', 'Lacuna::DB::Result::Empire', 'empire_id'); __PACKAGE__->has_many('_buildings','Lacuna::DB::Result::Building','body_id'); +__PACKAGE__->has_many('foreign_ships','Lacuna::DB::Result::Ships','foreign_body_id'); has building_cache => ( is => 'rw', @@ -249,16 +250,6 @@ sub building_avg_level { return 0; } -sub buildings_of_class { - my ($self,$class) = @_; - - $class =~ s/Lacuna::DB::Result::Building:://; - $class = "Lacuna::DB::Result::Building::$class"; - - my @buildings = grep {$_-> class eq $class} @{$self->building_cache}; - return @buildings; -} - sub abandon { my $self = shift; } diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 05423b65..84d0dff7 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -466,6 +466,13 @@ sub get_building_of_class { return $building; } +sub find_building { + my ($self, $id) = @_; + + my ($building) = grep {$_->id == $id} @{$self->building_cache}; + return $building; +} + has command => ( is => 'rw', lazy => 1, @@ -855,7 +862,8 @@ sub convert_to_station { $empire->add_medal('space_station_deployed'); # clean it - $self->delete_buildings($self->building_cache); + my @all_buildings = @{$self->building_cache}; + $self->delete_buildings(\@all_buildings); # add command building my $command = Lacuna->db->resultset('Lacuna::DB::Result::Building')->new({ @@ -2256,7 +2264,7 @@ sub complain_about_lack_of_resources { } } } - my ($building) = grep {$_->efficiency > 0} self->get_buildings_of_class($class); + my ($building) = grep {$_->efficiency > 0} $self->get_buildings_of_class($class); if (defined $building) { $building_name = $building->name; $building->spend_efficiency(25)->update; diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm index cbe0a148..80050535 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm @@ -5,6 +5,7 @@ use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Map::Body::Planet'; use Lacuna::Util qw(randint); +use Data::Dumper; use constant image => 'station'; __PACKAGE__->has_many('propositions','Lacuna::DB::Result::Propositions','station_id'); @@ -14,16 +15,20 @@ __PACKAGE__->has_many('stars','Lacuna::DB::Result::Map::Star','station_id'); has parliament => ( is => 'rw', lazy => 1, - default => sub { - my $self = shift; - my $parliament = $self->get_building_of_class('Lacuna::DB::Result::Building::Module::Parliament'); - if (defined $parliament) { - $parliament->body($self); - } - return $parliament; - }, + builder => '_build_parliament', ); +sub _build_parliament { + my ($self) = @_; + + my ($parliament) = grep {$_->class =~ /Parliament$/} @{$self->building_cache}; + + if (defined $parliament) { + $parliament->body($self); + } + return $parliament; +} + around get_status => sub { my ($orig, $self, $empire) = @_; my $out = $orig->($self, $empire); @@ -62,15 +67,17 @@ after sanitize => sub { has command => ( is => 'rw', lazy => 1, - default => sub { - my $self = shift; - my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Module::StationCommand'); - return undef unless defined $building; - $building->body($self); - return $building; - }, + builder => '_build_command', ); +sub _build_command { + my ($self) = @_; + my ($building) = grep {$_->class =~ /StationCommand$/} @{$self->building_cache}; + return undef unless defined $building; + $building->body($self); + return $building; +} + sub has_resources_to_operate { return 1; } diff --git a/lib/Lacuna/DB/Result/Propositions/DemolishModule.pm b/lib/Lacuna/DB/Result/Propositions/DemolishModule.pm index 528b2e10..b17cf66b 100644 --- a/lib/Lacuna/DB/Result/Propositions/DemolishModule.pm +++ b/lib/Lacuna/DB/Result/Propositions/DemolishModule.pm @@ -8,7 +8,7 @@ extends 'Lacuna::DB::Result::Propositions'; before pass => sub { my ($self) = @_; my $station = $self->station; - my ($building) = grep {$self->scratch->{building_id}} @{$station->building_cache}; + my $building = $station->find_building($self->scratch->{building_id}); if (defined $building) { $building->demolish; } diff --git a/lib/Lacuna/DB/Result/Propositions/DowngradeModule.pm b/lib/Lacuna/DB/Result/Propositions/DowngradeModule.pm index dbb26509..136ab7c2 100644 --- a/lib/Lacuna/DB/Result/Propositions/DowngradeModule.pm +++ b/lib/Lacuna/DB/Result/Propositions/DowngradeModule.pm @@ -8,7 +8,7 @@ extends 'Lacuna::DB::Result::Propositions'; before pass => sub { my ($self) = @_; my $station = $self->station; - my ($building) = grep {$self->scratch->{building_id}} @{$station->building_cache}; + my $building = $station->find_building($self->scratch->{building_id}); if (defined $building) { $building->downgrade; } diff --git a/lib/Lacuna/DB/Result/Propositions/InstallModule.pm b/lib/Lacuna/DB/Result/Propositions/InstallModule.pm index 577b3a99..be54d9dd 100644 --- a/lib/Lacuna/DB/Result/Propositions/InstallModule.pm +++ b/lib/Lacuna/DB/Result/Propositions/InstallModule.pm @@ -2,13 +2,15 @@ package Lacuna::DB::Result::Propositions::InstallModule; use Moose; use utf8; +use Data::Dumper; + no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Propositions'; before pass => sub { my ($self) = @_; my $station = $self->station; - my ($building) = grep {$self->scratch->{building_id}} @{$station->building_cache}; + my $building = $self->station->find_building($self->scratch->{building_id}); if (defined $building) { if ($building->is_upgrading && $building->level < $self->scratch->{to_level}) { $building->finish_upgrade; @@ -22,7 +24,7 @@ before pass => sub { before fail => sub { my ($self) = @_; my $station = $self->station; - my ($building) = grep {$self->scratch->{building_id}} @{$station->building_cache}; + my $building = $station->find_building($self->scratch->{building_id}); if (defined $building) { $station->add_plan($building->class, 1, $building->level); $building->demolish; diff --git a/lib/Lacuna/DB/Result/Propositions/RepairModule.pm b/lib/Lacuna/DB/Result/Propositions/RepairModule.pm index a0cb64fb..5fb49d10 100644 --- a/lib/Lacuna/DB/Result/Propositions/RepairModule.pm +++ b/lib/Lacuna/DB/Result/Propositions/RepairModule.pm @@ -8,7 +8,7 @@ extends 'Lacuna::DB::Result::Propositions'; before pass => sub { my ($self) = @_; my $station = $self->station; - my ($building) = grep {$self->scratch->{building_id}} @{$station->building_cache}; + my $building = $station->find_building($self->scratch->{building_id}); if (defined $building) { my $costs = $building->get_repair_costs; if (eval{$building->can_repair($costs)}) { diff --git a/lib/Lacuna/DB/Result/Propositions/UpgradeModule.pm b/lib/Lacuna/DB/Result/Propositions/UpgradeModule.pm index be905521..4281baad 100644 --- a/lib/Lacuna/DB/Result/Propositions/UpgradeModule.pm +++ b/lib/Lacuna/DB/Result/Propositions/UpgradeModule.pm @@ -7,8 +7,7 @@ extends 'Lacuna::DB::Result::Propositions'; before pass => sub { my ($self) = @_; - my $station = $self->station; - my ($building) = grep {$_->id == $self->scratch->{building_id}} @{$station->building_cache}; + my $building = $self->station->find_building($self->scratch->{building_id}); if (defined $building) { if ($building->is_upgrading && $building->level < $self->scratch->{to_level}) { $building->finish_upgrade; @@ -22,7 +21,7 @@ before pass => sub { before fail => sub { my ($self) = @_; my $station = $self->station; - my ($building) = grep {$_->id == $self->scratch->{building_id}} @{$station->building_cache}; + my $building = $station->find_building($self->scratch->{building_id}); if (defined $building) { $station->add_plan($building->class, $building->level + 1); if ($building->level == 0 ) { diff --git a/lib/Lacuna/Web/Admin.pm b/lib/Lacuna/Web/Admin.pm index 50b08d60..6929b4cd 100644 --- a/lib/Lacuna/Web/Admin.pm +++ b/lib/Lacuna/Web/Admin.pm @@ -332,12 +332,12 @@ sub www_view_ships { $out .= sprintf('Back To Body', $body_id); $out .= ''; while (my $ship = $ships->next) { - my $target = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($ship->foreign_body_id); $out .= sprintf('', $ship->id, $ship->name, $ship->type_formatted, $ship->stealth, $ship->hold_size, $ship->speed, $ship->combat); if ($ship->task eq 'Travelling') { $out .= sprintf('', $ship->task, $ship->id, $body_id); } - elsif ($ship->task ~~ [qw(Defend Orbiting)]) { + elsif ($ship->task ~~ [qw(Defend Orbiting)]) { + my $target = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($ship->foreign_body_id); $out .= sprintf('', $ship->task, $target->name, $target->x, $target->y, $ship->id, $body_id); } elsif ($ship->task ne 'Docked') { -- 2.51.2 From 82bc71723f03f92e6994d04af9d6cf686699fc7f Mon Sep 17 00:00:00 2001 From: ian docherty Date: Thu, 31 May 2012 08:22:18 -0400 Subject: [PATCH 045/105] Can now downgrade and demolish stockpile --- lib/Lacuna/DB/Result/Building/Stockpile.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Stockpile.pm b/lib/Lacuna/DB/Result/Building/Stockpile.pm index 236cbec4..8294dc6c 100644 --- a/lib/Lacuna/DB/Result/Building/Stockpile.pm +++ b/lib/Lacuna/DB/Result/Building/Stockpile.pm @@ -56,7 +56,7 @@ before 'can_downgrade' => sub { if ($self->body->empire->university_level > 25) { $max_level += ($self->body->empire->university_level - 25); } - foreach my $building (@{$self->building_cache}) { + foreach my $building (@{$self->body->building_cache}) { if ($building->level > $max_level + (($self->level - 1)/3) && 'Resources' ~~ [$building->build_tags] && ( !('Storage' ~~ [$self->build_tags]) || @@ -74,7 +74,7 @@ before 'can_demolish' => sub { if ($self->body->empire->university_level > 25) { $max_level += ($self->body->empire->university_level - 25); } - foreach my $building (@{$self->building_cache}) { + foreach my $building (@{$self->body->building_cache}) { if ($building->level > $max_level + (($self->level - 1)/3) && 'Resources' ~~ [$building->build_tags] && ( !('Storage' ~~ [$self->build_tags]) || -- 2.51.2 From 6fd4803f30ff3bdbdc837ce2b5413feb74da8830 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 31 May 2012 06:34:29 -0600 Subject: [PATCH 046/105] Avoid divide by zero rare error. --- lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm index ba8cd4d0..c0a797f2 100644 --- a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm +++ b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm @@ -41,7 +41,7 @@ sub damage_in_combat { my ($self, $defender, $damage) = @_; $self->combat( $self->combat - $damage ); return unless $self->combat < 1; - $self->attacker_shot_down($defender); + $self->attacker_shot_down($defender); $self->delete; confess [-1] } @@ -370,7 +370,7 @@ sub saw_combat { # printf "ship:%6d:%5d saw:%6d:%2d:%3d total:%8d ", # $self->id, $self->combat, $saw->id, $saw->level, $saw->efficiency, $saw_combat; - if ($self->combat > $saw_combat) { + if ($self->combat >= $saw_combat) { $saw->spend_efficiency(100); $self->saw_disabled($saw); # print "100\n"; -- 2.51.2 From 7af1895188444fe56ff69f528d71fe77a3a5164b Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 31 May 2012 11:50:44 -0600 Subject: [PATCH 047/105] Slight reduction in excav destruction --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index c995f99e..310170fd 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -195,12 +195,12 @@ sub dig_it { message => "Found level $lvl + $plus $name Plan.", outcome => "Artifact", }; - $self->body->add_news(20,sprintf("%s uncovered a rare %s plan on %s.", + $self->body->add_news(10,sprintf("%s uncovered a rare %s plan on %s.", $empire_name, $name, $body->name)); } } when ("destroy") { - if (randint(0,99) < 5) { + if (randint(0,99) < 3) { my $message = random_element([ 'Auntie Em, where\'s Toto? Its a twister! Its a twister!', 'Aw, there\'s something behind me, isn\'t there?', -- 2.51.2 From e9f88f6d87bbf34d843633917eaed45a966dfb00 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Fri, 1 Jun 2012 15:39:22 -0400 Subject: [PATCH 048/105] Show the incoming status as none/disabled/normal --- docs/Body.pod | 3 ++- docs/Empire.pod | 5 +++++ lib/Lacuna/DB/Result/Empire.pm | 2 +- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 5 +++-- lib/Lacuna/RPC/Empire.pm | 7 +++++++ var/upgrades/3.0852.sql | 2 +- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/docs/Body.pod b/docs/Body.pod index 2f6f891d..099e37d9 100644 --- a/docs/Body.pod +++ b/docs/Body.pod @@ -64,7 +64,8 @@ B You should probably B call this method directly, as it is a wast "water_stored" : 9929, "water_hour" : 295, "water_capacity" : 51050, - "num_incoming_enemy" : 10, # total number of incoming enemy ships + "skip_incoming_ships" : 0, # if set, then the following incoming data is missing. + "num_incoming_enemy" : 10, # total number of incoming foreign ships "num_incoming_ally" : 1, # total number of incoming allied ships "num_incoming_own : 0, # total number of incoming own ships from other colonies "incoming_enemy_ships" : [ # will only be included when enemy ships are coming to your planet (only the first 20 will be shown) diff --git a/docs/Empire.pod b/docs/Empire.pod index 97684531..77039c74 100644 --- a/docs/Empire.pod +++ b/docs/Empire.pod @@ -277,6 +277,7 @@ Provides a list of the editable properties of the current empire's profile. See "skip_spy_recovery" : 0, "skip_probe_detected" : 0, "skip_attack_messages" : 0, + "skip_incoming_ships" : 0, "email" : "joe@example.com", "sitter_password" : "abcdefgh" # never give out your real password, use the sitter password }, @@ -398,6 +399,10 @@ Defaults to 0. Set to 1 if the user no longers wants to receive messages when a Defaults to 0. Set to 1 if the user no longers wants to receive messages about attacks. +=head4 skip_incoming_ships + +Controls the display of incoming ships (Own, Allied, Foreign) on your map display. Defaults to 0 (shows ships). Set to 1 if you want to hide incoming ships (can improve response of browser). + =head2 view_public_profile (session_id, empire_id) Provides a list of the data that's publicly known about this empire. diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index da7df568..679ab1d8 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -82,7 +82,7 @@ __PACKAGE__->add_columns( skip_excavator_destroyed => { data_type => 'tinyint', default_value => 0 }, has_new_messages => { data_type => 'tinyint', default_value => 0 }, latest_message_id => { data_type => 'int', is_nullable => 1 }, - see_incoming_ships => { data_type => 'tinyint', default_value => 0 }, + skip_incoming_ships => { data_type => 'tinyint', default_value => 0 }, ); sub sqlt_deploy_hook { diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 84d0dff7..6603db29 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -236,8 +236,9 @@ around get_status => sub { if ($self->needs_recalc) { $self->tick; # in case what we just did is going to change our stats } - # ISO empires, and empires who have disabled the option, don't need to see incoming ships - if ($empire->see_incoming_ships and not $empire->is_isolationist) { + # empires who have disabled the option, don't see incoming ships + $out->{skip_incoming_ships} = $empire->skip_incoming_ships; + if (not $empire->skip_incoming_ships) { my $now = time; my $foreign_bodies; diff --git a/lib/Lacuna/RPC/Empire.pm b/lib/Lacuna/RPC/Empire.pm index 1c8ce042..a227cd1a 100644 --- a/lib/Lacuna/RPC/Empire.pm +++ b/lib/Lacuna/RPC/Empire.pm @@ -408,6 +408,7 @@ sub view_profile { skip_spy_recovery => $empire->skip_spy_recovery, skip_probe_detected => $empire->skip_probe_detected, skip_attack_messages => $empire->skip_attack_messages, + skip_incoming_ships => $empire->skip_incoming_ships, ); return { profile => \%out, status => $self->format_status($empire) }; @@ -558,6 +559,12 @@ sub edit_profile { } $empire->skip_attack_messages($profile->{skip_attack_messages}); } + if (exists $profile->{skip_incoming_ships}) { + if ($profile->{skip_incoming_ships} != 0 && $profile->{skip_incoming_ships} != 1) { + confess [1009, 'Skip Incoming Ships must be a 1 or a 0.', 'skip_incoming_ships'] + } + $empire->skip_incoming_ships($profile->{skip_incoming_ships}); + } if (exists $profile->{skype}) { Lacuna::Verify->new(content=>\$profile->{skype}, throws=>[1005,'Skype must be no longer than 100 characters, and cannot contain special characters or profanity.', 'skype']) diff --git a/var/upgrades/3.0852.sql b/var/upgrades/3.0852.sql index 81d0f7af..790be601 100644 --- a/var/upgrades/3.0852.sql +++ b/var/upgrades/3.0852.sql @@ -1,5 +1,5 @@ alter table body add column max_berth tinyint default 1; alter table empire add column has_new_messages integer(11) not null default 0; -alter table empire add column see_incoming_ships tinyint(4) not null default 1; +alter table empire add column skip_incoming_ships tinyint(4) not null default 0; alter table empire add column latest_message_id integer(11); -- 2.51.2 From 664501f5a0c1c52cb4f70047ea6bb38130c28012 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sat, 2 Jun 2012 15:58:21 -0400 Subject: [PATCH 049/105] Updated Empire Status documentation --- docs/Empire.pod | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/Empire.pod b/docs/Empire.pod index 77039c74..ed92ff14 100644 --- a/docs/Empire.pod +++ b/docs/Empire.pod @@ -220,16 +220,14 @@ B You should probably B call this method directly, as it is a wast "status_message" : "A spy's work is never done.", "home_planet_id" : "id-goes-here", "has_new_messages" : 4, - "newest_message" : { - "id" : "id-goes-here", - "date_received" : "01 31 2010 13:09:05 +0600", - "subject" : "Boom!" - }, + "latest_message_id" : 1234, "essentia" : 0, "planets" : { "id-goes-here" : "Earth", "id-goes-here" : "Mars - } + }, + "self_destruct_active" : 0, + "self_destruct_date" : "" } } -- 2.51.2 From 9dedb08948c5b8703cd0fc4a49aaa2967d4dae6f Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sat, 2 Jun 2012 17:24:30 -0400 Subject: [PATCH 050/105] Removed diagnostic message --- lib/Lacuna/DB/Result/Empire.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 679ab1d8..de3255a5 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -279,7 +279,6 @@ sub get_new_message_count { has_read => 0, }); - print "[[[[ message count = [$count] ]]]]\n"; return $count; } -- 2.51.2 From 95853733b96a871f8a76fada16e3f32f85374881 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 13 May 2012 05:19:39 -0400 Subject: [PATCH 051/105] Started adding new fleet action API calls --- docs/SpacePort.pod | 289 +++++++++++++++++++++------ lib/Lacuna/DB/Result/Ships.pm | 20 +- lib/Lacuna/RPC/Building/SpacePort.pm | 167 +++++++++++++++- t/440_fleets.t | 32 +++ 4 files changed, 440 insertions(+), 68 deletions(-) create mode 100644 t/440_fleets.t diff --git a/docs/SpacePort.pod b/docs/SpacePort.pod index a6ff0737..28d8d061 100644 --- a/docs/SpacePort.pod +++ b/docs/SpacePort.pod @@ -61,8 +61,8 @@ Shows you all your ships whatever they are doing. "name" : "Mars" } }, - { - "id" : "id-goes-here", + { + "id" : "id-goes-here", "name" : "F13", "type_human" : "Fighter", "type" : "fighter", @@ -85,11 +85,11 @@ Shows you all your ships whatever they are doing. "id" : "id-goes-here", "type" : "body", "name" : "Mars", - "x" : 4, - "y" : -3 + "x" : 4, + "y" : -3 } - }, + }, ... ], "number_of_ships" : 13, @@ -206,7 +206,87 @@ The unique id of the space port. Defaults to page 1. Shows 25 at a time. +=head2 get_fleet_for ( session_id, from_body_id, target ) + +Provides a summary of ships that can be included in a fleet action + + { + "ships" : [ + { + "type" : "sweeper", + "type_human" : "Sweeper", + "speed" : 10166, + "stealth" : 10948, + "combat" : 33372, + "quantity" : 103, + "estimated_travel_time" : "3654", + }, + { + "type" : "sweeper", + "type_human" : "Sweeper", + "speed" : 10166, + "stealth" : 10948, + "combat" : 25000, + "quantity" : 26, + "estimated_travel_time" : "3745", + }, + { + "type" : "surveyor", + "type_human" : "Surveyor", + "speed" : 9030, + "stealth" : 9030, + "combat" : 3220, + "quantity" : 24, + "estimated_travel_time" : "4123", + } + ... + ], + "status" : { ... } + } + +Ships are grouped according to type,speed,stealth and combat, the number of ships in each group is given. + +=head3 session_id + +A session id. + +=head3 from_body_id + +The unique id of the planet that should send the ships. + +=head3 target + +A hash reference that can contain one of five items to identify a star or body. + + { "body_name" : "Earth" } + + { "body_id" : "id-goes-here" } + + { "star_name" : "Sol" } + + { "star_id" : "id-goes-here" } + + { "x" : 4, "y" : -3 } + +=head4 body_name + +A string with the body's name. Case insensitive, but will throw an exception for misspelling. + +=head4 body_id +The unique id of the body. + +=head4 star_name + +A string with the star's name. Case insensitive, but will throw an exception for misspelling. + +=head4 star_id + +The unique id of the star. + +=head4 x | y + +A set of x,y coordinates to locate the star or body. =head2 get_ships_for ( session_id, from_body_id, target ) @@ -258,27 +338,27 @@ Provides a list of incoming ships and ships that are available to send to a spec ... ], "unavailable" : [ - { + { "reason" : [1009, "You can't send a detonator to a star."], - "ship" : { - "id" : "id-goes-here", - "name" : "D13", - "type_human" : "Detonator", - "type" : "detonator", - "task" : "Docked", - "speed" : "700", + "ship" : { + "id" : "id-goes-here", + "name" : "D13", + "type_human" : "Detonator", + "type" : "detonator", + "task" : "Docked", + "speed" : "700", "fleet_speed" : "0", - "stealth" : "0", - "hold_size" : "0", - "date_started" : "01 31 2010 13:09:05 +0600", - "date_available" : "01 31 2010 13:09:05 +0600" + "stealth" : "0", + "hold_size" : "0", + "date_started" : "01 31 2010 13:09:05 +0600", + "date_available" : "01 31 2010 13:09:05 +0600" } }, ... ], - "orbiting" : [ - { - "id" : "id-goes-here", + "orbiting" : [ + { + "id" : "id-goes-here", "name" : "F13", "type_human" : "Fighter", "type" : "fighter", @@ -299,13 +379,13 @@ Provides a list of incoming ships and ships that are available to send to a spec "id" : "id-goes-here", "type" : "body", "name" : "Mars", - "x" : 4, - "y" : -3, + "x" : 4, + "y" : -3, } - }, - ... - ], + }, + ... + ], "mining_platforms" : [ { empire_id => "id-goes-here", @@ -362,7 +442,6 @@ The unique id of the star. A set of x,y coordinates to locate the star or body. - =head2 send_ship ( session_id, ship_id, target ) Sends a ship to a specified body or star. Use with C. @@ -440,44 +519,138 @@ The unique id of the star. A set of x,y coordinates to locate the star or body. +=head2 send_ship_types ( session_id, from_body_id, target, types, arrival ) + +Sends a quantity of ships, of a specific type (type, speed, combat, stealth) to a target. + +Look at B for a summary of what ships can be sent. + +Returns the same as B showing how many ships are remaining to be sent. + +Throws 1002,1009,1010,1019 + +=head4 session_id + +A session ID. + +=head4 from_body_id + +The Unique ID of the body that should send the ships + +=head4 target + +A hash reference that can contain one of five items to identify a star or body. + + { "body_name" : "Earth" } + + { "body_id" : "id-goes-here" } + + { "star_name" : "Sol" } + + { "star_id" : "id-goes-here" } + + { "x" : 4, "y" : -3 } + +=head4 body_name + +A string with the body's name. Case insensitive, but will throw an exception for misspelling. + +=head4 body_id + +The unique id of the body. + +=head4 star_name + +A string with the star's name. Case insensitive, but will throw an exception for misspelling. + +=head4 star_id + +The unique id of the star. + +=head4 x | y + +A set of x,y coordinates to locate the star or body. + +=head4 types + +An array reference that contains the specification of the ships to send and the quantity. + + [ + { + "type" : "sweeper", + "speed" : 10166, + "stealth" : 10948, + "combat" : 33372, + "quantity" : 100 + }, + { + "type" : "surveyor", + "speed" : 9030, + "stealth" : 9030, + "combat" : 3220, + "quantity" : 10 + } + ] + +=head4 arrival + +A hash reference of the required arrival time. + + { + "day" : "23", + "hour" : "12", + "minute" : "01", + "second" : "30" + } + +So long as the sending body has that quantity of ships with those specifications, then the +ships will be sent. + +Ships will be set to arrive at the B time and date, which can be up to 28 days in +the future. B is the day of the month, either the remainder of the current month, or +the start of next month. e.g. if the current date is 23rd of January, then a B of 23 +will refer to today whereas 3 would refer to 3rd of February. + +If an arrival time is set which is prior to the earliest arrival time of the slowest ship, +then an exception is raised. =head2 send_fleet ( session_id, ship_ids, target, [ set_speed ] ) Sends a fleet of ships to a specified body or star. Use with C. - { + { "status" : { ... }, - "fleet" : [ - "ship" : { - "id" : "id-goes-here", - "name" : "P13", - "type_human" : "Probe", - "type" : "probe", - "task" : "Travelling", - "speed" : "1200", - "fleet_speed" : "250", - "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", - "can_recall" : "0", - "can_scuttle" : "0", - "from" : { - "id" : "id-goes-here", - "type" : "body", - "name" : "Earth" - }, - "to" : { - "id" : "id-goes-here", - "type" : "star", - "name" : "Sol" - } - }, - ... - ] - } + "fleet" : [ + "ship" : { + "id" : "id-goes-here", + "name" : "P13", + "type_human" : "Probe", + "type" : "probe", + "task" : "Travelling", + "speed" : "1200", + "fleet_speed" : "250", + "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", + "can_recall" : "0", + "can_scuttle" : "0", + "from" : { + "id" : "id-goes-here", + "type" : "body", + "name" : "Earth" + }, + "to" : { + "id" : "id-goes-here", + "type" : "star", + "name" : "Sol" + } + }, + ... + ] +} Throws 1002, 1009, 1010, 1016. @@ -485,7 +658,7 @@ Throws 1002, 1009, 1010, 1016. A session id. -=head3 ship_id +=head3 ship_ids An array reference of ship ids to send. diff --git a/lib/Lacuna/DB/Result/Ships.pm b/lib/Lacuna/DB/Result/Ships.pm index b2637bef..f6941df7 100644 --- a/lib/Lacuna/DB/Result/Ships.pm +++ b/lib/Lacuna/DB/Result/Ships.pm @@ -174,7 +174,13 @@ sub can_recall { sub type_formatted { my $self = shift; - my $type = $self->type; + + return $self->type_human($self->type); +} + +sub type_human { + my ($self, $type) = @_; + $type =~ s/_/ /g; $type =~ s/\b(\w)/\u$1/g; return $type; @@ -279,7 +285,9 @@ sub send { $self->payload($options{payload} || {}); $self->roundtrip($options{roundtrip} || 0); $self->direction($options{direction} || 'out'); - $self->date_available(DateTime->now->add(seconds=>$self->calculate_travel_time($options{target}))); + my $arrival = $options{arrival} || DateTime->now->add(seconds=>$self->calculate_travel_time($options{target})); + $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}); @@ -339,11 +347,19 @@ sub land { sub calculate_travel_time { my ($self, $target) = @_; + my $distance = $self->body->calculate_distance_to_target($target); my $speed = $self->speed; if ( $self->fleet_speed > 0 && $self->fleet_speed < $self->speed ) { $speed = $self->fleet_speed; } + return $self->travel_time($self->body, $target, $speed); +} + +sub travel_time { + my ($class, $from, $target, $speed) = @_; + + my $distance = $from->calculate_distance_to_target($target); $speed ||= 1; my $hours = $distance / $speed; my $seconds = 60 * 60 * $hours; diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index f6ce7b94..15568088 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -41,11 +41,55 @@ sub find_target { } } unless (defined $target) { - confess [ 1002, 'Could not find the target.', $target]; + confess [ 1002, 'Could not find the target.', $target]; } return $target; } +sub get_fleet_for { + my ($self, $session_id, $body_id, $target_params) = @_; + + my $empire = $self->get_empire_by_session($session_id); + my $body = $self->get_body($empire, $body_id); + my $target = $self->find_target($target_params); + + my $berth = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { + class => 'Lacuna::DB::Result::Building::SpacePort', + body_id => $body_id, + efficiency => 100, + } )->get_column('level')->max; + my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search( + { + body_id => $body->id, + task => 'docked', + },{ + '+select' => [{count => 'id'}], + '+as' => [ qw(quantity) ], + group_by => [ qw(type speed stealth combat hold_size) ], + }, + ); + my $summary; + while (my $ship_group = $ships->next) { + my $travel_time = Lacuna::DB::Result::Ships->travel_time($body,$target,$ship_group->speed); + my $type_human = Lacuna::DB::Result::Ships->type_human($ship_group->type); + my $summation = { + type => $ship_group->type, + type_human => $type_human, + speed => int($ship_group->speed), + stealth => int($ship_group->stealth), + combat => int($ship_group->combat), + quantity => $ship_group->get_column('quantity'), + estimated_travel_time => $travel_time, + }; + push @$summary, $summation; + } + my %out = ( + status => $self->format_status($empire, $body), + ships => $summary, + ); + return \%out; +} + sub get_ships_for { my ($self, $session_id, $body_id, $target_params) = @_; my $empire = $self->get_empire_by_session($session_id); @@ -55,12 +99,12 @@ sub get_ships_for { my @incoming; my $incoming_rs = $ships->search({ - task => 'Travelling', - direction => 'out', - 'body.empire_id' => $empire->id, - }, - { join => 'body' } - ); + task => 'Travelling', + direction => 'out', + 'body.empire_id' => $empire->id, + },{ + join => 'body', + }); if ($target->isa('Lacuna::DB::Result::Map::Star')) { $incoming_rs = $incoming_rs->search({foreign_star_id => $target->id}); } @@ -171,6 +215,113 @@ sub send_ship { } } +sub find_arrival { + my ($self, $arrival_params) = @_; + + my $now = DateTime->now; + my $year = $now->year, + my $month = $now->month; + my $mon_end = DateTime->last_day_of_month(year => $year, month => $month); + my $day = $arrival_params->{day}; + my $hour = $arrival_params->{hour}; + my $minute = $arrival_params->{minute}; + my $second = $arrival_params->{second}; + + if (not defined $day or $day < 1 or $day > $mon_end->day) { + confess [1009, 'Invalid day.']; + } + if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { + confess [1002, 'Invalid hour.']; + } + if (not defined $minute or $minute != int($minute) or $minute < 0 or $minute > 59) { + confess [1002, 'Invalid minute.']; + } + if (not defined $second or $second != int($second) or $second < 0 or $second > 59) { + confess [1002, 'Invalid second.']; + } + if ($day < $now->day) { + # Then it must be a day next month + $mon_end->add( days => $day); + $year = $mon_end->year; + $month = $mon_end->month; + } + my $arrival = DateTime->new( + year => $year, + month => $month, + day => $day, + hour => $hour, + minute => $minute, + second => $second, + ); + return $arrival; +} + +sub send_ship_types { + my ($self, $session_id, $from_body_id, $target_params, $type_params, $arrival) = @_; + + my $empire = $self->get_empire_by_session($session_id); + my $body = $self->get_body($empire, $body_id); + my $target = $self->find_target($target_params); + my $arrival = $self->find_arrival($arrival_params); + + # calculate the total ships before the expense of any database operations. + my $total_ships = 0; + map {$total_ships += $_->{quantity}} @$type_params; + my $max_ships = Lacuna->config->get('ships_per_fleet') || 20; + if ($total_ships > $max_ships) { + confess [1009, 'Too many ships for a fleet.']; + } + + my $ship_ref; + my $do_captcha_check = 0; + foreach my $type_param (@$type_params) { + foreach my $arg (qw(speed stealth combat quantity)) { + confess [1002, "$arg cannot be negative."] if $type_param->{$arg} < 0; + confess [1002, "$arg must be an integer."] if $type_param->{$arg} != int($type_param->{$arg}); + } + my $type = $type_param->{type}; + my $speed = $type_param->{speed}; + my $stealth = $type_param->{stealth}; + my $combat = $type_param->{combat}; + my $quantity = $type_param->{quantity}; + confess [1009, "Cannot send more than one excavator"] if ($type eq 'excavator' and $quantity > 1); + + # TODO Must check for valid berth levels + # + my $ships_rs = Lacuna->db->resultset('Ships')->search({ + body_id => $body->id, + task => 'Docked', + type => $type, + speed => $speed, + stealth => $stealth, + combat => $combat, + }); + if ($ships_rs->count < $quantity) { + confess [1009, "Cannot find $quantity of $type ships."]; + } + my @ships = $ships_rs->search(undef,{rows => $quantity}); + my $ship = $ships[0]; + # We only need to check one of the ships + $ship->can_send_to_target($target); + if (not $do_captcha_check and $ship->hostile_action) { + $do_captcha_check = 1; + } + foreach my $ship (@ships) { + my $hash = "${type}#${speed}#${stealth}#${combat}"; + $ship_ref->{$hash} = $ship; + } + } + if ($do_captcha_check) { + $empire->current_session->check_captcha; + } + # If we get here without exceptions, then all ships can be sent + foreach my $ship (values %$ship_ref) { + $ship->fleet_speed(1); + $ship->send(target => $target, arrival => $arrival); + } + +} + sub send_fleet { my ($self, $session_id, $ship_ids, $target_params, $set_speed) = @_; $set_speed //= 0; @@ -905,7 +1056,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_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 view_battle_logs)); +__PACKAGE__->register_rpc_method_names(qw(get_fleet_for 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 view_battle_logs)); no Moose; diff --git a/t/440_fleets.t b/t/440_fleets.t new file mode 100644 index 00000000..3e51eef0 --- /dev/null +++ b/t/440_fleets.t @@ -0,0 +1,32 @@ +use lib '../lib'; + +use strict; +use warnings; + +use Test::More tests => 10; +use Test::Deep; +use Data::Dumper; +use 5.010; +use DateTime; + +use TestHelper; +my $tester = TestHelper->new->use_existing_test_empire; +my $session_id = $tester->session->id; +my $empire = $tester->empire; +my $home = $empire->home_planet; +my $command = $home->command; + +my $result; + +my $space_port = Lacuna->db->resultset('Building')->search({ + class => 'Lacuna::DB::Result::Building::SpacePort', + body_id => $home->id, + },{ + rows => 1, +})->single; + +$result = $tester->post('spaceport','get_fleet_for', [$session_id, $home->id, {body_name => 'DeLambert-5-28'}]); + +END { +# TestHelper->clear_all_test_empires; +} -- 2.51.2 From 8a769810c6d44fdcbb1ebb34ed17cc166ac5ccd5 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 13 May 2012 13:48:35 -0400 Subject: [PATCH 052/105] Minor changes --- lib/Lacuna/RPC/Building/SpacePort.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 15568088..dfe69c99 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -257,7 +257,7 @@ sub find_arrival { } sub send_ship_types { - my ($self, $session_id, $from_body_id, $target_params, $type_params, $arrival) = @_; + my ($self, $session_id, $body_id, $target_params, $type_params, $arrival) = @_; my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); @@ -319,7 +319,7 @@ sub send_ship_types { $ship->fleet_speed(1); $ship->send(target => $target, arrival => $arrival); } - + return $self->get_fleet_for($session, $body_id, $target_params); } sub send_fleet { -- 2.51.2 From 14f8a72d3f1d4a13075bad407d9ba0c6f5c7133d Mon Sep 17 00:00:00 2001 From: ian docherty Date: Tue, 15 May 2012 05:09:30 -0400 Subject: [PATCH 053/105] Fix error checking for send_ship_types --- lib/Lacuna/RPC/Building/SpacePort.pm | 16 +++++++++------- t/440_fleets.t | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index dfe69c99..12564f1b 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -6,6 +6,8 @@ no warnings qw(uninitialized); extends 'Lacuna::RPC::Building'; use Lacuna::Constants qw(SHIP_TYPES); use Lacuna::Util qw(format_date); +use Data::Dumper; + use feature "switch"; sub app_url { @@ -228,7 +230,7 @@ sub find_arrival { my $second = $arrival_params->{second}; if (not defined $day or $day < 1 or $day > $mon_end->day) { - confess [1009, 'Invalid day.']; + confess [1009, "Invalid day. [$day][".Dumper($arrival_params)."]"]; } if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { confess [1002, 'Invalid hour.']; @@ -236,8 +238,8 @@ sub find_arrival { if (not defined $minute or $minute != int($minute) or $minute < 0 or $minute > 59) { confess [1002, 'Invalid minute.']; } - if (not defined $second or $second != int($second) or $second < 0 or $second > 59) { - confess [1002, 'Invalid second.']; + if (not defined $second or $second != 0 and $second != 15 and $second != 30 and $second != 45) { + confess [1002, 'Invalid second. Must be 0, 15, 30 or 45']; } if ($day < $now->day) { # Then it must be a day next month @@ -257,7 +259,7 @@ sub find_arrival { } sub send_ship_types { - my ($self, $session_id, $body_id, $target_params, $type_params, $arrival) = @_; + my ($self, $session_id, $body_id, $target_params, $type_params, $arrival_params) = @_; my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); @@ -319,7 +321,7 @@ sub send_ship_types { $ship->fleet_speed(1); $ship->send(target => $target, arrival => $arrival); } - return $self->get_fleet_for($session, $body_id, $target_params); + return $self->get_fleet_for($session_id, $body_id, $target_params); } sub send_fleet { @@ -327,7 +329,7 @@ sub send_fleet { $set_speed //= 0; my $empire = $self->get_empire_by_session($session_id); my $target = $self->find_target($target_params); - my $max_ships = Lacuna->config->get('ships_per_fleet') || 20; + my $max_ships = Lacuna->config->get('ships_per_fleet') || 50; if (@$ship_ids > $max_ships) { confess [1009, 'Too many ships for a fleet.']; } @@ -1056,7 +1058,7 @@ around 'view' => sub { return $out; }; -__PACKAGE__->register_rpc_method_names(qw(get_fleet_for 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 view_battle_logs)); +__PACKAGE__->register_rpc_method_names(qw(send_ship_types get_fleet_for 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 view_battle_logs)); no Moose; diff --git a/t/440_fleets.t b/t/440_fleets.t index 3e51eef0..d4113cd9 100644 --- a/t/440_fleets.t +++ b/t/440_fleets.t @@ -27,6 +27,23 @@ my $space_port = Lacuna->db->resultset('Building')->search({ $result = $tester->post('spaceport','get_fleet_for', [$session_id, $home->id, {body_name => 'DeLambert-5-28'}]); +my ($sweepers) = grep {$_->{type} eq 'sweeper'} @{$result->{result}{ships}}; + +diag Dumper(\$sweepers); + +Lacuna->cache->set('captcha', $session_id, { guid => 1111, solution => 1111 }, 60 * 30 ); +$result = $tester->post('captcha','solve', [$session_id, 1111, 1111]); +is($result->{result}, 1, 'Solved captcha'); + + +$result = $tester->post('spaceport','send_ship_types', [ + $session_id, + $home->id, + {body_name => 'DeLambert-5-28'}, + [{type => 'sweeper', speed => $sweepers->{speed}, stealth => $sweepers->{stealth}, combat => $sweepers->{combat}, quantity => 10}], + {day => 10, hour => 1, minute => 1, second => 15}, +]); + END { # TestHelper->clear_all_test_empires; } -- 2.51.2 From 46be3455473a92c58980795555174b9d9c9a3aed Mon Sep 17 00:00:00 2001 From: ian docherty Date: Thu, 17 May 2012 14:30:27 -0400 Subject: [PATCH 054/105] Send all ships in the fleet, not just one. --- lib/Lacuna/RPC/Building/SpacePort.pm | 3 +-- t/440_fleets.t | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 12564f1b..0175be4e 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -309,8 +309,7 @@ sub send_ship_types { $do_captcha_check = 1; } foreach my $ship (@ships) { - my $hash = "${type}#${speed}#${stealth}#${combat}"; - $ship_ref->{$hash} = $ship; + $ship_ref->{$ship->id} = $ship; } } if ($do_captcha_check) { diff --git a/t/440_fleets.t b/t/440_fleets.t index d4113cd9..787056fe 100644 --- a/t/440_fleets.t +++ b/t/440_fleets.t @@ -41,7 +41,7 @@ $result = $tester->post('spaceport','send_ship_types', [ $home->id, {body_name => 'DeLambert-5-28'}, [{type => 'sweeper', speed => $sweepers->{speed}, stealth => $sweepers->{stealth}, combat => $sweepers->{combat}, quantity => 10}], - {day => 10, hour => 1, minute => 1, second => 15}, + {day => 10, hour => 0, minute => 0, second => 0}, ]); END { -- 2.51.2 From 184aab3034073d373e4c32cadd5130ef464b26d7 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 13 May 2012 05:19:39 -0400 Subject: [PATCH 055/105] Started adding new fleet action API calls --- lib/Lacuna/RPC/Building/SpacePort.pm | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 0175be4e..76e3776f 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -230,7 +230,11 @@ sub find_arrival { my $second = $arrival_params->{second}; if (not defined $day or $day < 1 or $day > $mon_end->day) { +<<<<<<< HEAD confess [1009, "Invalid day. [$day][".Dumper($arrival_params)."]"]; +======= + confess [1009, 'Invalid day.']; +>>>>>>> Started adding new fleet action API calls } if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { confess [1002, 'Invalid hour.']; @@ -238,8 +242,13 @@ sub find_arrival { if (not defined $minute or $minute != int($minute) or $minute < 0 or $minute > 59) { confess [1002, 'Invalid minute.']; } +<<<<<<< HEAD if (not defined $second or $second != 0 and $second != 15 and $second != 30 and $second != 45) { confess [1002, 'Invalid second. Must be 0, 15, 30 or 45']; +======= + if (not defined $second or $second != int($second) or $second < 0 or $second > 59) { + confess [1002, 'Invalid second.']; +>>>>>>> Started adding new fleet action API calls } if ($day < $now->day) { # Then it must be a day next month @@ -259,7 +268,11 @@ sub find_arrival { } sub send_ship_types { +<<<<<<< HEAD my ($self, $session_id, $body_id, $target_params, $type_params, $arrival_params) = @_; +======= + my ($self, $session_id, $from_body_id, $target_params, $type_params, $arrival) = @_; +>>>>>>> Started adding new fleet action API calls my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); @@ -309,7 +322,12 @@ sub send_ship_types { $do_captcha_check = 1; } foreach my $ship (@ships) { +<<<<<<< HEAD $ship_ref->{$ship->id} = $ship; +======= + my $hash = "${type}#${speed}#${stealth}#${combat}"; + $ship_ref->{$hash} = $ship; +>>>>>>> Started adding new fleet action API calls } } if ($do_captcha_check) { @@ -320,7 +338,11 @@ sub send_ship_types { $ship->fleet_speed(1); $ship->send(target => $target, arrival => $arrival); } +<<<<<<< HEAD return $self->get_fleet_for($session_id, $body_id, $target_params); +======= + +>>>>>>> Started adding new fleet action API calls } sub send_fleet { @@ -1059,7 +1081,6 @@ around 'view' => sub { __PACKAGE__->register_rpc_method_names(qw(send_ship_types get_fleet_for 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 view_battle_logs)); - no Moose; __PACKAGE__->meta->make_immutable; -- 2.51.2 From b652ce64c5b9be90a1e09d817ad2d8bc2a9cad9e Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 13 May 2012 13:48:35 -0400 Subject: [PATCH 056/105] Minor changes --- lib/Lacuna/RPC/Building/SpacePort.pm | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 76e3776f..f2267570 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -230,11 +230,7 @@ sub find_arrival { my $second = $arrival_params->{second}; if (not defined $day or $day < 1 or $day > $mon_end->day) { -<<<<<<< HEAD confess [1009, "Invalid day. [$day][".Dumper($arrival_params)."]"]; -======= - confess [1009, 'Invalid day.']; ->>>>>>> Started adding new fleet action API calls } if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { confess [1002, 'Invalid hour.']; @@ -242,13 +238,8 @@ sub find_arrival { if (not defined $minute or $minute != int($minute) or $minute < 0 or $minute > 59) { confess [1002, 'Invalid minute.']; } -<<<<<<< HEAD if (not defined $second or $second != 0 and $second != 15 and $second != 30 and $second != 45) { confess [1002, 'Invalid second. Must be 0, 15, 30 or 45']; -======= - if (not defined $second or $second != int($second) or $second < 0 or $second > 59) { - confess [1002, 'Invalid second.']; ->>>>>>> Started adding new fleet action API calls } if ($day < $now->day) { # Then it must be a day next month @@ -268,11 +259,7 @@ sub find_arrival { } sub send_ship_types { -<<<<<<< HEAD my ($self, $session_id, $body_id, $target_params, $type_params, $arrival_params) = @_; -======= - my ($self, $session_id, $from_body_id, $target_params, $type_params, $arrival) = @_; ->>>>>>> Started adding new fleet action API calls my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); @@ -322,12 +309,7 @@ sub send_ship_types { $do_captcha_check = 1; } foreach my $ship (@ships) { -<<<<<<< HEAD $ship_ref->{$ship->id} = $ship; -======= - my $hash = "${type}#${speed}#${stealth}#${combat}"; - $ship_ref->{$hash} = $ship; ->>>>>>> Started adding new fleet action API calls } } if ($do_captcha_check) { @@ -338,11 +320,7 @@ sub send_ship_types { $ship->fleet_speed(1); $ship->send(target => $target, arrival => $arrival); } -<<<<<<< HEAD return $self->get_fleet_for($session_id, $body_id, $target_params); -======= - ->>>>>>> Started adding new fleet action API calls } sub send_fleet { -- 2.51.2 From c93683a9e4eea5688bbb364f90452a29dc0720e2 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 3 Jun 2012 04:50:41 -0400 Subject: [PATCH 057/105] Start to convert ships into fleets --- lib/Lacuna/DB/Result/Fleet.pm | 370 ++++++++++++++++++++++++++++++++++ 1 file changed, 370 insertions(+) create mode 100644 lib/Lacuna/DB/Result/Fleet.pm diff --git a/lib/Lacuna/DB/Result/Fleet.pm b/lib/Lacuna/DB/Result/Fleet.pm new file mode 100644 index 00000000..f6941df7 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet.pm @@ -0,0 +1,370 @@ +package Lacuna::DB::Result::Ships; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result'; +use Lacuna::Util qw(format_date randint); +use DateTime; +use feature "switch"; + +has 'hostile_action' => ( + is => 'rw', + isa => 'Bool', + lazy => 1, + builder => '_build_hostile_action', +); + +sub _build_hostile_action { 0 } + +__PACKAGE__->load_components('DynamicSubclass'); +__PACKAGE__->table('ships'); +__PACKAGE__->add_columns( + body_id => { data_type => 'int', is_nullable => 0 }, + shipyard_id => { data_type => 'int', is_nullable => 0 }, + date_started => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, + date_available => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, + type => { data_type => 'varchar', size => 30, is_nullable => 0 }, # probe, colony_ship, spy_pod, cargo_ship, space_station, smuggler_ship, mining_platform_ship, terraforming_platform_ship, gas_giant_settlement_ship + task => { data_type => 'varchar', size => 30, is_nullable => 0 }, # Docked, Building, Travelling, Mining, Defend, Orbiting + name => { data_type => 'varchar', size => 30, is_nullable => 0 }, + speed => { data_type => 'int', is_nullable => 0 }, + stealth => { data_type => 'int', is_nullable => 0 }, + combat => { data_type => 'int', is_nullable => 0 }, + hold_size => { data_type => 'int', is_nullable => 0 }, + payload => { data_type => 'mediumblob', is_nullable => 1, 'serializer_class' => 'JSON' }, + roundtrip => { data_type => 'bit', default_value => 0 }, + direction => { data_type => 'varchar', size => 3, is_nullable => 0 }, # in || out + foreign_body_id => { data_type => 'int', is_nullable => 1 }, + foreign_star_id => { data_type => 'int', is_nullable => 1 }, + fleet_speed => { data_type => 'int', is_nullable => 0 }, + berth_level => { data_type => 'int', is_nullable => 0 }, +); +__PACKAGE__->typecast_map(type => { + 'probe' => 'Lacuna::DB::Result::Ships::Probe', + 'stake' => 'Lacuna::DB::Result::Ships::Stake', + 'supply_pod' => 'Lacuna::DB::Result::Ships::SupplyPod', + 'supply_pod2' => 'Lacuna::DB::Result::Ships::SupplyPod2', + 'supply_pod3' => 'Lacuna::DB::Result::Ships::SupplyPod3', + 'supply_pod4' => 'Lacuna::DB::Result::Ships::SupplyPod4', + 'placebo' => 'Lacuna::DB::Result::Ships::Placebo', + 'placebo2' => 'Lacuna::DB::Result::Ships::Placebo2', + 'placebo3' => 'Lacuna::DB::Result::Ships::Placebo3', + 'placebo4' => 'Lacuna::DB::Result::Ships::Placebo4', + 'placebo5' => 'Lacuna::DB::Result::Ships::Placebo5', + 'placebo6' => 'Lacuna::DB::Result::Ships::Placebo6', + 'short_range_colony_ship' => 'Lacuna::DB::Result::Ships::ShortRangeColonyShip', + 'colony_ship' => 'Lacuna::DB::Result::Ships::ColonyShip', + 'spy_pod' => 'Lacuna::DB::Result::Ships::SpyPod', + 'cargo_ship' => 'Lacuna::DB::Result::Ships::CargoShip', + 'space_station' => 'Lacuna::DB::Result::Ships::SpaceStation', + 'smuggler_ship' => 'Lacuna::DB::Result::Ships::SmugglerShip', + 'mining_platform_ship' => 'Lacuna::DB::Result::Ships::MiningPlatformShip', + 'terraforming_platform_ship' => 'Lacuna::DB::Result::Ships::TerraformingPlatformShip', + 'gas_giant_settlement_ship' => 'Lacuna::DB::Result::Ships::GasGiantSettlementPlatformShip', + 'scanner' => 'Lacuna::DB::Result::Ships::Scanner', + 'surveyor' => 'Lacuna::DB::Result::Ships::Surveyor', + 'detonator' => 'Lacuna::DB::Result::Ships::Detonator', + 'excavator' => 'Lacuna::DB::Result::Ships::Excavator', + 'scow' => 'Lacuna::DB::Result::Ships::Scow', + 'scow_large' => 'Lacuna::DB::Result::Ships::ScowLarge', + 'scow_mega' => 'Lacuna::DB::Result::Ships::ScowMega', + 'scow_fast' => 'Lacuna::DB::Result::Ships::ScowFast', + 'freighter' => 'Lacuna::DB::Result::Ships::Freighter', + 'dory' => 'Lacuna::DB::Result::Ships::Dory', + 'barge' => 'Lacuna::DB::Result::Ships::Barge', + 'galleon' => 'Lacuna::DB::Result::Ships::Galleon', + 'hulk' => 'Lacuna::DB::Result::Ships::Hulk', + 'hulk_huge' => 'Lacuna::DB::Result::Ships::HulkHuge', + 'hulk_fast' => 'Lacuna::DB::Result::Ships::HulkFast', + 'snark' => 'Lacuna::DB::Result::Ships::Snark', + 'snark2' => 'Lacuna::DB::Result::Ships::Snark2', + 'snark3' => 'Lacuna::DB::Result::Ships::Snark3', + 'spy_shuttle' => 'Lacuna::DB::Result::Ships::SpyShuttle', + 'drone' => 'Lacuna::DB::Result::Ships::Drone', + 'fighter' => 'Lacuna::DB::Result::Ships::Fighter', + 'sweeper' => 'Lacuna::DB::Result::Ships::Sweeper', + 'bleeder' => 'Lacuna::DB::Result::Ships::Bleeder', + 'thud' => 'Lacuna::DB::Result::Ships::Thud', + 'observatory_seeker' => 'Lacuna::DB::Result::Ships::ObservatorySeeker', + 'spaceport_seeker' => 'Lacuna::DB::Result::Ships::SpacePortSeeker', + 'security_ministry_seeker' => 'Lacuna::DB::Result::Ships::SecurityMinistrySeeker', +}); + +with 'Lacuna::Role::Container'; + +__PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Map::Body', 'body_id'); +__PACKAGE__->belongs_to('foreign_star', 'Lacuna::DB::Result::Map::Star', 'foreign_star_id'); +__PACKAGE__->belongs_to('foreign_body', 'Lacuna::DB::Result::Map::Body', 'foreign_body_id'); + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::University', level => 1 } ]; +use constant base_food_cost => 1; +use constant base_water_cost => 1; +use constant base_energy_cost => 1; +use constant base_ore_cost => 1; +use constant base_time_cost => 1; +use constant base_waste_cost => 1; +use constant base_speed => 1; +use constant base_combat => 0; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant base_berth_level => 1; +use constant pilotable => 0; +use constant target_building => []; +use constant build_tags => []; +use constant splash_radius => 0; + +sub max_occupants { + my $self = shift; + return 0 unless $self->pilotable; + return int($self->hold_size / 350); +} + +sub arrive { + my $self = shift; + eval {$self->handle_arrival_procedures}; # throws exceptions to stop subsequent actions from happening + my $reason = $@; + if (ref $reason eq 'ARRAY' && $reason->[0] eq -1) { + # this is an expected exception, it means one of the roles took over + return; + } + elsif ($reason) { + # this is unexpected, so let's rethrow + confess $reason; + } + + # no exceptions, so we either need to go home or land + if ($self->direction eq 'out') { + $self->turn_around->update; + } + else { + $self->land->update; + } +} + +sub handle_arrival_procedures { + my $self = shift; + $self->note_arrival; +} + +sub note_arrival { + my $self = shift; + Lacuna->cache->increment($self->type.'_arrive_'.$self->foreign_body_id.$self->foreign_star_id, $self->body->empire_id,1, 60*60*24*30); +} + +sub is_available { + my ($self) = @_; + return ($self->task eq 'Docked'); +} + +sub can_send_to_target { + my $self = shift; + unless ($self->task eq 'Docked') { + confess [1010, 'That ship is busy.']; + } + return 1; +} + +sub can_recall { + my $self = shift; + unless ($self->task ~~ [qw(Defend Orbiting)]) { + confess [1010, 'That ship is busy.']; + } + return 1; +} + +sub type_formatted { + my $self = shift; + + return $self->type_human($self->type); +} + +sub type_human { + my ($self, $type) = @_; + + $type =~ s/_/ /g; + $type =~ s/\b(\w)/\u$1/g; + return $type; +} + +sub date_started_formatted { + my $self = shift; + return format_date($self->date_started); +} + +sub date_available_formatted { + my $self = shift; + return format_date($self->date_available); +} + +sub get_status { + my ($self, $target) = @_; + my %status = ( + id => $self->id, + name => $self->name, + type_human => $self->type_formatted, + type => $self->type, + task => $self->task, + speed => $self->speed, + fleet_speed => $self->fleet_speed, + stealth => $self->stealth, + combat => $self->combat, + hold_size => $self->hold_size, + berth_level => $self->berth_level, + date_started => $self->date_started_formatted, + date_available => $self->date_available_formatted, + max_occupants => $self->max_occupants, + payload => $self->format_description_of_payload, + can_scuttle => ($self->task eq 'Docked') ? 1 : 0, + can_recall => ($self->task ~~ [qw(Defend Orbiting)]) ? 1 : 0, + ); + if ($target) { + $status{estimated_travel_time} = $self->calculate_travel_time($target); + } + if ($self->task eq 'Travelling') { + my $body = $self->body; + my $target = ($self->foreign_body_id) ? $self->foreign_body : $self->foreign_star; + my $from = { + id => $body->id, + name => $body->name, + type => 'body', + }; + my $to = { + id => $target->id, + name => $target->name, + type => (ref $target eq 'Lacuna::DB::Result::Map::Star') ? 'star' : 'body', + }; + if ($self->direction ne 'out') { + my $temp = $from; + $from = $to; + $to = $temp; + } + $status{to} = $to; + $status{from} = $from; + $status{date_arrives} = $status{date_available}; + } + elsif ($self->task ~~ [qw(Defend Orbiting)]) { + my $body = $self->body; + my $from = { + id => $body->id, + name => $body->name, + type => 'body', + }; + my $orbiting = { + id => $self->foreign_body_id, + name => $self->foreign_body->name, + type => 'body', + x => $self->foreign_body->x, + y => $self->foreign_body->y, + }; + $status{from} = $from; + $status{orbiting} = $orbiting; + } + return \%status; +} + +sub seconds_remaining { + my $self = shift; + return time - $self->date_available->epoch; +} + +sub turn_around { + my $self = shift; + $self->direction( ($self->direction eq 'out') ? 'in' : 'out' ); +# $self->date_available(DateTime->now->add_duration( $self->date_available - $self->date_started )); + $self->fleet_speed(0); + my $target = ($self->foreign_body_id) ? $self->foreign_body : $self->foreign_star; + $self->date_available(DateTime->now->add(seconds=>$self->calculate_travel_time($target))); + $self->date_started(DateTime->now); + return $self; +} + +sub send { + my ($self, %options ) = @_; + $self->date_started(DateTime->now); + $self->task('Travelling'); + $self->payload($options{payload} || {}); + $self->roundtrip($options{roundtrip} || 0); + $self->direction($options{direction} || 'out'); + my $arrival = $options{arrival} || DateTime->now->add(seconds=>$self->calculate_travel_time($options{target})); + $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}); + $self->foreign_star_id(undef); + $self->foreign_star(undef); + } + elsif ($options{target}->isa('Lacuna::DB::Result::Map::Star')) { + $self->foreign_star_id($options{target}->id); + $self->foreign_star($options{target}); + $self->foreign_body_id(undef); + $self->foreign_body(undef); + } + else { + confess [1002, 'You cannot send a ship to a non-existant target.']; + } + $self->update; + return $self; +} + +sub finish_construction { + my ($self) = @_; + $self->body->empire->add_medal($self->type); + $self->task('Docked'); + $self->date_available(DateTime->now); + $self->update; +} + +sub orbit { + my ($self) = @_; + $self->task('Orbiting'); + $self->date_available(DateTime->now); + return $self; +} + +sub defend { + my ($self) = @_; + $self->task('Defend'); + $self->date_available(DateTime->now); + return $self; +} + +sub land { + my ($self) = @_; + $self->task('Docked'); + $self->fleet_speed(0); + $self->date_available(DateTime->now); + $self->payload({}); + return $self; +} + + + + +# DISTANCE + + + +sub calculate_travel_time { + my ($self, $target) = @_; + + my $distance = $self->body->calculate_distance_to_target($target); + my $speed = $self->speed; + if ( $self->fleet_speed > 0 && $self->fleet_speed < $self->speed ) { + $speed = $self->fleet_speed; + } + return $self->travel_time($self->body, $target, $speed); +} + +sub travel_time { + my ($class, $from, $target, $speed) = @_; + + my $distance = $from->calculate_distance_to_target($target); + $speed ||= 1; + my $hours = $distance / $speed; + my $seconds = 60 * 60 * $hours; + return sprintf('%.0f', $seconds); +} + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); -- 2.51.2 From f881f7c4f648c30447839735b72f4a66c9b93eac Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 3 Jun 2012 05:24:48 -0400 Subject: [PATCH 058/105] Added Fleet SQL --- lib/Lacuna/DB/Result/Fleet.pm | 133 +++++++++++++++++----------------- var/upgrades/3.fleet.sql | 31 ++++++++ 2 files changed, 98 insertions(+), 66 deletions(-) create mode 100644 var/upgrades/3.fleet.sql diff --git a/lib/Lacuna/DB/Result/Fleet.pm b/lib/Lacuna/DB/Result/Fleet.pm index f6941df7..5557e8a4 100644 --- a/lib/Lacuna/DB/Result/Fleet.pm +++ b/lib/Lacuna/DB/Result/Fleet.pm @@ -1,4 +1,4 @@ -package Lacuna::DB::Result::Ships; +package Lacuna::DB::Result::Fleet; use Moose; use utf8; @@ -18,14 +18,15 @@ has 'hostile_action' => ( sub _build_hostile_action { 0 } __PACKAGE__->load_components('DynamicSubclass'); -__PACKAGE__->table('ships'); +__PACKAGE__->table('fleet'); __PACKAGE__->add_columns( body_id => { data_type => 'int', is_nullable => 0 }, + mark => { data_type => 'varchar', size => 10, is_nullable => 0 }, shipyard_id => { data_type => 'int', is_nullable => 0 }, date_started => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, date_available => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, - type => { data_type => 'varchar', size => 30, is_nullable => 0 }, # probe, colony_ship, spy_pod, cargo_ship, space_station, smuggler_ship, mining_platform_ship, terraforming_platform_ship, gas_giant_settlement_ship - task => { data_type => 'varchar', size => 30, is_nullable => 0 }, # Docked, Building, Travelling, Mining, Defend, Orbiting + type => { data_type => 'varchar', size => 30, is_nullable => 0 }, + task => { data_type => 'varchar', size => 30, is_nullable => 0 }, name => { data_type => 'varchar', size => 30, is_nullable => 0 }, speed => { data_type => 'int', is_nullable => 0 }, stealth => { data_type => 'int', is_nullable => 0 }, @@ -40,54 +41,54 @@ __PACKAGE__->add_columns( berth_level => { data_type => 'int', is_nullable => 0 }, ); __PACKAGE__->typecast_map(type => { - 'probe' => 'Lacuna::DB::Result::Ships::Probe', - 'stake' => 'Lacuna::DB::Result::Ships::Stake', - 'supply_pod' => 'Lacuna::DB::Result::Ships::SupplyPod', - 'supply_pod2' => 'Lacuna::DB::Result::Ships::SupplyPod2', - 'supply_pod3' => 'Lacuna::DB::Result::Ships::SupplyPod3', - 'supply_pod4' => 'Lacuna::DB::Result::Ships::SupplyPod4', - 'placebo' => 'Lacuna::DB::Result::Ships::Placebo', - 'placebo2' => 'Lacuna::DB::Result::Ships::Placebo2', - 'placebo3' => 'Lacuna::DB::Result::Ships::Placebo3', - 'placebo4' => 'Lacuna::DB::Result::Ships::Placebo4', - 'placebo5' => 'Lacuna::DB::Result::Ships::Placebo5', - 'placebo6' => 'Lacuna::DB::Result::Ships::Placebo6', - 'short_range_colony_ship' => 'Lacuna::DB::Result::Ships::ShortRangeColonyShip', - 'colony_ship' => 'Lacuna::DB::Result::Ships::ColonyShip', - 'spy_pod' => 'Lacuna::DB::Result::Ships::SpyPod', - 'cargo_ship' => 'Lacuna::DB::Result::Ships::CargoShip', - 'space_station' => 'Lacuna::DB::Result::Ships::SpaceStation', - 'smuggler_ship' => 'Lacuna::DB::Result::Ships::SmugglerShip', - 'mining_platform_ship' => 'Lacuna::DB::Result::Ships::MiningPlatformShip', - 'terraforming_platform_ship' => 'Lacuna::DB::Result::Ships::TerraformingPlatformShip', - 'gas_giant_settlement_ship' => 'Lacuna::DB::Result::Ships::GasGiantSettlementPlatformShip', - 'scanner' => 'Lacuna::DB::Result::Ships::Scanner', - 'surveyor' => 'Lacuna::DB::Result::Ships::Surveyor', - 'detonator' => 'Lacuna::DB::Result::Ships::Detonator', - 'excavator' => 'Lacuna::DB::Result::Ships::Excavator', - 'scow' => 'Lacuna::DB::Result::Ships::Scow', - 'scow_large' => 'Lacuna::DB::Result::Ships::ScowLarge', - 'scow_mega' => 'Lacuna::DB::Result::Ships::ScowMega', - 'scow_fast' => 'Lacuna::DB::Result::Ships::ScowFast', - 'freighter' => 'Lacuna::DB::Result::Ships::Freighter', - 'dory' => 'Lacuna::DB::Result::Ships::Dory', - 'barge' => 'Lacuna::DB::Result::Ships::Barge', - 'galleon' => 'Lacuna::DB::Result::Ships::Galleon', - 'hulk' => 'Lacuna::DB::Result::Ships::Hulk', - 'hulk_huge' => 'Lacuna::DB::Result::Ships::HulkHuge', - 'hulk_fast' => 'Lacuna::DB::Result::Ships::HulkFast', - 'snark' => 'Lacuna::DB::Result::Ships::Snark', - 'snark2' => 'Lacuna::DB::Result::Ships::Snark2', - 'snark3' => 'Lacuna::DB::Result::Ships::Snark3', - 'spy_shuttle' => 'Lacuna::DB::Result::Ships::SpyShuttle', - 'drone' => 'Lacuna::DB::Result::Ships::Drone', - 'fighter' => 'Lacuna::DB::Result::Ships::Fighter', - 'sweeper' => 'Lacuna::DB::Result::Ships::Sweeper', - 'bleeder' => 'Lacuna::DB::Result::Ships::Bleeder', - 'thud' => 'Lacuna::DB::Result::Ships::Thud', - 'observatory_seeker' => 'Lacuna::DB::Result::Ships::ObservatorySeeker', - 'spaceport_seeker' => 'Lacuna::DB::Result::Ships::SpacePortSeeker', - 'security_ministry_seeker' => 'Lacuna::DB::Result::Ships::SecurityMinistrySeeker', + 'probe' => 'Lacuna::DB::Result::Fleet::Probe', + 'stake' => 'Lacuna::DB::Result::Fleet::Stake', + 'supply_pod' => 'Lacuna::DB::Result::Fleet::SupplyPod', + 'supply_pod2' => 'Lacuna::DB::Result::Fleet::SupplyPod2', + 'supply_pod3' => 'Lacuna::DB::Result::Fleet::SupplyPod3', + 'supply_pod4' => 'Lacuna::DB::Result::Fleet::SupplyPod4', + 'placebo' => 'Lacuna::DB::Result::Fleet::Placebo', + 'placebo2' => 'Lacuna::DB::Result::Fleet::Placebo2', + 'placebo3' => 'Lacuna::DB::Result::Fleet::Placebo3', + 'placebo4' => 'Lacuna::DB::Result::Fleet::Placebo4', + 'placebo5' => 'Lacuna::DB::Result::Fleet::Placebo5', + 'placebo6' => 'Lacuna::DB::Result::Fleet::Placebo6', + 'short_range_colony_ship' => 'Lacuna::DB::Result::Fleet::ShortRangeColonyShip', + 'colony_ship' => 'Lacuna::DB::Result::Fleet::ColonyShip', + 'spy_pod' => 'Lacuna::DB::Result::Fleet::SpyPod', + 'cargo_ship' => 'Lacuna::DB::Result::Fleet::CargoShip', + 'space_station' => 'Lacuna::DB::Result::Fleet::SpaceStation', + 'smuggler_ship' => 'Lacuna::DB::Result::Fleet::SmugglerShip', + 'mining_platform_ship' => 'Lacuna::DB::Result::Fleet::MiningPlatformShip', + 'terraforming_platform_ship' => 'Lacuna::DB::Result::Fleet::TerraformingPlatformShip', + 'gas_giant_settlement_ship' => 'Lacuna::DB::Result::Fleet::GasGiantSettlementPlatformShip', + 'scanner' => 'Lacuna::DB::Result::Fleet::Scanner', + 'surveyor' => 'Lacuna::DB::Result::Fleet::Surveyor', + 'detonator' => 'Lacuna::DB::Result::Fleet::Detonator', + 'excavator' => 'Lacuna::DB::Result::Fleet::Excavator', + 'scow' => 'Lacuna::DB::Result::Fleet::Scow', + 'scow_large' => 'Lacuna::DB::Result::Fleet::ScowLarge', + 'scow_mega' => 'Lacuna::DB::Result::Fleet::ScowMega', + 'scow_fast' => 'Lacuna::DB::Result::Fleet::ScowFast', + 'freighter' => 'Lacuna::DB::Result::Fleet::Freighter', + 'dory' => 'Lacuna::DB::Result::Fleet::Dory', + 'barge' => 'Lacuna::DB::Result::Fleet::Barge', + 'galleon' => 'Lacuna::DB::Result::Fleet::Galleon', + 'hulk' => 'Lacuna::DB::Result::Fleet::Hulk', + 'hulk_huge' => 'Lacuna::DB::Result::Fleet::HulkHuge', + 'hulk_fast' => 'Lacuna::DB::Result::Fleet::HulkFast', + 'snark' => 'Lacuna::DB::Result::Fleet::Snark', + 'snark2' => 'Lacuna::DB::Result::Fleet::Snark2', + 'snark3' => 'Lacuna::DB::Result::Fleet::Snark3', + 'spy_shuttle' => 'Lacuna::DB::Result::Fleet::SpyShuttle', + 'drone' => 'Lacuna::DB::Result::Fleet::Drone', + 'fighter' => 'Lacuna::DB::Result::Fleet::Fighter', + 'sweeper' => 'Lacuna::DB::Result::Fleet::Sweeper', + 'bleeder' => 'Lacuna::DB::Result::Fleet::Bleeder', + 'thud' => 'Lacuna::DB::Result::Fleet::Thud', + 'observatory_seeker' => 'Lacuna::DB::Result::Fleet::ObservatorySeeker', + 'spaceport_seeker' => 'Lacuna::DB::Result::Fleet::SpacePortSeeker', + 'security_ministry_seeker' => 'Lacuna::DB::Result::Fleet::SecurityMinistrySeeker', }); with 'Lacuna::Role::Container'; @@ -122,7 +123,7 @@ sub max_occupants { sub arrive { my $self = shift; eval {$self->handle_arrival_procedures}; # throws exceptions to stop subsequent actions from happening - my $reason = $@; + my $reason = $@; if (ref $reason eq 'ARRAY' && $reason->[0] eq -1) { # this is an expected exception, it means one of the roles took over return; @@ -166,7 +167,7 @@ sub can_send_to_target { sub can_recall { my $self = shift; - unless ($self->task ~~ [qw(Defend Orbiting)]) { + unless ($self->task ~~ [qw(Defend Orbiting)]) { confess [1010, 'That ship is busy.']; } return 1; @@ -249,16 +250,16 @@ sub get_status { name => $body->name, type => 'body', }; - my $orbiting = { - id => $self->foreign_body_id, + my $orbiting = { + id => $self->foreign_body_id, name => $self->foreign_body->name, - type => 'body', - x => $self->foreign_body->x, - y => $self->foreign_body->y, + type => 'body', + x => $self->foreign_body->x, + y => $self->foreign_body->y, }; - $status{from} = $from; - $status{orbiting} = $orbiting; - } + $status{from} = $from; + $status{orbiting} = $orbiting; + } return \%status; } @@ -316,15 +317,15 @@ sub finish_construction { } sub orbit { - my ($self) = @_; - $self->task('Orbiting'); + my ($self) = @_; + $self->task('Orbiting'); $self->date_available(DateTime->now); return $self; } sub defend { - my ($self) = @_; - $self->task('Defend'); + my ($self) = @_; + $self->task('Defend'); $self->date_available(DateTime->now); return $self; } diff --git a/var/upgrades/3.fleet.sql b/var/upgrades/3.fleet.sql new file mode 100644 index 00000000..da71e190 --- /dev/null +++ b/var/upgrades/3.fleet.sql @@ -0,0 +1,31 @@ + +create table fleet ( + id int(11) not null auto_increment, + body_id int(11) not null, + shipyard_id int(11) not null, + date_started datetime not null, + date_available datetime not null, + mark varchar(10) not null, + type varchar(30) not null, + task varchar(30) not null, + name varchar(30) not null, + speed int(11) not null, + stealth int(11) not null, + combat int(11) not null, + hold_size int(11) not null, + payload mediumblob, + roundtrip tinyint(4) not null default 0, + direction varchar(3) not null, + foreign_body_id int(11), + foreign_star_id int(11), + berth_level tinyint(4) default 1, + primary key (id), + key f_mark (mark), + key f_idx_body_id (body_id), + key f_idx_foreign_body_id (foreign_body_id), + key f_idx_foreign_star_id (foreign_star_id), + constraint wc_f_body_id foreign key (body_id) references body (id), + constraint wc_f_foreign_body_id foreign key (foreign_body_id) references body (id), + constraint wc_f_foreign_star_id foreign key (foreign_star_id) references star (id) +); + -- 2.51.2 From 57c3db7ae6d45b4e0ef9e8115ba3b74aa4c25e8f Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 13 May 2012 05:19:39 -0400 Subject: [PATCH 059/105] Started adding new fleet action API calls --- lib/Lacuna/RPC/Building/SpacePort.pm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index f2267570..76e3776f 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -230,7 +230,11 @@ sub find_arrival { my $second = $arrival_params->{second}; if (not defined $day or $day < 1 or $day > $mon_end->day) { +<<<<<<< HEAD confess [1009, "Invalid day. [$day][".Dumper($arrival_params)."]"]; +======= + confess [1009, 'Invalid day.']; +>>>>>>> Started adding new fleet action API calls } if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { confess [1002, 'Invalid hour.']; @@ -238,8 +242,13 @@ sub find_arrival { if (not defined $minute or $minute != int($minute) or $minute < 0 or $minute > 59) { confess [1002, 'Invalid minute.']; } +<<<<<<< HEAD if (not defined $second or $second != 0 and $second != 15 and $second != 30 and $second != 45) { confess [1002, 'Invalid second. Must be 0, 15, 30 or 45']; +======= + if (not defined $second or $second != int($second) or $second < 0 or $second > 59) { + confess [1002, 'Invalid second.']; +>>>>>>> Started adding new fleet action API calls } if ($day < $now->day) { # Then it must be a day next month @@ -259,7 +268,11 @@ sub find_arrival { } sub send_ship_types { +<<<<<<< HEAD my ($self, $session_id, $body_id, $target_params, $type_params, $arrival_params) = @_; +======= + my ($self, $session_id, $from_body_id, $target_params, $type_params, $arrival) = @_; +>>>>>>> Started adding new fleet action API calls my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); @@ -309,7 +322,12 @@ sub send_ship_types { $do_captcha_check = 1; } foreach my $ship (@ships) { +<<<<<<< HEAD $ship_ref->{$ship->id} = $ship; +======= + my $hash = "${type}#${speed}#${stealth}#${combat}"; + $ship_ref->{$hash} = $ship; +>>>>>>> Started adding new fleet action API calls } } if ($do_captcha_check) { @@ -320,7 +338,11 @@ sub send_ship_types { $ship->fleet_speed(1); $ship->send(target => $target, arrival => $arrival); } +<<<<<<< HEAD return $self->get_fleet_for($session_id, $body_id, $target_params); +======= + +>>>>>>> Started adding new fleet action API calls } sub send_fleet { -- 2.51.2 From f95ea619ffe2e54f1498715599442e1626fad09e Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 3 Jun 2012 06:25:13 -0400 Subject: [PATCH 060/105] Added Fleet files --- bin/convert_ships_to_fleets.pl | 81 +++++++++++++++++++ lib/Lacuna/DB/Result/Fleet/Barge.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/Bleeder.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/CargoShip.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/ColonyShip.pm | 30 +++++++ lib/Lacuna/DB/Result/Fleet/Detonator.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/Dory.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/Drone.pm | 24 ++++++ lib/Lacuna/DB/Result/Fleet/Excavator.pm | 25 ++++++ lib/Lacuna/DB/Result/Fleet/Fighter.pm | 24 ++++++ lib/Lacuna/DB/Result/Fleet/Freighter.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/Galleon.pm | 26 ++++++ .../Fleet/GasGiantSettlementPlatformShip.pm | 26 ++++++ lib/Lacuna/DB/Result/Fleet/Hulk.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/HulkFast.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/HulkHuge.pm | 28 +++++++ .../DB/Result/Fleet/MiningPlatformShip.pm | 27 +++++++ .../DB/Result/Fleet/ObservatorySeeker.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Placebo.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/Placebo2.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Placebo3.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Placebo4.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Placebo5.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Placebo6.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Probe.pm | 24 ++++++ lib/Lacuna/DB/Result/Fleet/Scanner.pm | 27 +++++++ lib/Lacuna/DB/Result/Fleet/Scow.pm | 27 +++++++ lib/Lacuna/DB/Result/Fleet/ScowFast.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/ScowLarge.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/ScowMega.pm | 28 +++++++ .../DB/Result/Fleet/SecurityMinistrySeeker.pm | 29 +++++++ .../DB/Result/Fleet/ShortRangeColonyShip.pm | 31 +++++++ lib/Lacuna/DB/Result/Fleet/SmugglerShip.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/Snark.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Snark2.pm | 31 +++++++ lib/Lacuna/DB/Result/Fleet/Snark3.pm | 31 +++++++ lib/Lacuna/DB/Result/Fleet/SpacePortSeeker.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/SpaceStation.pm | 31 +++++++ lib/Lacuna/DB/Result/Fleet/SpyPod.pm | 32 ++++++++ lib/Lacuna/DB/Result/Fleet/SpyShuttle.pm | 31 +++++++ lib/Lacuna/DB/Result/Fleet/Stake.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/SupplyPod.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/SupplyPod2.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/SupplyPod3.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/SupplyPod4.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Surveyor.pm | 27 +++++++ lib/Lacuna/DB/Result/Fleet/Sweeper.pm | 27 +++++++ .../Result/Fleet/TerraformingPlatformShip.pm | 25 ++++++ lib/Lacuna/DB/Result/Fleet/Thud.pm | 29 +++++++ 49 files changed, 1436 insertions(+) create mode 100644 bin/convert_ships_to_fleets.pl create mode 100644 lib/Lacuna/DB/Result/Fleet/Barge.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Bleeder.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/CargoShip.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/ColonyShip.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Detonator.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Dory.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Drone.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Excavator.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Fighter.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Freighter.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Galleon.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/GasGiantSettlementPlatformShip.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Hulk.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/HulkFast.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/HulkHuge.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/MiningPlatformShip.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/ObservatorySeeker.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Placebo.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Placebo2.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Placebo3.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Placebo4.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Placebo5.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Placebo6.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Probe.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Scanner.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Scow.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/ScowFast.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/ScowLarge.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/ScowMega.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SecurityMinistrySeeker.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/ShortRangeColonyShip.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SmugglerShip.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Snark.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Snark2.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Snark3.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SpacePortSeeker.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SpaceStation.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SpyPod.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SpyShuttle.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Stake.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SupplyPod.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SupplyPod2.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SupplyPod3.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SupplyPod4.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Surveyor.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Sweeper.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/TerraformingPlatformShip.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Thud.pm diff --git a/bin/convert_ships_to_fleets.pl b/bin/convert_ships_to_fleets.pl new file mode 100644 index 00000000..9c3c3c9c --- /dev/null +++ b/bin/convert_ships_to_fleets.pl @@ -0,0 +1,81 @@ +use 5.010; +use strict; +use feature "switch"; +use lib '/data/Lacuna-Server/lib'; +use Lacuna::DB; +use Lacuna; +use Lacuna::Util qw(randint format_date); +use Getopt::Long; +$|=1; +our $quiet; +GetOptions( + 'quiet' => \$quiet, +); + +out('Started'); +my $start = time; + +out('Loading DB'); +our $db = Lacuna->db; + +out('Complete all ships being built'); +my $ships = $db->resultset('Lacuna::DB::Result::Ships')->search({ + task => 'Building', +}); +my $now = DateTime->now; +while (my $ship = $ships->next) { + $ship->update({ + task => 'Docked', + date_available => $now, + }); +} + +out('Zip all ships to their destination'); +my $ships = $db->resultset('Lacuna::DB::Result::Ships')->search({ + task => 'Travelling' +}); +while (my $ship = $ships->next) { + out('Zooming ship '.$ship->id); + $ship->update({ + date_available => $now, + }); +} + +out('Do a final tick of all planets'); +my $planets_rs = $db->resultset('Lacuna::DB::Result::Map::Body'); +my $planets = $planets_rs->search({ empire_id => {'!=' => 0} }); +while (my $planet = $planets->next) { + out('Ticking '.$planet->name); + eval{$planet->tick}; + my $reason = $@; + if (ref $reason eq 'ARRAY' && $reason->[0] eq -1) { + # this is an expected exception, it means one of the roles took over + } + elsif ( ref $reason eq 'ARRAY') { + out(sprintf("Ticking %s resulted in errno: %d, %s\n", $planet->name, $reason->[0], $reason->[1])); + } + elsif ( $reason ) { + out(sprintf("Ticking %s resulted in: %s\n", $planet->name, $reason)); + } +} + +$ships = $db->resultset('Lacuna::DB::Result::Ships')->search({},{ + group_by => [qw(body_id type task name speed stealth combat hold_size)], +}); + +my $finish = time; +out('Finished'); +out((($finish - $start)/60)." minutes have elapsed"); + + +############### +## SUBROUTINES +############### + +sub out { + my ($message) = @_; + unless ($quiet) { + say format_date(DateTime->now), " ", $message; + } +} + diff --git a/lib/Lacuna/DB/Result/Fleet/Barge.pm b/lib/Lacuna/DB/Result/Fleet/Barge.pm new file mode 100644 index 00000000..4149490e --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Barge.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::Barge; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 5 } ]; +use constant base_food_cost => 650; +use constant base_water_cost => 1900; +use constant base_energy_cost => 6100; +use constant base_ore_cost => 10300; +use constant base_time_cost => 5000; +use constant base_waste_cost => 900; +use constant base_speed => 1100; +use constant base_stealth => 2450; +use constant base_hold_size => 800; +use constant base_berth_level => 1; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining Intelligence SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CaptureWithSpies"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; +with "Lacuna::Role::Ship::Arrive::PickUpSpies"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Bleeder.pm b/lib/Lacuna/DB/Result/Fleet/Bleeder.pm new file mode 100644 index 00000000..af4cab2f --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Bleeder.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Bleeder; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 12 } ]; +use constant base_food_cost => 8000; +use constant base_water_cost => 21000; +use constant base_energy_cost => 69010; +use constant base_ore_cost => 95020; +use constant base_time_cost => 60 * 60 * 13; +use constant base_waste_cost => 12200; +use constant base_speed => 600; +use constant base_stealth => 2850; +use constant base_combat => 1700; +use constant base_hold_size => 0; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DeployBleeder"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/CargoShip.pm b/lib/Lacuna/DB/Result/Fleet/CargoShip.pm new file mode 100644 index 00000000..36711848 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/CargoShip.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::CargoShip; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 10 } ]; +use constant base_food_cost => 1200; +use constant base_water_cost => 3600; +use constant base_energy_cost => 12000; +use constant base_ore_cost => 20400; +use constant base_time_cost => 7200; +use constant base_waste_cost => 1500; +use constant base_speed => 1050; +use constant base_stealth => 1500; +use constant base_hold_size => 1700; +use constant base_berth_level => 5; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining Intelligence SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CaptureWithSpies"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; +with "Lacuna::Role::Ship::Arrive::PickUpSpies"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/ColonyShip.pm b/lib/Lacuna/DB/Result/Fleet/ColonyShip.pm new file mode 100644 index 00000000..41505e9a --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/ColonyShip.pm @@ -0,0 +1,30 @@ +package Lacuna::DB::Result::Fleet::ColonyShip; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Observatory', level => 5 } ]; +use constant base_food_cost => 45000; +use constant base_water_cost => 45000; +use constant base_energy_cost => 45000; +use constant base_ore_cost => 45000; +use constant base_time_cost => 60 * 60 * 24; +use constant base_waste_cost => 10000; +use constant base_combat => 1000; +use constant base_speed => 455; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => ['Colonization']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Uninhabited"; +with "Lacuna::Role::Ship::Send::SpendNextColonyCost"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::Colonize"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Detonator.pm b/lib/Lacuna/DB/Result/Fleet/Detonator.pm new file mode 100644 index 00000000..6e7cd68d --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Detonator.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::Detonator; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 1 } ]; +use constant base_food_cost => 6000; +use constant base_water_cost => 15600; +use constant base_energy_cost => 113600; +use constant base_ore_cost => 97200; +use constant base_time_cost => 86400; +use constant base_waste_cost => 25200; +use constant base_combat => 1850; +use constant base_speed => 1000; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::AsteroidStarUninhabited"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DestroyProbes"; +with "Lacuna::Role::Ship::Arrive::DestroyMinersExcavators"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Dory.pm b/lib/Lacuna/DB/Result/Fleet/Dory.pm new file mode 100644 index 00000000..c6419c74 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Dory.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::Dory; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 1 } ]; +use constant base_food_cost => 350; +use constant base_water_cost => 700; +use constant base_energy_cost => 3250; +use constant base_ore_cost => 5500; +use constant base_time_cost => 3800; +use constant base_waste_cost => 400; +use constant base_speed => 1250; +use constant base_stealth => 4100; +use constant base_hold_size => 400; +use constant base_berth_level => 1; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining Intelligence SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CaptureWithSpies"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; +with "Lacuna::Role::Ship::Arrive::PickUpSpies"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Drone.pm b/lib/Lacuna/DB/Result/Fleet/Drone.pm new file mode 100644 index 00000000..28069c9a --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Drone.pm @@ -0,0 +1,24 @@ +package Lacuna::DB::Result::Fleet::Drone; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Security', level => 1 } ]; +use constant base_food_cost => 250; +use constant base_water_cost => 650; +use constant base_energy_cost => 4050; +use constant base_ore_cost => 3550; +use constant base_time_cost => 3650; +use constant base_waste_cost => 1050; +use constant base_speed => 0; +use constant base_combat => 6000; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::NotAllowed"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Excavator.pm b/lib/Lacuna/DB/Result/Fleet/Excavator.pm new file mode 100644 index 00000000..2abf774e --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Excavator.pm @@ -0,0 +1,25 @@ +package Lacuna::DB::Result::Fleet::Excavator; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Archaeology', level => 11 } ]; +use constant base_food_cost => 3000; +use constant base_water_cost => 5000; +use constant base_energy_cost => 20000; +use constant base_ore_cost => 80000; +use constant base_time_cost => 8 * 60 * 60; +use constant base_waste_cost => 10000; +use constant base_speed => 1000; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant build_tags => ['Exploration']; + +with "Lacuna::Role::Ship::Send::AsteroidAndUninhabited"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DeployExcavator"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Fighter.pm b/lib/Lacuna/DB/Result/Fleet/Fighter.pm new file mode 100644 index 00000000..8f53cc36 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Fighter.pm @@ -0,0 +1,24 @@ +package Lacuna::DB::Result::Fleet::Fighter; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::PilotTraining', level => 1 } ]; +use constant base_food_cost => 1000; +use constant base_water_cost => 2600; +use constant base_energy_cost => 16200; +use constant base_ore_cost => 14200; +use constant base_time_cost => 60 * 60 * 4; +use constant base_waste_cost => 4200; +use constant base_combat => 4000; +use constant base_speed => 2000; +use constant pilotable => 1; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Body"; +with "Lacuna::Role::Ship::Arrive::Defend"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Freighter.pm b/lib/Lacuna/DB/Result/Fleet/Freighter.pm new file mode 100644 index 00000000..20ecde1a --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Freighter.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::Freighter; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 20 } ]; +use constant base_food_cost => 3600; +use constant base_water_cost => 10800; +use constant base_energy_cost => 36000; +use constant base_ore_cost => 61000; +use constant base_time_cost => 15000; +use constant base_waste_cost => 4800; +use constant base_speed => 900; +use constant base_stealth => 0; +use constant base_hold_size => 4000; +use constant base_berth_level => 15; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; + + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Galleon.pm b/lib/Lacuna/DB/Result/Fleet/Galleon.pm new file mode 100644 index 00000000..436b69cb --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Galleon.pm @@ -0,0 +1,26 @@ +package Lacuna::DB::Result::Fleet::Galleon; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 15 } ]; +use constant base_food_cost => 2500; +use constant base_water_cost => 7500; +use constant base_energy_cost => 25000; +use constant base_ore_cost => 40200; +use constant base_time_cost => 11200; +use constant base_waste_cost => 3200; +use constant base_speed => 1250; +use constant base_stealth => 0; +use constant base_hold_size => 1750; +use constant base_berth_level => 10; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/GasGiantSettlementPlatformShip.pm b/lib/Lacuna/DB/Result/Fleet/GasGiantSettlementPlatformShip.pm new file mode 100644 index 00000000..42e21e55 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/GasGiantSettlementPlatformShip.pm @@ -0,0 +1,26 @@ +package Lacuna::DB::Result::Fleet::GasGiantSettlementPlatformShip; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::GasGiantLab', level => 1 } ]; +use constant base_food_cost => 36000; +use constant base_water_cost => 90000; +use constant base_energy_cost => 340000; +use constant base_ore_cost => 250000; +use constant base_time_cost => 48000; +use constant base_waste_cost => 53000; +use constant base_speed => 500; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => ['Colonization']; + +with "Lacuna::Role::Ship::Send::GasGiant"; +with "Lacuna::Role::Ship::Arrive::AddGasGiantPlatform"; + + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Hulk.pm b/lib/Lacuna/DB/Result/Fleet/Hulk.pm new file mode 100644 index 00000000..017bdc88 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Hulk.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::Hulk; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 25 }]; +use constant base_food_cost => 7300; +use constant base_water_cost => 23000; +use constant base_energy_cost => 75000; +use constant base_ore_cost => 124000; +use constant base_time_cost => 20000; +use constant base_waste_cost => 11000; +use constant base_speed => 600; +use constant base_stealth => 0; +use constant base_hold_size => 7900; +use constant base_berth_level => 20; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; + + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/HulkFast.pm b/lib/Lacuna/DB/Result/Fleet/HulkFast.pm new file mode 100644 index 00000000..d08a8dee --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/HulkFast.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::HulkFast; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 25 }, + { class=> 'Lacuna::DB::Result::Building::Propulsion', level => 30 } ]; +use constant base_food_cost => 15000; +use constant base_water_cost => 30000; +use constant base_energy_cost => 500000; +use constant base_ore_cost => 1000000; +use constant base_time_cost => 43200; +use constant base_waste_cost => 100000; +use constant base_speed => 750; +use constant base_stealth => 0; +use constant base_hold_size => 10000; +use constant base_berth_level => 25; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; + + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/HulkHuge.pm b/lib/Lacuna/DB/Result/Fleet/HulkHuge.pm new file mode 100644 index 00000000..c57e6bea --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/HulkHuge.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::HulkHuge; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 30 } ]; +use constant base_food_cost => 90000; +use constant base_water_cost => 150000; +use constant base_energy_cost => 15000000; +use constant base_ore_cost => 10000000; +use constant base_time_cost => 256000; +use constant base_waste_cost => 1000000; +use constant base_speed => 350; +use constant base_stealth => 0; +use constant base_hold_size => 170100; +use constant base_berth_level => 30; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; + + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/MiningPlatformShip.pm b/lib/Lacuna/DB/Result/Fleet/MiningPlatformShip.pm new file mode 100644 index 00000000..c02f702f --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/MiningPlatformShip.pm @@ -0,0 +1,27 @@ +package Lacuna::DB::Result::Fleet::MiningPlatformShip; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Ore::Ministry', level => 1 }]; +use constant base_food_cost => 4800; +use constant base_water_cost => 14400; +use constant base_energy_cost => 96000; +use constant base_ore_cost => 81600; +use constant base_time_cost => 28800; +use constant base_waste_cost => 12000; +use constant base_combat => 600; +use constant base_speed => 600; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => ['Mining']; + +with "Lacuna::Role::Ship::Send::Asteroid"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DeployMiningPlatform"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/ObservatorySeeker.pm b/lib/Lacuna/DB/Result/Fleet/ObservatorySeeker.pm new file mode 100644 index 00000000..f516a4d2 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/ObservatorySeeker.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::ObservatorySeeker; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 10 }]; +use constant base_food_cost => 20000; +use constant base_water_cost => 50000; +use constant base_energy_cost => 170000; +use constant base_ore_cost => 200000; +use constant base_time_cost => 58500; +use constant base_waste_cost => 40000; +use constant base_speed => 1000; +use constant base_combat => 2500; +use constant base_stealth => 2700; +use constant target_building => ['Lacuna::DB::Result::Building::Observatory']; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DamageBuilding"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Placebo.pm b/lib/Lacuna/DB/Result/Fleet/Placebo.pm new file mode 100644 index 00000000..fd59e7bc --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Placebo.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::Placebo; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::CloakingLab', level => 5 }]; +use constant base_food_cost => 2000; +use constant base_water_cost => 2000; +use constant base_energy_cost => 4000; +use constant base_ore_cost => 4000; +use constant base_time_cost => 3600; +use constant base_waste_cost => 400; +use constant base_speed => 500; +use constant base_combat => 0; +use constant base_stealth => 2500; +use constant base_hold_size => 0; +use constant build_tags => [qw(War)]; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::Scuttle"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Placebo2.pm b/lib/Lacuna/DB/Result/Fleet/Placebo2.pm new file mode 100644 index 00000000..ef2a8ee3 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Placebo2.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Placebo2; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::CloakingLab', level => 10 }]; +use constant base_food_cost => 2000; +use constant base_water_cost => 2000; +use constant base_energy_cost => 5000; +use constant base_ore_cost => 5000; +use constant base_time_cost => 3600; +use constant base_waste_cost => 500; +use constant base_speed => 1000; +use constant base_combat => 0; +use constant base_stealth => 4000; +use constant base_hold_size => 0; +use constant build_tags => [qw(War)]; +use constant type_formatted => 'Placebo II'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::Scuttle"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Placebo3.pm b/lib/Lacuna/DB/Result/Fleet/Placebo3.pm new file mode 100644 index 00000000..ff95f603 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Placebo3.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Placebo3; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::CloakingLab', level => 15 }]; +use constant base_food_cost => 2000; +use constant base_water_cost => 2000; +use constant base_energy_cost => 6000; +use constant base_ore_cost => 6000; +use constant base_time_cost => 3600; +use constant base_waste_cost => 600; +use constant base_speed => 1500; +use constant base_combat => 0; +use constant base_stealth => 5500; +use constant base_hold_size => 0; +use constant build_tags => [qw(War)]; +use constant type_formatted => 'Placebo III'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::Scuttle"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Placebo4.pm b/lib/Lacuna/DB/Result/Fleet/Placebo4.pm new file mode 100644 index 00000000..32149049 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Placebo4.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Placebo4; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::CloakingLab', level => 20 }]; +use constant base_food_cost => 2000; +use constant base_water_cost => 2000; +use constant base_energy_cost => 7000; +use constant base_ore_cost => 7000; +use constant base_time_cost => 3600; +use constant base_waste_cost => 700; +use constant base_speed => 2000; +use constant base_combat => 0; +use constant base_stealth => 7000; +use constant base_hold_size => 0; +use constant build_tags => [qw(War)]; +use constant type_formatted => 'Placebo IV'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::Scuttle"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Placebo5.pm b/lib/Lacuna/DB/Result/Fleet/Placebo5.pm new file mode 100644 index 00000000..8e798b56 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Placebo5.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Placebo5; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::CloakingLab', level => 25 }]; +use constant base_food_cost => 2000; +use constant base_water_cost => 2000; +use constant base_energy_cost => 8000; +use constant base_ore_cost => 8000; +use constant base_time_cost => 3600; +use constant base_waste_cost => 800; +use constant base_speed => 2500; +use constant base_combat => 0; +use constant base_stealth => 8500; +use constant base_hold_size => 0; +use constant build_tags => [qw(War)]; +use constant type_formatted => 'Placebo V'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::Scuttle"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Placebo6.pm b/lib/Lacuna/DB/Result/Fleet/Placebo6.pm new file mode 100644 index 00000000..3d5e2fd6 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Placebo6.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Placebo6; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::CloakingLab', level => 30 }]; +use constant base_food_cost => 2000; +use constant base_water_cost => 2000; +use constant base_energy_cost => 9000; +use constant base_ore_cost => 9000; +use constant base_time_cost => 3600; +use constant base_waste_cost => 900; +use constant base_speed => 3000; +use constant base_combat => 0; +use constant base_stealth => 10000; +use constant base_hold_size => 0; +use constant build_tags => [qw(War)]; +use constant type_formatted => 'Placebo VI'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::Scuttle"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Probe.pm b/lib/Lacuna/DB/Result/Fleet/Probe.pm new file mode 100644 index 00000000..5dbffcd2 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Probe.pm @@ -0,0 +1,24 @@ +package Lacuna::DB::Result::Fleet::Probe; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::Observatory', level => 1 }]; +use constant base_food_cost => 100; +use constant base_water_cost => 300; +use constant base_energy_cost => 2000; +use constant base_ore_cost => 1700; +use constant base_time_cost => 3600; +use constant base_waste_cost => 500; +use constant base_speed => 5000; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant build_tags => [qw(Exploration Intelligence)]; + +with "Lacuna::Role::Ship::Send::Star"; +with "Lacuna::Role::Ship::Arrive::DeployProbe"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Scanner.pm b/lib/Lacuna/DB/Result/Fleet/Scanner.pm new file mode 100644 index 00000000..aa101d90 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Scanner.pm @@ -0,0 +1,27 @@ +package Lacuna::DB::Result::Fleet::Scanner; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::Intelligence', level => 5 }]; +use constant base_food_cost => 150; +use constant base_water_cost => 250; +use constant base_energy_cost => 2500; +use constant base_ore_cost => 2900; +use constant base_time_cost => 3600; +use constant base_waste_cost => 520; +use constant base_speed => 3000; +use constant base_combat => 200; +use constant base_stealth => 1850; +use constant base_hold_size => 0; +use constant build_tags => [qw(Exploration Intelligence)]; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::MaybeHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::ScanSurface"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Scow.pm b/lib/Lacuna/DB/Result/Fleet/Scow.pm new file mode 100644 index 00000000..d1a6a1ca --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Scow.pm @@ -0,0 +1,27 @@ +package Lacuna::DB::Result::Fleet::Scow; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Waste::Sequestration', level => 10 } ]; +use constant base_food_cost => 2000; +use constant base_water_cost => 5200; +use constant base_energy_cost => 32400; +use constant base_ore_cost => 28400; +use constant base_time_cost => 14600; +use constant base_waste_cost => 8400; +use constant base_speed => 420; +use constant base_combat => 500; +use constant base_stealth => 0; +use constant base_hold_size => 2000; +use constant build_tags => [qw(War WasteChain)]; + +with "Lacuna::Role::Ship::Send::PlanetAndStar"; +with "Lacuna::Role::Ship::Send::MaybeHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DumpWaste"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/ScowFast.pm b/lib/Lacuna/DB/Result/Fleet/ScowFast.pm new file mode 100644 index 00000000..8a2d8c78 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/ScowFast.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::ScowFast; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::Waste::Sequestration', level => 25 }, + { class=> 'Lacuna::DB::Result::Building::Propulsion', level => 25 } ]; +use constant base_food_cost => 3000; +use constant base_water_cost => 10000; +use constant base_energy_cost => 100000; +use constant base_ore_cost => 60000; +use constant base_time_cost => 21600; +use constant base_waste_cost => 25000; +use constant base_speed => 700; +use constant base_combat => 500; +use constant base_stealth => 0; +use constant base_hold_size => 2000; +use constant base_berth_level => 20; +use constant build_tags => [qw(War WasteChain)]; + +with "Lacuna::Role::Ship::Send::PlanetAndStar"; +with "Lacuna::Role::Ship::Send::MaybeHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DumpWaste"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/ScowLarge.pm b/lib/Lacuna/DB/Result/Fleet/ScowLarge.pm new file mode 100644 index 00000000..55bd8e5a --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/ScowLarge.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::ScowLarge; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Waste::Sequestration', level => 20 } ]; +use constant base_food_cost => 10000; +use constant base_water_cost => 32000; +use constant base_energy_cost => 170000; +use constant base_ore_cost => 120000; +use constant base_time_cost => 32000; +use constant base_waste_cost => 50000; +use constant base_speed => 325; +use constant base_combat => 600; +use constant base_stealth => 0; +use constant base_hold_size => 12000; +use constant base_berth_level => 15; +use constant build_tags => [qw(War WasteChain)]; + +with "Lacuna::Role::Ship::Send::PlanetAndStar"; +with "Lacuna::Role::Ship::Send::MaybeHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DumpWaste"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/ScowMega.pm b/lib/Lacuna/DB/Result/Fleet/ScowMega.pm new file mode 100644 index 00000000..84443cd2 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/ScowMega.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::ScowMega; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Waste::Sequestration', level => 30 } ]; +use constant base_food_cost => 60000; +use constant base_water_cost => 180000; +use constant base_energy_cost => 6000000; +use constant base_ore_cost => 1500000; +use constant base_time_cost => 98000; +use constant base_waste_cost => 25000000; +use constant base_speed => 100; +use constant base_combat => 0; +use constant base_stealth => 0; +use constant base_hold_size => 300000; +use constant base_berth_level => 25; +use constant build_tags => [qw(War WasteChain)]; + +with "Lacuna::Role::Ship::Send::PlanetAndStar"; +with "Lacuna::Role::Ship::Send::MaybeHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DumpWaste"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SecurityMinistrySeeker.pm b/lib/Lacuna/DB/Result/Fleet/SecurityMinistrySeeker.pm new file mode 100644 index 00000000..4b7d61fa --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SecurityMinistrySeeker.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::SecurityMinistrySeeker; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 20 } ]; +use constant base_food_cost => 20000; +use constant base_water_cost => 50000; +use constant base_energy_cost => 180000; +use constant base_ore_cost => 200000; +use constant base_time_cost => 58500; +use constant base_waste_cost => 40000; +use constant base_speed => 1000; +use constant base_combat => 3500; +use constant base_stealth => 2700; +use constant target_building => ['Lacuna::DB::Result::Building::Security','Lacuna::DB::Result::Building::Module::PoliceStation']; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DamageBuilding"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/ShortRangeColonyShip.pm b/lib/Lacuna/DB/Result/Fleet/ShortRangeColonyShip.pm new file mode 100644 index 00000000..70a3545f --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/ShortRangeColonyShip.pm @@ -0,0 +1,31 @@ +package Lacuna::DB::Result::Fleet::ShortRangeColonyShip; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Observatory', level => 3 } ]; +use constant base_food_cost => 15000; +use constant base_water_cost => 15000; +use constant base_energy_cost => 15000; +use constant base_ore_cost => 15000; +use constant base_time_cost => 60 * 60 * 8; +use constant base_waste_cost => 7000; +use constant base_combat => 1000; +use constant base_speed => 700; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => ['Colonization']; + +with "Lacuna::Role::Ship::Send::Range"; +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Uninhabited"; +with "Lacuna::Role::Ship::Send::SpendNextColonyCost"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::Colonize"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SmugglerShip.pm b/lib/Lacuna/DB/Result/Fleet/SmugglerShip.pm new file mode 100644 index 00000000..c1a85463 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SmugglerShip.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::SmugglerShip; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::CloakingLab', level => 1 } ]; +use constant base_food_cost => 1500; +use constant base_water_cost => 3900; +use constant base_energy_cost => 27000; +use constant base_ore_cost => 16800; +use constant base_time_cost => 28800; +use constant base_waste_cost => 1800; +use constant base_speed => 1700; +use constant base_stealth => 5000; +use constant base_hold_size => 520; +use constant base_berth_level => 10; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining Intelligence SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CaptureWithSpies"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; +with "Lacuna::Role::Ship::Arrive::PickUpSpies"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Snark.pm b/lib/Lacuna/DB/Result/Fleet/Snark.pm new file mode 100644 index 00000000..3fbf66ce --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Snark.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Snark; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 5 } ]; +use constant base_food_cost => 18000; +use constant base_water_cost => 46800; +use constant base_energy_cost => 145000; +use constant base_ore_cost => 195030; +use constant base_time_cost => 60 * 60 * 16; +use constant base_waste_cost => 39600; +use constant base_speed => 1000; +use constant base_stealth => 2400; +use constant base_combat => 2000; +use constant base_hold_size => 0; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DamageBuilding"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Snark2.pm b/lib/Lacuna/DB/Result/Fleet/Snark2.pm new file mode 100644 index 00000000..cd24da8a --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Snark2.pm @@ -0,0 +1,31 @@ +package Lacuna::DB::Result::Fleet::Snark2; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 18 } ]; +use constant base_food_cost => 37000; +use constant base_water_cost => 64600; +use constant base_energy_cost => 194000; +use constant base_ore_cost => 252230; +use constant base_time_cost => 58400; +use constant base_waste_cost => 59500; +use constant base_speed => 1000; +use constant base_stealth => 2600; +use constant base_combat => 4000; +use constant base_hold_size => 0; +use constant build_tags => ['War']; +use constant type_formatted => 'Snark II'; +use constant splash_radius => 1; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DamageBuilding"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Snark3.pm b/lib/Lacuna/DB/Result/Fleet/Snark3.pm new file mode 100644 index 00000000..62db2a19 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Snark3.pm @@ -0,0 +1,31 @@ +package Lacuna::DB::Result::Fleet::Snark3; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 25 } ]; +use constant base_food_cost => 47000; +use constant base_water_cost => 84600; +use constant base_energy_cost => 224000; +use constant base_ore_cost => 352230; +use constant base_time_cost => 58400; +use constant base_waste_cost => 69500; +use constant base_speed => 1000; +use constant base_stealth => 3000; +use constant base_combat => 5000; +use constant base_hold_size => 0; +use constant build_tags => ['War']; +use constant type_formatted => 'Snark III'; +use constant splash_radius => 2; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DamageBuilding"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SpacePortSeeker.pm b/lib/Lacuna/DB/Result/Fleet/SpacePortSeeker.pm new file mode 100644 index 00000000..0f53ee1b --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SpacePortSeeker.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::SpacePortSeeker; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 15 } ]; +use constant base_food_cost => 20000; +use constant base_water_cost => 50000; +use constant base_energy_cost => 160000; +use constant base_ore_cost => 200000; +use constant base_time_cost => 58500; +use constant base_waste_cost => 40000; +use constant base_speed => 1000; +use constant base_combat => 3000; +use constant base_stealth => 2700; +use constant target_building => ['Lacuna::DB::Result::Building::SpacePort']; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DamageBuilding"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SpaceStation.pm b/lib/Lacuna/DB/Result/Fleet/SpaceStation.pm new file mode 100644 index 00000000..fc809839 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SpaceStation.pm @@ -0,0 +1,31 @@ +package Lacuna::DB::Result::Fleet::SpaceStation; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Embassy', level => 20 } ]; +use constant base_food_cost => 8000000; +use constant base_water_cost => 8000000; +use constant base_energy_cost => 8000000; +use constant base_ore_cost => 8000000; +use constant base_time_cost => 60 * 60 * 72; +use constant base_waste_cost => 1000000; +use constant base_speed => 10; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => [qw(War Intelligence)]; +use constant type_formatted => 'Space Station Hull'; + +with "Lacuna::Role::Ship::Send::Planet"; +with 'Lacuna::Role::Ship::Send::Uninhabited'; +with 'Lacuna::Role::Ship::Send::MemberOfAlliance'; +with "Lacuna::Role::Ship::Send::SpendNextColonyCost"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::ConvertToStation"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SpyPod.pm b/lib/Lacuna/DB/Result/Fleet/SpyPod.pm new file mode 100644 index 00000000..474a2933 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SpyPod.pm @@ -0,0 +1,32 @@ +package Lacuna::DB::Result::Fleet::SpyPod; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Espionage', level => 1 } ]; +use constant base_food_cost => 200; +use constant base_water_cost => 600; +use constant base_energy_cost => 4000; +use constant base_ore_cost => 3400; +use constant base_time_cost => 3600; +use constant base_waste_cost => 1000; +use constant base_speed => 2000; +use constant base_stealth => 7000; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => ['Intelligence']; +use constant max_occupants => 1; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::LoadWithSpies"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::CaptureWithSpies"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; +with "Lacuna::Role::Ship::Arrive::Scuttle"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SpyShuttle.pm b/lib/Lacuna/DB/Result/Fleet/SpyShuttle.pm new file mode 100644 index 00000000..59b8bfa1 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SpyShuttle.pm @@ -0,0 +1,31 @@ +package Lacuna::DB::Result::Fleet::SpyShuttle; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Espionage', level => 15 } ]; +use constant base_food_cost => 750; +use constant base_water_cost => 2300; +use constant base_energy_cost => 15000; +use constant base_ore_cost => 13000; +use constant base_time_cost => 7200; +use constant base_waste_cost => 5000; +use constant base_speed => 2000; +use constant base_stealth => 6200; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => ['Intelligence']; +use constant max_occupants => 4; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::LoadWithSpies"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::CaptureWithSpies"; +with "Lacuna::Role::Ship::Arrive::Orbit"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Stake.pm b/lib/Lacuna/DB/Result/Fleet/Stake.pm new file mode 100644 index 00000000..90fa6759 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Stake.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Stake; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Observatory', level => 10 } ]; +use constant base_food_cost => 3000; +use constant base_water_cost => 4000; +use constant base_energy_cost => 10000; +use constant base_ore_cost => 10000; +use constant base_time_cost => 60 * 60 * 2; +use constant base_waste_cost => 3500; +use constant base_speed => 3000; +use constant base_combat => 250; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant pilotable => 0; +use constant build_tags => ['Colonization']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Uninhabited"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::StakeAClaim"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SupplyPod.pm b/lib/Lacuna/DB/Result/Fleet/SupplyPod.pm new file mode 100644 index 00000000..5ddd165e --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SupplyPod.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::SupplyPod; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::PlanetaryCommand', level => 10 } ]; +use constant base_food_cost => 1800; +use constant base_water_cost => 1900; +use constant base_energy_cost => 4500; +use constant base_ore_cost => 4500; +use constant base_time_cost => 60 * 60 * 2; +use constant base_waste_cost => 5000; +use constant base_speed => 1000; +use constant base_stealth => 0; +use constant base_hold_size => 400; +use constant pilotable => 0; +use constant build_tags => [qw(Colonization)]; +use constant supply_pod_level => 5; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::LoadSupplyPod"; +with "Lacuna::Role::Ship::Arrive::DeploySupplyPod"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SupplyPod2.pm b/lib/Lacuna/DB/Result/Fleet/SupplyPod2.pm new file mode 100644 index 00000000..36ff6d8b --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SupplyPod2.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::SupplyPod2; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::PlanetaryCommand', level => 15 } ]; +use constant base_food_cost => 29000; +use constant base_water_cost => 30000; +use constant base_energy_cost => 74000; +use constant base_ore_cost => 74000; +use constant base_time_cost => 60 * 60 * 4; +use constant base_waste_cost => 30000; +use constant base_speed => 1000; +use constant base_stealth => 0; +use constant base_hold_size => 900; +use constant pilotable => 0; +use constant build_tags => [qw(Colonization)]; +use constant supply_pod_level => 10; +use constant type_formatted => 'Supply Pod II'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::LoadSupplyPod"; +with "Lacuna::Role::Ship::Arrive::DeploySupplyPod"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SupplyPod3.pm b/lib/Lacuna/DB/Result/Fleet/SupplyPod3.pm new file mode 100644 index 00000000..c895ea91 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SupplyPod3.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::SupplyPod3; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::PlanetaryCommand', level => 20 } ]; +use constant base_food_cost => 480000; +use constant base_water_cost => 500000; +use constant base_energy_cost => 1200000; +use constant base_ore_cost => 1200000; +use constant base_time_cost => 60 * 60 * 6; +use constant base_waste_cost => 450000; +use constant base_speed => 1000; +use constant base_stealth => 0; +use constant base_hold_size => 2000; +use constant pilotable => 0; +use constant build_tags => [qw(Colonization)]; +use constant supply_pod_level => 15; +use constant type_formatted => 'Supply Pod III'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::LoadSupplyPod"; +with "Lacuna::Role::Ship::Arrive::DeploySupplyPod"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SupplyPod4.pm b/lib/Lacuna/DB/Result/Fleet/SupplyPod4.pm new file mode 100644 index 00000000..5d0ef75a --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SupplyPod4.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::SupplyPod4; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::PlanetaryCommand', level => 25 } ]; +use constant base_food_cost => 8000000; +use constant base_water_cost => 8500000; +use constant base_energy_cost => 20000000; +use constant base_ore_cost => 20000000; +use constant base_time_cost => 60 * 60 * 8; +use constant base_waste_cost => 2000000; +use constant base_speed => 1000; +use constant base_stealth => 0; +use constant base_hold_size => 3800; +use constant pilotable => 0; +use constant build_tags => [qw(Colonization)]; +use constant supply_pod_level => 20; +use constant type_formatted => 'Supply Pod IV'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::LoadSupplyPod"; +with "Lacuna::Role::Ship::Arrive::DeploySupplyPod"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Surveyor.pm b/lib/Lacuna/DB/Result/Fleet/Surveyor.pm new file mode 100644 index 00000000..838f2b58 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Surveyor.pm @@ -0,0 +1,27 @@ +package Lacuna::DB::Result::Fleet::Surveyor; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Intelligence', level => 10 } ]; +use constant base_food_cost => 1500; +use constant base_water_cost => 2500; +use constant base_energy_cost => 25000; +use constant base_ore_cost => 29000; +use constant base_time_cost => 60 * 60 * 6; +use constant base_waste_cost => 5200; +use constant base_speed => 3000; +use constant base_combat => 1000; +use constant base_stealth => 3000; +use constant base_hold_size => 0; +use constant build_tags => [qw(Exploration Intelligence)]; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::MaybeHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::SurveySurface"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Sweeper.pm b/lib/Lacuna/DB/Result/Fleet/Sweeper.pm new file mode 100644 index 00000000..97329ed1 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Sweeper.pm @@ -0,0 +1,27 @@ +package Lacuna::DB::Result::Fleet::Sweeper; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 16 } ]; +use constant base_food_cost => 5000; +use constant base_water_cost => 12000; +use constant base_energy_cost => 70000; +use constant base_ore_cost => 75000; +use constant base_time_cost => 60 * 60 * 7; +use constant base_waste_cost => 20000; +use constant base_combat => 8100; +use constant base_speed => 2600; +use constant base_stealth => 2800; +use constant pilotable => 1; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Body"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/TerraformingPlatformShip.pm b/lib/Lacuna/DB/Result/Fleet/TerraformingPlatformShip.pm new file mode 100644 index 00000000..de1d8faa --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/TerraformingPlatformShip.pm @@ -0,0 +1,25 @@ +package Lacuna::DB::Result::Fleet::TerraformingPlatformShip; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::TerraformingLab', level => 1 } ]; +use constant base_food_cost => 96000; +use constant base_water_cost => 180000; +use constant base_energy_cost => 310000; +use constant base_ore_cost => 226000; +use constant base_time_cost => 45000; +use constant base_waste_cost => 45000; +use constant base_speed => 550; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => ['Colonization']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Arrive::AddTerraformingPlatform"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Thud.pm b/lib/Lacuna/DB/Result/Fleet/Thud.pm new file mode 100644 index 00000000..5949b0dc --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Thud.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Thud; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 3 } ]; +use constant base_food_cost => 7000; +use constant base_water_cost => 8000; +use constant base_energy_cost => 23000; +use constant base_ore_cost => 45000; +use constant base_time_cost => 60 * 60 * 2; +use constant base_waste_cost => 8400; +use constant base_speed => 700; +use constant base_stealth => 1600; +use constant base_combat => 2100; +use constant base_hold_size => 0; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DeploySmolderingCrater"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); -- 2.51.2 From 011519e507ba52dd98d6c29ce3a8da578f14bb16 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 3 Jun 2012 15:20:58 -0400 Subject: [PATCH 061/105] Weaken building_cache so as to prevent memory leak --- lib/Lacuna/DB/Result/Map/Body.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index 2b58fe4b..a8a87382 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -3,6 +3,7 @@ package Lacuna::DB::Result::Map::Body; use Moose; use utf8; use List::Util qw(max reduce); +use Scalar::Util qw(weaken); no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Map'; @@ -224,6 +225,7 @@ __PACKAGE__->has_many('foreign_ships','Lacuna::DB::Result::Ships','foreign_body_ has building_cache => ( is => 'rw', lazy => 1, + weak_ref => 1, builder => '_build_building_cache', clearer => 'clear_building_cache', ); @@ -231,7 +233,12 @@ has building_cache => ( sub _build_building_cache { my ($self) = @_; - my @buildings = $self->_buildings; + my @buildings_cache = $self->_buildings; + my @buildings; + for my $building (@buildings_cache) { + push @buildings, weaken($building); + } + return \@buildings; } -- 2.51.2 From 1e29691c5cadf247b6aeb317dd933d23b9951f78 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 3 Jun 2012 15:24:36 -0400 Subject: [PATCH 062/105] Test to check for memory leak --- t/450_memory_leak.t | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 t/450_memory_leak.t diff --git a/t/450_memory_leak.t b/t/450_memory_leak.t new file mode 100644 index 00000000..8af41ea7 --- /dev/null +++ b/t/450_memory_leak.t @@ -0,0 +1,32 @@ +use lib '../lib'; + +use strict; +use warnings; + +use Test::More tests => 3; +use Test::Deep; +use Test::Memory::Cycle; +use Data::Dumper; +use 5.010; +use DateTime; + +use TestHelper; +my $tester = TestHelper->new->use_existing_test_empire; +my $session_id = $tester->session->id; +my $empire = $tester->empire; +my $home = $empire->home_planet; + +memory_cycle_ok($home, "home has no memory cycles"); + +my $cache = $home->building_cache; + +memory_cycle_ok($home, "no memory cycles after reading cache"); + +$home->tick; + +memory_cycle_ok($home, "home has no memory cycles after tick"); + + +END { +# TestHelper->clear_all_test_empires; +} -- 2.51.2 From 96830ced7f6040c81d1b31d75ce62c389f73e7bd Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 3 Jun 2012 15:32:52 -0400 Subject: [PATCH 063/105] Refactor tick_planets.pl to be more efficient memory wise --- bin/tick_planets.pl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bin/tick_planets.pl b/bin/tick_planets.pl index 71a7659f..4f61a3a2 100644 --- a/bin/tick_planets.pl +++ b/bin/tick_planets.pl @@ -19,10 +19,9 @@ out('Loading DB'); our $db = Lacuna->db; out('Ticking planets'); -my $planets_rs = $db->resultset('Lacuna::DB::Result::Map::Body'); -my @planets = $planets_rs->search({ empire_id => {'>' => 0} })->get_column('id')->all; -foreach my $id (@planets) { - my $planet = $planets_rs->find($id); +my $planets_rs = $db->resultset('Lacuna::DB::Result::Map::Body')->search({empire_id => {'!=' => 0}}); +while (my $planet = $planets_rs->next) { + out('Ticking '.$planet->name); eval{$planet->tick}; my $reason = $@; if (ref $reason eq 'ARRAY' && $reason->[0] eq -1) { -- 2.51.2 From 6560ed198eb70f05f361437c2c3df17d2b14d262 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 3 Jun 2012 18:56:57 -0400 Subject: [PATCH 064/105] Remove weaken until we can sort out PT issues --- lib/Lacuna/DB/Result/Map/Body.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index a8a87382..0d95d15c 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -225,7 +225,7 @@ __PACKAGE__->has_many('foreign_ships','Lacuna::DB::Result::Ships','foreign_body_ has building_cache => ( is => 'rw', lazy => 1, - weak_ref => 1, +# weak_ref => 1, builder => '_build_building_cache', clearer => 'clear_building_cache', ); @@ -236,7 +236,8 @@ sub _build_building_cache { my @buildings_cache = $self->_buildings; my @buildings; for my $building (@buildings_cache) { - push @buildings, weaken($building); +# push @buildings, weaken($building); + push @buildings, $building; } return \@buildings; -- 2.51.2 From 468e2a23e1882d07bbf8d1c15597ae478b0fb019 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 4 Jun 2012 00:44:57 -0600 Subject: [PATCH 065/105] Autoreplacement of Excavators and bug fix on chances. --- lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Building/Archaeology.pm | 81 ++++++++++++++++---- lib/Lacuna/DB/Result/Empire.pm | 2 + lib/Lacuna/RPC/Empire.pm | 14 ++++ var/upgrades/3.0853.sql | 2 + var/www/public/changes.txt | 4 + 6 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 var/upgrades/3.0853.sql diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index ae501422..f6d62717 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0852; +our $VERSION = 3.0853; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1}); diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 4bb50452..9fdf9c1c 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -89,6 +89,7 @@ sub run_excavators { while (my $excav = $excavators->next) { my $body = $excav->body; my $result; + my $new_colony = 0; if ($body->empire_id) { # Clean off the excav if planet gets settled. $result = { @@ -98,6 +99,7 @@ sub run_excavators { message => sprintf "Dig wiped out by new Colony from %s.", $body->empire->name, }; + $new_colony = 1; } else { $result = $self->dig_it($body, $level, 0); @@ -106,17 +108,23 @@ sub run_excavators { push @{$results}, $result; if ($result->{outcome} eq "Destroyed") { $self->remove_excavator($excav); +# If not a result from colony, send replacement excav if option is chosen. + unless ($new_colony or $empire->dont_replace_excavator) { + my $replacement = $self->replace_excav($body); + push @{$results}, $replacement; + } } } } my $report; for $result (sort { $a->{site} cmp $b->{site} } @{$results}) { - next if ($empire->skip_found_nothing and $result->{outcome} eq "Nothing"); - next if ($empire->skip_excavator_artifact and $result->{outcome} eq "Artifact"); - next if ($empire->skip_excavator_resources and $result->{outcome} eq "Resource"); - next if ($empire->skip_excavator_plan and $result->{outcome} eq "Plan"); - next if ($empire->skip_excavator_glyph and $result->{outcome} eq "Glyph"); - next if ($empire->skip_excavator_destroyed and $result->{outcome} eq "Destroyed"); + next if ($empire->skip_found_nothing and $result->{outcome} eq "Nothing"); + next if ($empire->skip_excavator_artifact and $result->{outcome} eq "Artifact"); + next if ($empire->skip_excavator_resources and $result->{outcome} eq "Resource"); + next if ($empire->skip_excavator_plan and $result->{outcome} eq "Plan"); + next if ($empire->skip_excavator_glyph and $result->{outcome} eq "Glyph"); + next if ($empire->skip_excavator_destroyed and $result->{outcome} eq "Destroyed"); + next if ($empire->skip_excavator_replace_msg and $result->{outcome} eq "Replace"); push @{$report}, [ $result->{site}, $result->{outcome}, @@ -135,6 +143,44 @@ sub run_excavators { return 1; } +sub replace_excav { + my ($self, $body) = @_; + + my $replace_msg = { + id => -1, + site => $body->name, + outcome => "Replace", + }; +# Check to see if excavs available + my $avail = Lacuna->db->resultset('Lacuna::DB::Result::Ships') + ->search({type=>'excavator', task=>'Docked',body_id=>$self->body_id}); + if ($avail) { + my $count = $avail->count; + my $ship = $avail->next; # Just grab first one + eval { $ship->can_send_to_target($body) }; + my $reason = $@; + if ($reason) { + if (ref $reason ne 'ARRAY') { + $reason = join(":", @{$reason}); + } + $replace_msg->{message} = sprintf("Fail : Could not send excavator: %s", $reason); + } + else { + if (eval{$ship->send(target => $body)}) { + $count--; + $replace_msg->{message} = sprintf("Success : Excavator launched. %d left.", $count); + } + else { + $replace_msg->{message} = "Fail : Target Failure"; + } + } + } + else { + $replace_msg->{message} = "Fail : No excavators to send"; + } + return $replace_msg; +} + sub dig_it { my ($self, $body, $level, $arch) = @_; @@ -200,7 +246,8 @@ sub dig_it { } } when ("destroy") { - if (randint(0,99) < 3) { +# Most destruction choices result in nothing found. + if (randint(0,99) < 5) { my $message = random_element([ 'Auntie Em, where\'s Toto? Its a twister! Its a twister!', 'Aw, there\'s something behind me, isn\'t there?', @@ -302,32 +349,32 @@ sub found_artifact { } return (0,0,"Nothing") unless (defined($artifacts)); my $select = random_element($artifacts); - my $class; my $lvl; my $plus; my $name; my $destroy; + my $class; my $lvl; my $plus; my $name; my $bld_destroy; if ($level > $select->level and randint(1, int(3 * $level/2)) >= $select->level) { $class = $select->class; $lvl = 1; $plus = int( ($select->level - 1) * 2/3); #Max doable would be 1+18 $name = $select->name; - $destroy = 100; + $bld_destroy = 100; } elsif (randint(1,2) == 1) { $class = $select->class; $lvl = 1; $plus = 0; $name = $select->name; - $destroy = 10; + $bld_destroy = 10; } else { $class = $select->class; $lvl = randint(1,$select->level); # Slight chance of getting a level 30 plan. $plus = 0; $name = $select->name; - $destroy = 25; + $bld_destroy = 25; } $lvl = 30 if ($lvl > 30); $plus = 30 if ($plus > 30); $self->body->add_plan($class, $lvl, $plus); - if ($select->level == 1 or randint(0,99) < $destroy) { + if ($select->level == 1 or randint(0,99) < $bld_destroy) { $select->delete; } else { @@ -367,7 +414,7 @@ sub can_you_dig_it { my ($self, $body, $level, $arch) = @_; my $mult = $arch + 1; - my $plan = int($level/4 + 1) * $mult; + my $plan = int($level/4 + 1); my $ore_total = 0; for my $ore (ORE_TYPES) { $ore_total += $body->$ore; @@ -376,13 +423,13 @@ sub can_you_dig_it { my $glyph = int($mult * $level * $ore_total/20_000)+1; my $resource = int(5/2 * $level); my $artifact = 0; - if (!$arch && $body->building_cache) { - $artifact = 14; + if (!$arch && (scalar @{$body->building_cache})) { + $artifact = 15; } - my $destroy = $arch ? 0 : 1; + my $destroy = $arch ? 0 : 5; $destroy += $artifact; my $most = $plan + $glyph + $artifact + $destroy; -# resources get cut down if over 100% +# resource chance gets cut down if over 100% if ($most + $resource > 100) { $resource -= ($most + $resource - 100); } diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index de3255a5..8a4547c1 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -80,6 +80,8 @@ __PACKAGE__->add_columns( skip_attack_messages => { data_type => 'tinyint', default_value => 0 }, skip_excavator_artifact => { data_type => 'tinyint', default_value => 0 }, skip_excavator_destroyed => { data_type => 'tinyint', default_value => 0 }, + skip_excavator_replace_msg => { data_type => 'tinyint', default_value => 0 }, + dont_replace_excavator => { data_type => 'tinyint', default_value => 0 }, has_new_messages => { data_type => 'tinyint', default_value => 0 }, latest_message_id => { data_type => 'int', is_nullable => 1 }, skip_incoming_ships => { data_type => 'tinyint', default_value => 0 }, diff --git a/lib/Lacuna/RPC/Empire.pm b/lib/Lacuna/RPC/Empire.pm index a227cd1a..67ad42b9 100644 --- a/lib/Lacuna/RPC/Empire.pm +++ b/lib/Lacuna/RPC/Empire.pm @@ -405,6 +405,8 @@ sub view_profile { skip_excavator_plan => $empire->skip_excavator_plan, skip_excavator_artifact => $empire->skip_excavator_artifact, skip_excavator_destroyed => $empire->skip_excavator_destroyed, + skip_excavator_replace_msg => $empire->skip_excavator_replace_msg, + dont_replace_excavator => $empire->dont_replace_excavator, skip_spy_recovery => $empire->skip_spy_recovery, skip_probe_detected => $empire->skip_probe_detected, skip_attack_messages => $empire->skip_attack_messages, @@ -511,6 +513,12 @@ sub edit_profile { } $empire->skip_found_nothing($profile->{skip_found_nothing}); } + if (exists $profile->{skip_excavator_replace_msg}) { + if ($profile->{skip_excavator_replace_msg} < 0 || $profile->{skip_excavator_replace_msg} > 1) { + confess [1009, 'Skip Excavator Replacement Message must be a 1 or a 0.', 'skip_excavator_replace_msg'] + } + $empire->skip_excavator_resources($profile->{skip_excavator_replace_msg}); + } if (exists $profile->{skip_excavator_resources}) { if ($profile->{skip_excavator_resources} < 0 || $profile->{skip_excavator_resources} > 1) { confess [1009, 'Skip Excavator Resources must be a 1 or a 0.', 'skip_excavator_resources'] @@ -541,6 +549,12 @@ sub edit_profile { } $empire->skip_excavator_destroyed($profile->{skip_excavator_destroyed}); } + if (exists $profile->{dont_replace_excavator}) { + if ($profile->{dont_replace_excavator} < 0 || $profile->{dont_replace_excavator} > 1) { + confess [1009, 'Do not replace excavator must be a 1 or a 0.', 'dont_replace_excavator'] + } + $empire->skip_excavator_resources($profile->{dont_replace_excavator}); + } if (exists $profile->{skip_spy_recovery}) { if ($profile->{skip_spy_recovery} < 0 || $profile->{skip_spy_recovery} > 1) { confess [1009, 'Skip Spy Recovery must be a 1 or a 0.', 'skip_spy_recovery'] diff --git a/var/upgrades/3.0853.sql b/var/upgrades/3.0853.sql new file mode 100644 index 00000000..ee2e16d4 --- /dev/null +++ b/var/upgrades/3.0853.sql @@ -0,0 +1,2 @@ +alter table empire add column `dont_replace_excavator` tinyint NOT NULL default 0; +alter table empire add column `skip_excavator_replace_msg` tinyint NOT NULL default 0; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index b79ee7b1..dfcb15b4 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,7 @@ +3.0853: + - Mod: Excavator destruction will trigger a replacement excavator to be sent if available. + - Add: Options in UI for excavator replacement. + 3.0852: - Mod: Efficiency modifications. - Mod: Various bug fixes. -- 2.51.2 From 43cb4637be4616ec42c5ea05085586c91fc7ec8b Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 4 Jun 2012 01:12:16 -0600 Subject: [PATCH 066/105] On founding colony, make sure body has stats calculated. --- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 6603db29..a11f764a 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -834,6 +834,7 @@ sub found_colony { } # add starting resources + $self->needs_recalc(1); $self->tick; $self->add_algae(700); $self->add_energy(700); -- 2.51.2 From a7b73ec9698465dec9373a9b6bcb5f5b0be314d1 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 4 Jun 2012 09:53:11 -0600 Subject: [PATCH 067/105] Think of the children! --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 2 +- var/www/public/changes.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 9fdf9c1c..11c1b80d 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -262,7 +262,7 @@ sub dig_it { 'It\'s dead Jim.', 'It\'s just a harmless little bunny...', 'It\'s full of stars.', - 'Looks like I picked the wrong week to stop sniffing glue.', + 'Looks like I picked the wrong week to stop drinking coffee.', 'Klaatu Barada Ni*cough*', 'Oh no, not again.', 'Oops? What oops? No oops!', diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index dfcb15b4..ee86dadc 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,6 +1,6 @@ 3.0853: - Mod: Excavator destruction will trigger a replacement excavator to be sent if available. - - Add: Options in UI for excavator replacement. + - Add: Hooks for UI for excavator replacement added. (UI being updated soon.) 3.0852: - Mod: Efficiency modifications. -- 2.51.2 From e73b9d1b093af96a8a0e76f3c00a8b6d822a24f1 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 4 Jun 2012 13:01:52 -0600 Subject: [PATCH 068/105] no biscuit. --- lib/Lacuna/RPC/Empire.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/RPC/Empire.pm b/lib/Lacuna/RPC/Empire.pm index 67ad42b9..4c73053a 100644 --- a/lib/Lacuna/RPC/Empire.pm +++ b/lib/Lacuna/RPC/Empire.pm @@ -517,7 +517,7 @@ sub edit_profile { if ($profile->{skip_excavator_replace_msg} < 0 || $profile->{skip_excavator_replace_msg} > 1) { confess [1009, 'Skip Excavator Replacement Message must be a 1 or a 0.', 'skip_excavator_replace_msg'] } - $empire->skip_excavator_resources($profile->{skip_excavator_replace_msg}); + $empire->skip_excavator_replace_msg($profile->{skip_excavator_replace_msg}); } if (exists $profile->{skip_excavator_resources}) { if ($profile->{skip_excavator_resources} < 0 || $profile->{skip_excavator_resources} > 1) { @@ -553,7 +553,7 @@ sub edit_profile { if ($profile->{dont_replace_excavator} < 0 || $profile->{dont_replace_excavator} > 1) { confess [1009, 'Do not replace excavator must be a 1 or a 0.', 'dont_replace_excavator'] } - $empire->skip_excavator_resources($profile->{dont_replace_excavator}); + $empire->dont_replace_excavator($profile->{dont_replace_excavator}); } if (exists $profile->{skip_spy_recovery}) { if ($profile->{skip_spy_recovery} < 0 || $profile->{skip_spy_recovery} > 1) { -- 2.51.2 From 751a2f56fa24da98d97ad6a5ed0b6738643249b2 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 4 Jun 2012 23:13:51 -0600 Subject: [PATCH 069/105] Embarassing use of ne when eq should of been used --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 11c1b80d..8a56d25b 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -160,7 +160,7 @@ sub replace_excav { eval { $ship->can_send_to_target($body) }; my $reason = $@; if ($reason) { - if (ref $reason ne 'ARRAY') { + if (ref $reason eq 'ARRAY') { $reason = join(":", @{$reason}); } $replace_msg->{message} = sprintf("Fail : Could not send excavator: %s", $reason); -- 2.51.2 From b5d4e0c97254a2372f72ade5ddb98f799bdc7901 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Tue, 5 Jun 2012 04:55:58 -0400 Subject: [PATCH 070/105] Remove circular dependency that causes memory leak --- lib/Lacuna/DB/Result/Map/Body.pm | 5 +++-- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index a8a87382..0d95d15c 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -225,7 +225,7 @@ __PACKAGE__->has_many('foreign_ships','Lacuna::DB::Result::Ships','foreign_body_ has building_cache => ( is => 'rw', lazy => 1, - weak_ref => 1, +# weak_ref => 1, builder => '_build_building_cache', clearer => 'clear_building_cache', ); @@ -236,7 +236,8 @@ sub _build_building_cache { my @buildings_cache = $self->_buildings; my @buildings; for my $building (@buildings_cache) { - push @buildings, weaken($building); +# push @buildings, weaken($building); + push @buildings, $building; } return \@buildings; diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 6603db29..b700f367 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -481,7 +481,7 @@ has command => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::PlanetaryCommand'); return undef unless defined $building; - $building->body($self); + #$building->body($self); return $building; }, ); @@ -493,7 +493,7 @@ has oversight => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Oversight'); return undef unless defined $building; - $building->body($self); + #$building->body($self); return $building; }, ); @@ -505,7 +505,7 @@ has archaeology => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Archaeology'); return undef unless defined $building; - $building->body($self); +# #$building->body($self); return $building; }, ); @@ -517,7 +517,7 @@ has mining_ministry => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Ore::Ministry'); return undef unless defined $building; - $building->body($self); + #$building->body($self); return $building; }, ); @@ -529,7 +529,7 @@ has network19 => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Network19'); return undef unless defined $building; - $building->body($self); + #$building->body($self); return $building; }, ); @@ -541,7 +541,7 @@ has development => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Development'); return undef unless defined $building; - $building->body($self); + #$building->body($self); return $building; }, ); @@ -553,7 +553,7 @@ has refinery => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Ore::Refinery'); return undef unless defined $building; - $building->body($self); + #$building->body($self); return $building; }, ); @@ -565,7 +565,7 @@ has spaceport => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::SpacePort'); return undef unless defined $building; - $building->body($self); + #$building->body($self); return $building; }, ); @@ -577,7 +577,7 @@ has embassy => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Embassy'); return undef unless defined $building; - $building->body($self); + #$building->body($self); return $building; }, ); @@ -794,7 +794,7 @@ sub build_building { $building->body_id($self->id); $building->level(0) unless $building->level; $building->insert; - $building->body($self); + #$building->body($self); $building->start_upgrade(undef, $in_parallel); $self->building_cache([@{$self->building_cache}, $building]); } -- 2.51.2 From 58b9c13855e70bb89b68195529c7023e9074ae7d Mon Sep 17 00:00:00 2001 From: ian docherty Date: Tue, 5 Jun 2012 09:45:40 -0400 Subject: [PATCH 071/105] Fixed a few issues with hourly tasks --- bin/run_daily.sh | 6 ++---- bin/summarize_server.pl | 2 +- lib/Lacuna/DB/Result/Map/Body.pm | 10 +++++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bin/run_daily.sh b/bin/run_daily.sh index 18c11e78..53ecd872 100755 --- a/bin/run_daily.sh +++ b/bin/run_daily.sh @@ -5,8 +5,6 @@ perl trickle_essentia_veins.pl perl determine_lottery_winner.pl perl alert_inactive_users.pl perl rotate_taxes_paid.pl -perl diablotin/send_attack.pl --randomize& +perl diablotin/send_attack.pl& +perl saben/send_attack.pl& perl clean_up_mail.pl -#perl saben/send_attack.pl --randomize& -#perl trelvestian/check_for_total_victory.pl - diff --git a/bin/summarize_server.pl b/bin/summarize_server.pl index 8fe9735d..0406dfc3 100644 --- a/bin/summarize_server.pl +++ b/bin/summarize_server.pl @@ -434,7 +434,7 @@ sub summarize_colonies { my %colony_data = ( date_stamp => DateTime->now, planet_name => $planet->name, - building_count => @{ $planet->building_cache }, + building_count => scalar @{ $planet->building_cache }, population => $planet->population, population_delta => (defined $log ? $log->population_delta + $planet->population - $log->population : $planet->population ), average_building_level => $planet->building_avg_level, diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index 0d95d15c..9a39154e 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -2,7 +2,7 @@ package Lacuna::DB::Result::Map::Body; use Moose; use utf8; -use List::Util qw(max reduce); +use List::Util qw(max sum); use Scalar::Util qw(weaken); no warnings qw(uninitialized); @@ -246,14 +246,18 @@ sub _build_building_cache { sub building_max_level { my ($self) = @_; - return reduce {$a->level > $b->level ? $a->level : $b->level} 0, @{$self->building_cache} + if (scalar @{$self->building_cache}) { + return max map {$_->level} @{$self->building_cache}; + } + return 0; } sub building_avg_level { my ($self) = @_; if (scalar @{$self->building_cache}) { - return (reduce {$a->level + $b->level} 0, @{$self->building_cache} ) / @{$self->building_cache}; + my $sum = sum map {$_->level} @{$self->building_cache}; + return $sum / @{$self->building_cache}; } return 0; } -- 2.51.2 From cc38529d81c7a1751d69e0801a69250469730d9b Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 13 May 2012 05:19:39 -0400 Subject: [PATCH 072/105] Started adding new fleet action API calls --- docs/SpacePort.pod | 289 +++++++++++++++++++++------ lib/Lacuna/DB/Result/Ships.pm | 20 +- lib/Lacuna/RPC/Building/SpacePort.pm | 167 +++++++++++++++- t/440_fleets.t | 32 +++ 4 files changed, 440 insertions(+), 68 deletions(-) create mode 100644 t/440_fleets.t diff --git a/docs/SpacePort.pod b/docs/SpacePort.pod index a6ff0737..28d8d061 100644 --- a/docs/SpacePort.pod +++ b/docs/SpacePort.pod @@ -61,8 +61,8 @@ Shows you all your ships whatever they are doing. "name" : "Mars" } }, - { - "id" : "id-goes-here", + { + "id" : "id-goes-here", "name" : "F13", "type_human" : "Fighter", "type" : "fighter", @@ -85,11 +85,11 @@ Shows you all your ships whatever they are doing. "id" : "id-goes-here", "type" : "body", "name" : "Mars", - "x" : 4, - "y" : -3 + "x" : 4, + "y" : -3 } - }, + }, ... ], "number_of_ships" : 13, @@ -206,7 +206,87 @@ The unique id of the space port. Defaults to page 1. Shows 25 at a time. +=head2 get_fleet_for ( session_id, from_body_id, target ) + +Provides a summary of ships that can be included in a fleet action + + { + "ships" : [ + { + "type" : "sweeper", + "type_human" : "Sweeper", + "speed" : 10166, + "stealth" : 10948, + "combat" : 33372, + "quantity" : 103, + "estimated_travel_time" : "3654", + }, + { + "type" : "sweeper", + "type_human" : "Sweeper", + "speed" : 10166, + "stealth" : 10948, + "combat" : 25000, + "quantity" : 26, + "estimated_travel_time" : "3745", + }, + { + "type" : "surveyor", + "type_human" : "Surveyor", + "speed" : 9030, + "stealth" : 9030, + "combat" : 3220, + "quantity" : 24, + "estimated_travel_time" : "4123", + } + ... + ], + "status" : { ... } + } + +Ships are grouped according to type,speed,stealth and combat, the number of ships in each group is given. + +=head3 session_id + +A session id. + +=head3 from_body_id + +The unique id of the planet that should send the ships. + +=head3 target + +A hash reference that can contain one of five items to identify a star or body. + + { "body_name" : "Earth" } + + { "body_id" : "id-goes-here" } + + { "star_name" : "Sol" } + + { "star_id" : "id-goes-here" } + + { "x" : 4, "y" : -3 } + +=head4 body_name + +A string with the body's name. Case insensitive, but will throw an exception for misspelling. + +=head4 body_id +The unique id of the body. + +=head4 star_name + +A string with the star's name. Case insensitive, but will throw an exception for misspelling. + +=head4 star_id + +The unique id of the star. + +=head4 x | y + +A set of x,y coordinates to locate the star or body. =head2 get_ships_for ( session_id, from_body_id, target ) @@ -258,27 +338,27 @@ Provides a list of incoming ships and ships that are available to send to a spec ... ], "unavailable" : [ - { + { "reason" : [1009, "You can't send a detonator to a star."], - "ship" : { - "id" : "id-goes-here", - "name" : "D13", - "type_human" : "Detonator", - "type" : "detonator", - "task" : "Docked", - "speed" : "700", + "ship" : { + "id" : "id-goes-here", + "name" : "D13", + "type_human" : "Detonator", + "type" : "detonator", + "task" : "Docked", + "speed" : "700", "fleet_speed" : "0", - "stealth" : "0", - "hold_size" : "0", - "date_started" : "01 31 2010 13:09:05 +0600", - "date_available" : "01 31 2010 13:09:05 +0600" + "stealth" : "0", + "hold_size" : "0", + "date_started" : "01 31 2010 13:09:05 +0600", + "date_available" : "01 31 2010 13:09:05 +0600" } }, ... ], - "orbiting" : [ - { - "id" : "id-goes-here", + "orbiting" : [ + { + "id" : "id-goes-here", "name" : "F13", "type_human" : "Fighter", "type" : "fighter", @@ -299,13 +379,13 @@ Provides a list of incoming ships and ships that are available to send to a spec "id" : "id-goes-here", "type" : "body", "name" : "Mars", - "x" : 4, - "y" : -3, + "x" : 4, + "y" : -3, } - }, - ... - ], + }, + ... + ], "mining_platforms" : [ { empire_id => "id-goes-here", @@ -362,7 +442,6 @@ The unique id of the star. A set of x,y coordinates to locate the star or body. - =head2 send_ship ( session_id, ship_id, target ) Sends a ship to a specified body or star. Use with C. @@ -440,44 +519,138 @@ The unique id of the star. A set of x,y coordinates to locate the star or body. +=head2 send_ship_types ( session_id, from_body_id, target, types, arrival ) + +Sends a quantity of ships, of a specific type (type, speed, combat, stealth) to a target. + +Look at B for a summary of what ships can be sent. + +Returns the same as B showing how many ships are remaining to be sent. + +Throws 1002,1009,1010,1019 + +=head4 session_id + +A session ID. + +=head4 from_body_id + +The Unique ID of the body that should send the ships + +=head4 target + +A hash reference that can contain one of five items to identify a star or body. + + { "body_name" : "Earth" } + + { "body_id" : "id-goes-here" } + + { "star_name" : "Sol" } + + { "star_id" : "id-goes-here" } + + { "x" : 4, "y" : -3 } + +=head4 body_name + +A string with the body's name. Case insensitive, but will throw an exception for misspelling. + +=head4 body_id + +The unique id of the body. + +=head4 star_name + +A string with the star's name. Case insensitive, but will throw an exception for misspelling. + +=head4 star_id + +The unique id of the star. + +=head4 x | y + +A set of x,y coordinates to locate the star or body. + +=head4 types + +An array reference that contains the specification of the ships to send and the quantity. + + [ + { + "type" : "sweeper", + "speed" : 10166, + "stealth" : 10948, + "combat" : 33372, + "quantity" : 100 + }, + { + "type" : "surveyor", + "speed" : 9030, + "stealth" : 9030, + "combat" : 3220, + "quantity" : 10 + } + ] + +=head4 arrival + +A hash reference of the required arrival time. + + { + "day" : "23", + "hour" : "12", + "minute" : "01", + "second" : "30" + } + +So long as the sending body has that quantity of ships with those specifications, then the +ships will be sent. + +Ships will be set to arrive at the B time and date, which can be up to 28 days in +the future. B is the day of the month, either the remainder of the current month, or +the start of next month. e.g. if the current date is 23rd of January, then a B of 23 +will refer to today whereas 3 would refer to 3rd of February. + +If an arrival time is set which is prior to the earliest arrival time of the slowest ship, +then an exception is raised. =head2 send_fleet ( session_id, ship_ids, target, [ set_speed ] ) Sends a fleet of ships to a specified body or star. Use with C. - { + { "status" : { ... }, - "fleet" : [ - "ship" : { - "id" : "id-goes-here", - "name" : "P13", - "type_human" : "Probe", - "type" : "probe", - "task" : "Travelling", - "speed" : "1200", - "fleet_speed" : "250", - "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", - "can_recall" : "0", - "can_scuttle" : "0", - "from" : { - "id" : "id-goes-here", - "type" : "body", - "name" : "Earth" - }, - "to" : { - "id" : "id-goes-here", - "type" : "star", - "name" : "Sol" - } - }, - ... - ] - } + "fleet" : [ + "ship" : { + "id" : "id-goes-here", + "name" : "P13", + "type_human" : "Probe", + "type" : "probe", + "task" : "Travelling", + "speed" : "1200", + "fleet_speed" : "250", + "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", + "can_recall" : "0", + "can_scuttle" : "0", + "from" : { + "id" : "id-goes-here", + "type" : "body", + "name" : "Earth" + }, + "to" : { + "id" : "id-goes-here", + "type" : "star", + "name" : "Sol" + } + }, + ... + ] +} Throws 1002, 1009, 1010, 1016. @@ -485,7 +658,7 @@ Throws 1002, 1009, 1010, 1016. A session id. -=head3 ship_id +=head3 ship_ids An array reference of ship ids to send. diff --git a/lib/Lacuna/DB/Result/Ships.pm b/lib/Lacuna/DB/Result/Ships.pm index b2637bef..f6941df7 100644 --- a/lib/Lacuna/DB/Result/Ships.pm +++ b/lib/Lacuna/DB/Result/Ships.pm @@ -174,7 +174,13 @@ sub can_recall { sub type_formatted { my $self = shift; - my $type = $self->type; + + return $self->type_human($self->type); +} + +sub type_human { + my ($self, $type) = @_; + $type =~ s/_/ /g; $type =~ s/\b(\w)/\u$1/g; return $type; @@ -279,7 +285,9 @@ sub send { $self->payload($options{payload} || {}); $self->roundtrip($options{roundtrip} || 0); $self->direction($options{direction} || 'out'); - $self->date_available(DateTime->now->add(seconds=>$self->calculate_travel_time($options{target}))); + my $arrival = $options{arrival} || DateTime->now->add(seconds=>$self->calculate_travel_time($options{target})); + $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}); @@ -339,11 +347,19 @@ sub land { sub calculate_travel_time { my ($self, $target) = @_; + my $distance = $self->body->calculate_distance_to_target($target); my $speed = $self->speed; if ( $self->fleet_speed > 0 && $self->fleet_speed < $self->speed ) { $speed = $self->fleet_speed; } + return $self->travel_time($self->body, $target, $speed); +} + +sub travel_time { + my ($class, $from, $target, $speed) = @_; + + my $distance = $from->calculate_distance_to_target($target); $speed ||= 1; my $hours = $distance / $speed; my $seconds = 60 * 60 * $hours; diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index f6ce7b94..15568088 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -41,11 +41,55 @@ sub find_target { } } unless (defined $target) { - confess [ 1002, 'Could not find the target.', $target]; + confess [ 1002, 'Could not find the target.', $target]; } return $target; } +sub get_fleet_for { + my ($self, $session_id, $body_id, $target_params) = @_; + + my $empire = $self->get_empire_by_session($session_id); + my $body = $self->get_body($empire, $body_id); + my $target = $self->find_target($target_params); + + my $berth = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { + class => 'Lacuna::DB::Result::Building::SpacePort', + body_id => $body_id, + efficiency => 100, + } )->get_column('level')->max; + my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search( + { + body_id => $body->id, + task => 'docked', + },{ + '+select' => [{count => 'id'}], + '+as' => [ qw(quantity) ], + group_by => [ qw(type speed stealth combat hold_size) ], + }, + ); + my $summary; + while (my $ship_group = $ships->next) { + my $travel_time = Lacuna::DB::Result::Ships->travel_time($body,$target,$ship_group->speed); + my $type_human = Lacuna::DB::Result::Ships->type_human($ship_group->type); + my $summation = { + type => $ship_group->type, + type_human => $type_human, + speed => int($ship_group->speed), + stealth => int($ship_group->stealth), + combat => int($ship_group->combat), + quantity => $ship_group->get_column('quantity'), + estimated_travel_time => $travel_time, + }; + push @$summary, $summation; + } + my %out = ( + status => $self->format_status($empire, $body), + ships => $summary, + ); + return \%out; +} + sub get_ships_for { my ($self, $session_id, $body_id, $target_params) = @_; my $empire = $self->get_empire_by_session($session_id); @@ -55,12 +99,12 @@ sub get_ships_for { my @incoming; my $incoming_rs = $ships->search({ - task => 'Travelling', - direction => 'out', - 'body.empire_id' => $empire->id, - }, - { join => 'body' } - ); + task => 'Travelling', + direction => 'out', + 'body.empire_id' => $empire->id, + },{ + join => 'body', + }); if ($target->isa('Lacuna::DB::Result::Map::Star')) { $incoming_rs = $incoming_rs->search({foreign_star_id => $target->id}); } @@ -171,6 +215,113 @@ sub send_ship { } } +sub find_arrival { + my ($self, $arrival_params) = @_; + + my $now = DateTime->now; + my $year = $now->year, + my $month = $now->month; + my $mon_end = DateTime->last_day_of_month(year => $year, month => $month); + my $day = $arrival_params->{day}; + my $hour = $arrival_params->{hour}; + my $minute = $arrival_params->{minute}; + my $second = $arrival_params->{second}; + + if (not defined $day or $day < 1 or $day > $mon_end->day) { + confess [1009, 'Invalid day.']; + } + if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { + confess [1002, 'Invalid hour.']; + } + if (not defined $minute or $minute != int($minute) or $minute < 0 or $minute > 59) { + confess [1002, 'Invalid minute.']; + } + if (not defined $second or $second != int($second) or $second < 0 or $second > 59) { + confess [1002, 'Invalid second.']; + } + if ($day < $now->day) { + # Then it must be a day next month + $mon_end->add( days => $day); + $year = $mon_end->year; + $month = $mon_end->month; + } + my $arrival = DateTime->new( + year => $year, + month => $month, + day => $day, + hour => $hour, + minute => $minute, + second => $second, + ); + return $arrival; +} + +sub send_ship_types { + my ($self, $session_id, $from_body_id, $target_params, $type_params, $arrival) = @_; + + my $empire = $self->get_empire_by_session($session_id); + my $body = $self->get_body($empire, $body_id); + my $target = $self->find_target($target_params); + my $arrival = $self->find_arrival($arrival_params); + + # calculate the total ships before the expense of any database operations. + my $total_ships = 0; + map {$total_ships += $_->{quantity}} @$type_params; + my $max_ships = Lacuna->config->get('ships_per_fleet') || 20; + if ($total_ships > $max_ships) { + confess [1009, 'Too many ships for a fleet.']; + } + + my $ship_ref; + my $do_captcha_check = 0; + foreach my $type_param (@$type_params) { + foreach my $arg (qw(speed stealth combat quantity)) { + confess [1002, "$arg cannot be negative."] if $type_param->{$arg} < 0; + confess [1002, "$arg must be an integer."] if $type_param->{$arg} != int($type_param->{$arg}); + } + my $type = $type_param->{type}; + my $speed = $type_param->{speed}; + my $stealth = $type_param->{stealth}; + my $combat = $type_param->{combat}; + my $quantity = $type_param->{quantity}; + confess [1009, "Cannot send more than one excavator"] if ($type eq 'excavator' and $quantity > 1); + + # TODO Must check for valid berth levels + # + my $ships_rs = Lacuna->db->resultset('Ships')->search({ + body_id => $body->id, + task => 'Docked', + type => $type, + speed => $speed, + stealth => $stealth, + combat => $combat, + }); + if ($ships_rs->count < $quantity) { + confess [1009, "Cannot find $quantity of $type ships."]; + } + my @ships = $ships_rs->search(undef,{rows => $quantity}); + my $ship = $ships[0]; + # We only need to check one of the ships + $ship->can_send_to_target($target); + if (not $do_captcha_check and $ship->hostile_action) { + $do_captcha_check = 1; + } + foreach my $ship (@ships) { + my $hash = "${type}#${speed}#${stealth}#${combat}"; + $ship_ref->{$hash} = $ship; + } + } + if ($do_captcha_check) { + $empire->current_session->check_captcha; + } + # If we get here without exceptions, then all ships can be sent + foreach my $ship (values %$ship_ref) { + $ship->fleet_speed(1); + $ship->send(target => $target, arrival => $arrival); + } + +} + sub send_fleet { my ($self, $session_id, $ship_ids, $target_params, $set_speed) = @_; $set_speed //= 0; @@ -905,7 +1056,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_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 view_battle_logs)); +__PACKAGE__->register_rpc_method_names(qw(get_fleet_for 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 view_battle_logs)); no Moose; diff --git a/t/440_fleets.t b/t/440_fleets.t new file mode 100644 index 00000000..3e51eef0 --- /dev/null +++ b/t/440_fleets.t @@ -0,0 +1,32 @@ +use lib '../lib'; + +use strict; +use warnings; + +use Test::More tests => 10; +use Test::Deep; +use Data::Dumper; +use 5.010; +use DateTime; + +use TestHelper; +my $tester = TestHelper->new->use_existing_test_empire; +my $session_id = $tester->session->id; +my $empire = $tester->empire; +my $home = $empire->home_planet; +my $command = $home->command; + +my $result; + +my $space_port = Lacuna->db->resultset('Building')->search({ + class => 'Lacuna::DB::Result::Building::SpacePort', + body_id => $home->id, + },{ + rows => 1, +})->single; + +$result = $tester->post('spaceport','get_fleet_for', [$session_id, $home->id, {body_name => 'DeLambert-5-28'}]); + +END { +# TestHelper->clear_all_test_empires; +} -- 2.51.2 From 83e66009592c426820284c292ca3c546d7697754 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 13 May 2012 13:48:35 -0400 Subject: [PATCH 073/105] Minor changes --- lib/Lacuna/RPC/Building/SpacePort.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 15568088..dfe69c99 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -257,7 +257,7 @@ sub find_arrival { } sub send_ship_types { - my ($self, $session_id, $from_body_id, $target_params, $type_params, $arrival) = @_; + my ($self, $session_id, $body_id, $target_params, $type_params, $arrival) = @_; my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); @@ -319,7 +319,7 @@ sub send_ship_types { $ship->fleet_speed(1); $ship->send(target => $target, arrival => $arrival); } - + return $self->get_fleet_for($session, $body_id, $target_params); } sub send_fleet { -- 2.51.2 From ac33cfaf5338049b7093892e0fc8f51a51ebc1bd Mon Sep 17 00:00:00 2001 From: ian docherty Date: Tue, 15 May 2012 05:09:30 -0400 Subject: [PATCH 074/105] Fix error checking for send_ship_types --- lib/Lacuna/RPC/Building/SpacePort.pm | 16 +++++++++------- t/440_fleets.t | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index dfe69c99..12564f1b 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -6,6 +6,8 @@ no warnings qw(uninitialized); extends 'Lacuna::RPC::Building'; use Lacuna::Constants qw(SHIP_TYPES); use Lacuna::Util qw(format_date); +use Data::Dumper; + use feature "switch"; sub app_url { @@ -228,7 +230,7 @@ sub find_arrival { my $second = $arrival_params->{second}; if (not defined $day or $day < 1 or $day > $mon_end->day) { - confess [1009, 'Invalid day.']; + confess [1009, "Invalid day. [$day][".Dumper($arrival_params)."]"]; } if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { confess [1002, 'Invalid hour.']; @@ -236,8 +238,8 @@ sub find_arrival { if (not defined $minute or $minute != int($minute) or $minute < 0 or $minute > 59) { confess [1002, 'Invalid minute.']; } - if (not defined $second or $second != int($second) or $second < 0 or $second > 59) { - confess [1002, 'Invalid second.']; + if (not defined $second or $second != 0 and $second != 15 and $second != 30 and $second != 45) { + confess [1002, 'Invalid second. Must be 0, 15, 30 or 45']; } if ($day < $now->day) { # Then it must be a day next month @@ -257,7 +259,7 @@ sub find_arrival { } sub send_ship_types { - my ($self, $session_id, $body_id, $target_params, $type_params, $arrival) = @_; + my ($self, $session_id, $body_id, $target_params, $type_params, $arrival_params) = @_; my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); @@ -319,7 +321,7 @@ sub send_ship_types { $ship->fleet_speed(1); $ship->send(target => $target, arrival => $arrival); } - return $self->get_fleet_for($session, $body_id, $target_params); + return $self->get_fleet_for($session_id, $body_id, $target_params); } sub send_fleet { @@ -327,7 +329,7 @@ sub send_fleet { $set_speed //= 0; my $empire = $self->get_empire_by_session($session_id); my $target = $self->find_target($target_params); - my $max_ships = Lacuna->config->get('ships_per_fleet') || 20; + my $max_ships = Lacuna->config->get('ships_per_fleet') || 50; if (@$ship_ids > $max_ships) { confess [1009, 'Too many ships for a fleet.']; } @@ -1056,7 +1058,7 @@ around 'view' => sub { return $out; }; -__PACKAGE__->register_rpc_method_names(qw(get_fleet_for 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 view_battle_logs)); +__PACKAGE__->register_rpc_method_names(qw(send_ship_types get_fleet_for 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 view_battle_logs)); no Moose; diff --git a/t/440_fleets.t b/t/440_fleets.t index 3e51eef0..d4113cd9 100644 --- a/t/440_fleets.t +++ b/t/440_fleets.t @@ -27,6 +27,23 @@ my $space_port = Lacuna->db->resultset('Building')->search({ $result = $tester->post('spaceport','get_fleet_for', [$session_id, $home->id, {body_name => 'DeLambert-5-28'}]); +my ($sweepers) = grep {$_->{type} eq 'sweeper'} @{$result->{result}{ships}}; + +diag Dumper(\$sweepers); + +Lacuna->cache->set('captcha', $session_id, { guid => 1111, solution => 1111 }, 60 * 30 ); +$result = $tester->post('captcha','solve', [$session_id, 1111, 1111]); +is($result->{result}, 1, 'Solved captcha'); + + +$result = $tester->post('spaceport','send_ship_types', [ + $session_id, + $home->id, + {body_name => 'DeLambert-5-28'}, + [{type => 'sweeper', speed => $sweepers->{speed}, stealth => $sweepers->{stealth}, combat => $sweepers->{combat}, quantity => 10}], + {day => 10, hour => 1, minute => 1, second => 15}, +]); + END { # TestHelper->clear_all_test_empires; } -- 2.51.2 From f72ac1a1ec60c3228bae71345b44689d1c866116 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Thu, 17 May 2012 14:30:27 -0400 Subject: [PATCH 075/105] Send all ships in the fleet, not just one. --- lib/Lacuna/RPC/Building/SpacePort.pm | 3 +-- t/440_fleets.t | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 12564f1b..0175be4e 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -309,8 +309,7 @@ sub send_ship_types { $do_captcha_check = 1; } foreach my $ship (@ships) { - my $hash = "${type}#${speed}#${stealth}#${combat}"; - $ship_ref->{$hash} = $ship; + $ship_ref->{$ship->id} = $ship; } } if ($do_captcha_check) { diff --git a/t/440_fleets.t b/t/440_fleets.t index d4113cd9..787056fe 100644 --- a/t/440_fleets.t +++ b/t/440_fleets.t @@ -41,7 +41,7 @@ $result = $tester->post('spaceport','send_ship_types', [ $home->id, {body_name => 'DeLambert-5-28'}, [{type => 'sweeper', speed => $sweepers->{speed}, stealth => $sweepers->{stealth}, combat => $sweepers->{combat}, quantity => 10}], - {day => 10, hour => 1, minute => 1, second => 15}, + {day => 10, hour => 0, minute => 0, second => 0}, ]); END { -- 2.51.2 From 7a55329bf4b6a5ea7c1d39cb48270dabdd7b6220 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 13 May 2012 05:19:39 -0400 Subject: [PATCH 076/105] Started adding new fleet action API calls --- lib/Lacuna/RPC/Building/SpacePort.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 0175be4e..e8419821 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -230,7 +230,7 @@ sub find_arrival { my $second = $arrival_params->{second}; if (not defined $day or $day < 1 or $day > $mon_end->day) { - confess [1009, "Invalid day. [$day][".Dumper($arrival_params)."]"]; + confess [1009, 'Invalid day.']; } if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { confess [1002, 'Invalid hour.']; @@ -1059,7 +1059,6 @@ around 'view' => sub { __PACKAGE__->register_rpc_method_names(qw(send_ship_types get_fleet_for 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 view_battle_logs)); - no Moose; __PACKAGE__->meta->make_immutable; -- 2.51.2 From ce94968f4aead12798f06c41e794a8d6f915dd6b Mon Sep 17 00:00:00 2001 From: ian docherty Date: Tue, 15 May 2012 05:09:30 -0400 Subject: [PATCH 077/105] Fix error checking for send_ship_types --- lib/Lacuna/RPC/Building/SpacePort.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index e8419821..f2267570 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -230,7 +230,7 @@ sub find_arrival { my $second = $arrival_params->{second}; if (not defined $day or $day < 1 or $day > $mon_end->day) { - confess [1009, 'Invalid day.']; + confess [1009, "Invalid day. [$day][".Dumper($arrival_params)."]"]; } if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { confess [1002, 'Invalid hour.']; -- 2.51.2 From a75e97b95e619d1cb440088d060f4a178775f13d Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 13 May 2012 05:19:39 -0400 Subject: [PATCH 078/105] Started adding new fleet action API calls --- lib/Lacuna/RPC/Building/SpacePort.pm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index f2267570..76e3776f 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -230,7 +230,11 @@ sub find_arrival { my $second = $arrival_params->{second}; if (not defined $day or $day < 1 or $day > $mon_end->day) { +<<<<<<< HEAD confess [1009, "Invalid day. [$day][".Dumper($arrival_params)."]"]; +======= + confess [1009, 'Invalid day.']; +>>>>>>> Started adding new fleet action API calls } if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { confess [1002, 'Invalid hour.']; @@ -238,8 +242,13 @@ sub find_arrival { if (not defined $minute or $minute != int($minute) or $minute < 0 or $minute > 59) { confess [1002, 'Invalid minute.']; } +<<<<<<< HEAD if (not defined $second or $second != 0 and $second != 15 and $second != 30 and $second != 45) { confess [1002, 'Invalid second. Must be 0, 15, 30 or 45']; +======= + if (not defined $second or $second != int($second) or $second < 0 or $second > 59) { + confess [1002, 'Invalid second.']; +>>>>>>> Started adding new fleet action API calls } if ($day < $now->day) { # Then it must be a day next month @@ -259,7 +268,11 @@ sub find_arrival { } sub send_ship_types { +<<<<<<< HEAD my ($self, $session_id, $body_id, $target_params, $type_params, $arrival_params) = @_; +======= + my ($self, $session_id, $from_body_id, $target_params, $type_params, $arrival) = @_; +>>>>>>> Started adding new fleet action API calls my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); @@ -309,7 +322,12 @@ sub send_ship_types { $do_captcha_check = 1; } foreach my $ship (@ships) { +<<<<<<< HEAD $ship_ref->{$ship->id} = $ship; +======= + my $hash = "${type}#${speed}#${stealth}#${combat}"; + $ship_ref->{$hash} = $ship; +>>>>>>> Started adding new fleet action API calls } } if ($do_captcha_check) { @@ -320,7 +338,11 @@ sub send_ship_types { $ship->fleet_speed(1); $ship->send(target => $target, arrival => $arrival); } +<<<<<<< HEAD return $self->get_fleet_for($session_id, $body_id, $target_params); +======= + +>>>>>>> Started adding new fleet action API calls } sub send_fleet { -- 2.51.2 From 78a7ae24c24253e05cac811e1a5ab9474cf353c9 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 13 May 2012 13:48:35 -0400 Subject: [PATCH 079/105] Minor changes --- lib/Lacuna/RPC/Building/SpacePort.pm | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 76e3776f..f2267570 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -230,11 +230,7 @@ sub find_arrival { my $second = $arrival_params->{second}; if (not defined $day or $day < 1 or $day > $mon_end->day) { -<<<<<<< HEAD confess [1009, "Invalid day. [$day][".Dumper($arrival_params)."]"]; -======= - confess [1009, 'Invalid day.']; ->>>>>>> Started adding new fleet action API calls } if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { confess [1002, 'Invalid hour.']; @@ -242,13 +238,8 @@ sub find_arrival { if (not defined $minute or $minute != int($minute) or $minute < 0 or $minute > 59) { confess [1002, 'Invalid minute.']; } -<<<<<<< HEAD if (not defined $second or $second != 0 and $second != 15 and $second != 30 and $second != 45) { confess [1002, 'Invalid second. Must be 0, 15, 30 or 45']; -======= - if (not defined $second or $second != int($second) or $second < 0 or $second > 59) { - confess [1002, 'Invalid second.']; ->>>>>>> Started adding new fleet action API calls } if ($day < $now->day) { # Then it must be a day next month @@ -268,11 +259,7 @@ sub find_arrival { } sub send_ship_types { -<<<<<<< HEAD my ($self, $session_id, $body_id, $target_params, $type_params, $arrival_params) = @_; -======= - my ($self, $session_id, $from_body_id, $target_params, $type_params, $arrival) = @_; ->>>>>>> Started adding new fleet action API calls my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); @@ -322,12 +309,7 @@ sub send_ship_types { $do_captcha_check = 1; } foreach my $ship (@ships) { -<<<<<<< HEAD $ship_ref->{$ship->id} = $ship; -======= - my $hash = "${type}#${speed}#${stealth}#${combat}"; - $ship_ref->{$hash} = $ship; ->>>>>>> Started adding new fleet action API calls } } if ($do_captcha_check) { @@ -338,11 +320,7 @@ sub send_ship_types { $ship->fleet_speed(1); $ship->send(target => $target, arrival => $arrival); } -<<<<<<< HEAD return $self->get_fleet_for($session_id, $body_id, $target_params); -======= - ->>>>>>> Started adding new fleet action API calls } sub send_fleet { -- 2.51.2 From 315b965fed150156702f37ace95d8c35fa87a64b Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 3 Jun 2012 04:50:41 -0400 Subject: [PATCH 080/105] Start to convert ships into fleets --- lib/Lacuna/DB/Result/Fleet.pm | 370 ++++++++++++++++++++++++++++++++++ 1 file changed, 370 insertions(+) create mode 100644 lib/Lacuna/DB/Result/Fleet.pm diff --git a/lib/Lacuna/DB/Result/Fleet.pm b/lib/Lacuna/DB/Result/Fleet.pm new file mode 100644 index 00000000..f6941df7 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet.pm @@ -0,0 +1,370 @@ +package Lacuna::DB::Result::Ships; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result'; +use Lacuna::Util qw(format_date randint); +use DateTime; +use feature "switch"; + +has 'hostile_action' => ( + is => 'rw', + isa => 'Bool', + lazy => 1, + builder => '_build_hostile_action', +); + +sub _build_hostile_action { 0 } + +__PACKAGE__->load_components('DynamicSubclass'); +__PACKAGE__->table('ships'); +__PACKAGE__->add_columns( + body_id => { data_type => 'int', is_nullable => 0 }, + shipyard_id => { data_type => 'int', is_nullable => 0 }, + date_started => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, + date_available => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, + type => { data_type => 'varchar', size => 30, is_nullable => 0 }, # probe, colony_ship, spy_pod, cargo_ship, space_station, smuggler_ship, mining_platform_ship, terraforming_platform_ship, gas_giant_settlement_ship + task => { data_type => 'varchar', size => 30, is_nullable => 0 }, # Docked, Building, Travelling, Mining, Defend, Orbiting + name => { data_type => 'varchar', size => 30, is_nullable => 0 }, + speed => { data_type => 'int', is_nullable => 0 }, + stealth => { data_type => 'int', is_nullable => 0 }, + combat => { data_type => 'int', is_nullable => 0 }, + hold_size => { data_type => 'int', is_nullable => 0 }, + payload => { data_type => 'mediumblob', is_nullable => 1, 'serializer_class' => 'JSON' }, + roundtrip => { data_type => 'bit', default_value => 0 }, + direction => { data_type => 'varchar', size => 3, is_nullable => 0 }, # in || out + foreign_body_id => { data_type => 'int', is_nullable => 1 }, + foreign_star_id => { data_type => 'int', is_nullable => 1 }, + fleet_speed => { data_type => 'int', is_nullable => 0 }, + berth_level => { data_type => 'int', is_nullable => 0 }, +); +__PACKAGE__->typecast_map(type => { + 'probe' => 'Lacuna::DB::Result::Ships::Probe', + 'stake' => 'Lacuna::DB::Result::Ships::Stake', + 'supply_pod' => 'Lacuna::DB::Result::Ships::SupplyPod', + 'supply_pod2' => 'Lacuna::DB::Result::Ships::SupplyPod2', + 'supply_pod3' => 'Lacuna::DB::Result::Ships::SupplyPod3', + 'supply_pod4' => 'Lacuna::DB::Result::Ships::SupplyPod4', + 'placebo' => 'Lacuna::DB::Result::Ships::Placebo', + 'placebo2' => 'Lacuna::DB::Result::Ships::Placebo2', + 'placebo3' => 'Lacuna::DB::Result::Ships::Placebo3', + 'placebo4' => 'Lacuna::DB::Result::Ships::Placebo4', + 'placebo5' => 'Lacuna::DB::Result::Ships::Placebo5', + 'placebo6' => 'Lacuna::DB::Result::Ships::Placebo6', + 'short_range_colony_ship' => 'Lacuna::DB::Result::Ships::ShortRangeColonyShip', + 'colony_ship' => 'Lacuna::DB::Result::Ships::ColonyShip', + 'spy_pod' => 'Lacuna::DB::Result::Ships::SpyPod', + 'cargo_ship' => 'Lacuna::DB::Result::Ships::CargoShip', + 'space_station' => 'Lacuna::DB::Result::Ships::SpaceStation', + 'smuggler_ship' => 'Lacuna::DB::Result::Ships::SmugglerShip', + 'mining_platform_ship' => 'Lacuna::DB::Result::Ships::MiningPlatformShip', + 'terraforming_platform_ship' => 'Lacuna::DB::Result::Ships::TerraformingPlatformShip', + 'gas_giant_settlement_ship' => 'Lacuna::DB::Result::Ships::GasGiantSettlementPlatformShip', + 'scanner' => 'Lacuna::DB::Result::Ships::Scanner', + 'surveyor' => 'Lacuna::DB::Result::Ships::Surveyor', + 'detonator' => 'Lacuna::DB::Result::Ships::Detonator', + 'excavator' => 'Lacuna::DB::Result::Ships::Excavator', + 'scow' => 'Lacuna::DB::Result::Ships::Scow', + 'scow_large' => 'Lacuna::DB::Result::Ships::ScowLarge', + 'scow_mega' => 'Lacuna::DB::Result::Ships::ScowMega', + 'scow_fast' => 'Lacuna::DB::Result::Ships::ScowFast', + 'freighter' => 'Lacuna::DB::Result::Ships::Freighter', + 'dory' => 'Lacuna::DB::Result::Ships::Dory', + 'barge' => 'Lacuna::DB::Result::Ships::Barge', + 'galleon' => 'Lacuna::DB::Result::Ships::Galleon', + 'hulk' => 'Lacuna::DB::Result::Ships::Hulk', + 'hulk_huge' => 'Lacuna::DB::Result::Ships::HulkHuge', + 'hulk_fast' => 'Lacuna::DB::Result::Ships::HulkFast', + 'snark' => 'Lacuna::DB::Result::Ships::Snark', + 'snark2' => 'Lacuna::DB::Result::Ships::Snark2', + 'snark3' => 'Lacuna::DB::Result::Ships::Snark3', + 'spy_shuttle' => 'Lacuna::DB::Result::Ships::SpyShuttle', + 'drone' => 'Lacuna::DB::Result::Ships::Drone', + 'fighter' => 'Lacuna::DB::Result::Ships::Fighter', + 'sweeper' => 'Lacuna::DB::Result::Ships::Sweeper', + 'bleeder' => 'Lacuna::DB::Result::Ships::Bleeder', + 'thud' => 'Lacuna::DB::Result::Ships::Thud', + 'observatory_seeker' => 'Lacuna::DB::Result::Ships::ObservatorySeeker', + 'spaceport_seeker' => 'Lacuna::DB::Result::Ships::SpacePortSeeker', + 'security_ministry_seeker' => 'Lacuna::DB::Result::Ships::SecurityMinistrySeeker', +}); + +with 'Lacuna::Role::Container'; + +__PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Map::Body', 'body_id'); +__PACKAGE__->belongs_to('foreign_star', 'Lacuna::DB::Result::Map::Star', 'foreign_star_id'); +__PACKAGE__->belongs_to('foreign_body', 'Lacuna::DB::Result::Map::Body', 'foreign_body_id'); + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::University', level => 1 } ]; +use constant base_food_cost => 1; +use constant base_water_cost => 1; +use constant base_energy_cost => 1; +use constant base_ore_cost => 1; +use constant base_time_cost => 1; +use constant base_waste_cost => 1; +use constant base_speed => 1; +use constant base_combat => 0; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant base_berth_level => 1; +use constant pilotable => 0; +use constant target_building => []; +use constant build_tags => []; +use constant splash_radius => 0; + +sub max_occupants { + my $self = shift; + return 0 unless $self->pilotable; + return int($self->hold_size / 350); +} + +sub arrive { + my $self = shift; + eval {$self->handle_arrival_procedures}; # throws exceptions to stop subsequent actions from happening + my $reason = $@; + if (ref $reason eq 'ARRAY' && $reason->[0] eq -1) { + # this is an expected exception, it means one of the roles took over + return; + } + elsif ($reason) { + # this is unexpected, so let's rethrow + confess $reason; + } + + # no exceptions, so we either need to go home or land + if ($self->direction eq 'out') { + $self->turn_around->update; + } + else { + $self->land->update; + } +} + +sub handle_arrival_procedures { + my $self = shift; + $self->note_arrival; +} + +sub note_arrival { + my $self = shift; + Lacuna->cache->increment($self->type.'_arrive_'.$self->foreign_body_id.$self->foreign_star_id, $self->body->empire_id,1, 60*60*24*30); +} + +sub is_available { + my ($self) = @_; + return ($self->task eq 'Docked'); +} + +sub can_send_to_target { + my $self = shift; + unless ($self->task eq 'Docked') { + confess [1010, 'That ship is busy.']; + } + return 1; +} + +sub can_recall { + my $self = shift; + unless ($self->task ~~ [qw(Defend Orbiting)]) { + confess [1010, 'That ship is busy.']; + } + return 1; +} + +sub type_formatted { + my $self = shift; + + return $self->type_human($self->type); +} + +sub type_human { + my ($self, $type) = @_; + + $type =~ s/_/ /g; + $type =~ s/\b(\w)/\u$1/g; + return $type; +} + +sub date_started_formatted { + my $self = shift; + return format_date($self->date_started); +} + +sub date_available_formatted { + my $self = shift; + return format_date($self->date_available); +} + +sub get_status { + my ($self, $target) = @_; + my %status = ( + id => $self->id, + name => $self->name, + type_human => $self->type_formatted, + type => $self->type, + task => $self->task, + speed => $self->speed, + fleet_speed => $self->fleet_speed, + stealth => $self->stealth, + combat => $self->combat, + hold_size => $self->hold_size, + berth_level => $self->berth_level, + date_started => $self->date_started_formatted, + date_available => $self->date_available_formatted, + max_occupants => $self->max_occupants, + payload => $self->format_description_of_payload, + can_scuttle => ($self->task eq 'Docked') ? 1 : 0, + can_recall => ($self->task ~~ [qw(Defend Orbiting)]) ? 1 : 0, + ); + if ($target) { + $status{estimated_travel_time} = $self->calculate_travel_time($target); + } + if ($self->task eq 'Travelling') { + my $body = $self->body; + my $target = ($self->foreign_body_id) ? $self->foreign_body : $self->foreign_star; + my $from = { + id => $body->id, + name => $body->name, + type => 'body', + }; + my $to = { + id => $target->id, + name => $target->name, + type => (ref $target eq 'Lacuna::DB::Result::Map::Star') ? 'star' : 'body', + }; + if ($self->direction ne 'out') { + my $temp = $from; + $from = $to; + $to = $temp; + } + $status{to} = $to; + $status{from} = $from; + $status{date_arrives} = $status{date_available}; + } + elsif ($self->task ~~ [qw(Defend Orbiting)]) { + my $body = $self->body; + my $from = { + id => $body->id, + name => $body->name, + type => 'body', + }; + my $orbiting = { + id => $self->foreign_body_id, + name => $self->foreign_body->name, + type => 'body', + x => $self->foreign_body->x, + y => $self->foreign_body->y, + }; + $status{from} = $from; + $status{orbiting} = $orbiting; + } + return \%status; +} + +sub seconds_remaining { + my $self = shift; + return time - $self->date_available->epoch; +} + +sub turn_around { + my $self = shift; + $self->direction( ($self->direction eq 'out') ? 'in' : 'out' ); +# $self->date_available(DateTime->now->add_duration( $self->date_available - $self->date_started )); + $self->fleet_speed(0); + my $target = ($self->foreign_body_id) ? $self->foreign_body : $self->foreign_star; + $self->date_available(DateTime->now->add(seconds=>$self->calculate_travel_time($target))); + $self->date_started(DateTime->now); + return $self; +} + +sub send { + my ($self, %options ) = @_; + $self->date_started(DateTime->now); + $self->task('Travelling'); + $self->payload($options{payload} || {}); + $self->roundtrip($options{roundtrip} || 0); + $self->direction($options{direction} || 'out'); + my $arrival = $options{arrival} || DateTime->now->add(seconds=>$self->calculate_travel_time($options{target})); + $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}); + $self->foreign_star_id(undef); + $self->foreign_star(undef); + } + elsif ($options{target}->isa('Lacuna::DB::Result::Map::Star')) { + $self->foreign_star_id($options{target}->id); + $self->foreign_star($options{target}); + $self->foreign_body_id(undef); + $self->foreign_body(undef); + } + else { + confess [1002, 'You cannot send a ship to a non-existant target.']; + } + $self->update; + return $self; +} + +sub finish_construction { + my ($self) = @_; + $self->body->empire->add_medal($self->type); + $self->task('Docked'); + $self->date_available(DateTime->now); + $self->update; +} + +sub orbit { + my ($self) = @_; + $self->task('Orbiting'); + $self->date_available(DateTime->now); + return $self; +} + +sub defend { + my ($self) = @_; + $self->task('Defend'); + $self->date_available(DateTime->now); + return $self; +} + +sub land { + my ($self) = @_; + $self->task('Docked'); + $self->fleet_speed(0); + $self->date_available(DateTime->now); + $self->payload({}); + return $self; +} + + + + +# DISTANCE + + + +sub calculate_travel_time { + my ($self, $target) = @_; + + my $distance = $self->body->calculate_distance_to_target($target); + my $speed = $self->speed; + if ( $self->fleet_speed > 0 && $self->fleet_speed < $self->speed ) { + $speed = $self->fleet_speed; + } + return $self->travel_time($self->body, $target, $speed); +} + +sub travel_time { + my ($class, $from, $target, $speed) = @_; + + my $distance = $from->calculate_distance_to_target($target); + $speed ||= 1; + my $hours = $distance / $speed; + my $seconds = 60 * 60 * $hours; + return sprintf('%.0f', $seconds); +} + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); -- 2.51.2 From d16851ed5b491633f4f520e5840921ff0bd942f3 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 3 Jun 2012 05:24:48 -0400 Subject: [PATCH 081/105] Added Fleet SQL --- lib/Lacuna/DB/Result/Fleet.pm | 133 +++++++++++++++++----------------- var/upgrades/3.fleet.sql | 31 ++++++++ 2 files changed, 98 insertions(+), 66 deletions(-) create mode 100644 var/upgrades/3.fleet.sql diff --git a/lib/Lacuna/DB/Result/Fleet.pm b/lib/Lacuna/DB/Result/Fleet.pm index f6941df7..5557e8a4 100644 --- a/lib/Lacuna/DB/Result/Fleet.pm +++ b/lib/Lacuna/DB/Result/Fleet.pm @@ -1,4 +1,4 @@ -package Lacuna::DB::Result::Ships; +package Lacuna::DB::Result::Fleet; use Moose; use utf8; @@ -18,14 +18,15 @@ has 'hostile_action' => ( sub _build_hostile_action { 0 } __PACKAGE__->load_components('DynamicSubclass'); -__PACKAGE__->table('ships'); +__PACKAGE__->table('fleet'); __PACKAGE__->add_columns( body_id => { data_type => 'int', is_nullable => 0 }, + mark => { data_type => 'varchar', size => 10, is_nullable => 0 }, shipyard_id => { data_type => 'int', is_nullable => 0 }, date_started => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, date_available => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, - type => { data_type => 'varchar', size => 30, is_nullable => 0 }, # probe, colony_ship, spy_pod, cargo_ship, space_station, smuggler_ship, mining_platform_ship, terraforming_platform_ship, gas_giant_settlement_ship - task => { data_type => 'varchar', size => 30, is_nullable => 0 }, # Docked, Building, Travelling, Mining, Defend, Orbiting + type => { data_type => 'varchar', size => 30, is_nullable => 0 }, + task => { data_type => 'varchar', size => 30, is_nullable => 0 }, name => { data_type => 'varchar', size => 30, is_nullable => 0 }, speed => { data_type => 'int', is_nullable => 0 }, stealth => { data_type => 'int', is_nullable => 0 }, @@ -40,54 +41,54 @@ __PACKAGE__->add_columns( berth_level => { data_type => 'int', is_nullable => 0 }, ); __PACKAGE__->typecast_map(type => { - 'probe' => 'Lacuna::DB::Result::Ships::Probe', - 'stake' => 'Lacuna::DB::Result::Ships::Stake', - 'supply_pod' => 'Lacuna::DB::Result::Ships::SupplyPod', - 'supply_pod2' => 'Lacuna::DB::Result::Ships::SupplyPod2', - 'supply_pod3' => 'Lacuna::DB::Result::Ships::SupplyPod3', - 'supply_pod4' => 'Lacuna::DB::Result::Ships::SupplyPod4', - 'placebo' => 'Lacuna::DB::Result::Ships::Placebo', - 'placebo2' => 'Lacuna::DB::Result::Ships::Placebo2', - 'placebo3' => 'Lacuna::DB::Result::Ships::Placebo3', - 'placebo4' => 'Lacuna::DB::Result::Ships::Placebo4', - 'placebo5' => 'Lacuna::DB::Result::Ships::Placebo5', - 'placebo6' => 'Lacuna::DB::Result::Ships::Placebo6', - 'short_range_colony_ship' => 'Lacuna::DB::Result::Ships::ShortRangeColonyShip', - 'colony_ship' => 'Lacuna::DB::Result::Ships::ColonyShip', - 'spy_pod' => 'Lacuna::DB::Result::Ships::SpyPod', - 'cargo_ship' => 'Lacuna::DB::Result::Ships::CargoShip', - 'space_station' => 'Lacuna::DB::Result::Ships::SpaceStation', - 'smuggler_ship' => 'Lacuna::DB::Result::Ships::SmugglerShip', - 'mining_platform_ship' => 'Lacuna::DB::Result::Ships::MiningPlatformShip', - 'terraforming_platform_ship' => 'Lacuna::DB::Result::Ships::TerraformingPlatformShip', - 'gas_giant_settlement_ship' => 'Lacuna::DB::Result::Ships::GasGiantSettlementPlatformShip', - 'scanner' => 'Lacuna::DB::Result::Ships::Scanner', - 'surveyor' => 'Lacuna::DB::Result::Ships::Surveyor', - 'detonator' => 'Lacuna::DB::Result::Ships::Detonator', - 'excavator' => 'Lacuna::DB::Result::Ships::Excavator', - 'scow' => 'Lacuna::DB::Result::Ships::Scow', - 'scow_large' => 'Lacuna::DB::Result::Ships::ScowLarge', - 'scow_mega' => 'Lacuna::DB::Result::Ships::ScowMega', - 'scow_fast' => 'Lacuna::DB::Result::Ships::ScowFast', - 'freighter' => 'Lacuna::DB::Result::Ships::Freighter', - 'dory' => 'Lacuna::DB::Result::Ships::Dory', - 'barge' => 'Lacuna::DB::Result::Ships::Barge', - 'galleon' => 'Lacuna::DB::Result::Ships::Galleon', - 'hulk' => 'Lacuna::DB::Result::Ships::Hulk', - 'hulk_huge' => 'Lacuna::DB::Result::Ships::HulkHuge', - 'hulk_fast' => 'Lacuna::DB::Result::Ships::HulkFast', - 'snark' => 'Lacuna::DB::Result::Ships::Snark', - 'snark2' => 'Lacuna::DB::Result::Ships::Snark2', - 'snark3' => 'Lacuna::DB::Result::Ships::Snark3', - 'spy_shuttle' => 'Lacuna::DB::Result::Ships::SpyShuttle', - 'drone' => 'Lacuna::DB::Result::Ships::Drone', - 'fighter' => 'Lacuna::DB::Result::Ships::Fighter', - 'sweeper' => 'Lacuna::DB::Result::Ships::Sweeper', - 'bleeder' => 'Lacuna::DB::Result::Ships::Bleeder', - 'thud' => 'Lacuna::DB::Result::Ships::Thud', - 'observatory_seeker' => 'Lacuna::DB::Result::Ships::ObservatorySeeker', - 'spaceport_seeker' => 'Lacuna::DB::Result::Ships::SpacePortSeeker', - 'security_ministry_seeker' => 'Lacuna::DB::Result::Ships::SecurityMinistrySeeker', + 'probe' => 'Lacuna::DB::Result::Fleet::Probe', + 'stake' => 'Lacuna::DB::Result::Fleet::Stake', + 'supply_pod' => 'Lacuna::DB::Result::Fleet::SupplyPod', + 'supply_pod2' => 'Lacuna::DB::Result::Fleet::SupplyPod2', + 'supply_pod3' => 'Lacuna::DB::Result::Fleet::SupplyPod3', + 'supply_pod4' => 'Lacuna::DB::Result::Fleet::SupplyPod4', + 'placebo' => 'Lacuna::DB::Result::Fleet::Placebo', + 'placebo2' => 'Lacuna::DB::Result::Fleet::Placebo2', + 'placebo3' => 'Lacuna::DB::Result::Fleet::Placebo3', + 'placebo4' => 'Lacuna::DB::Result::Fleet::Placebo4', + 'placebo5' => 'Lacuna::DB::Result::Fleet::Placebo5', + 'placebo6' => 'Lacuna::DB::Result::Fleet::Placebo6', + 'short_range_colony_ship' => 'Lacuna::DB::Result::Fleet::ShortRangeColonyShip', + 'colony_ship' => 'Lacuna::DB::Result::Fleet::ColonyShip', + 'spy_pod' => 'Lacuna::DB::Result::Fleet::SpyPod', + 'cargo_ship' => 'Lacuna::DB::Result::Fleet::CargoShip', + 'space_station' => 'Lacuna::DB::Result::Fleet::SpaceStation', + 'smuggler_ship' => 'Lacuna::DB::Result::Fleet::SmugglerShip', + 'mining_platform_ship' => 'Lacuna::DB::Result::Fleet::MiningPlatformShip', + 'terraforming_platform_ship' => 'Lacuna::DB::Result::Fleet::TerraformingPlatformShip', + 'gas_giant_settlement_ship' => 'Lacuna::DB::Result::Fleet::GasGiantSettlementPlatformShip', + 'scanner' => 'Lacuna::DB::Result::Fleet::Scanner', + 'surveyor' => 'Lacuna::DB::Result::Fleet::Surveyor', + 'detonator' => 'Lacuna::DB::Result::Fleet::Detonator', + 'excavator' => 'Lacuna::DB::Result::Fleet::Excavator', + 'scow' => 'Lacuna::DB::Result::Fleet::Scow', + 'scow_large' => 'Lacuna::DB::Result::Fleet::ScowLarge', + 'scow_mega' => 'Lacuna::DB::Result::Fleet::ScowMega', + 'scow_fast' => 'Lacuna::DB::Result::Fleet::ScowFast', + 'freighter' => 'Lacuna::DB::Result::Fleet::Freighter', + 'dory' => 'Lacuna::DB::Result::Fleet::Dory', + 'barge' => 'Lacuna::DB::Result::Fleet::Barge', + 'galleon' => 'Lacuna::DB::Result::Fleet::Galleon', + 'hulk' => 'Lacuna::DB::Result::Fleet::Hulk', + 'hulk_huge' => 'Lacuna::DB::Result::Fleet::HulkHuge', + 'hulk_fast' => 'Lacuna::DB::Result::Fleet::HulkFast', + 'snark' => 'Lacuna::DB::Result::Fleet::Snark', + 'snark2' => 'Lacuna::DB::Result::Fleet::Snark2', + 'snark3' => 'Lacuna::DB::Result::Fleet::Snark3', + 'spy_shuttle' => 'Lacuna::DB::Result::Fleet::SpyShuttle', + 'drone' => 'Lacuna::DB::Result::Fleet::Drone', + 'fighter' => 'Lacuna::DB::Result::Fleet::Fighter', + 'sweeper' => 'Lacuna::DB::Result::Fleet::Sweeper', + 'bleeder' => 'Lacuna::DB::Result::Fleet::Bleeder', + 'thud' => 'Lacuna::DB::Result::Fleet::Thud', + 'observatory_seeker' => 'Lacuna::DB::Result::Fleet::ObservatorySeeker', + 'spaceport_seeker' => 'Lacuna::DB::Result::Fleet::SpacePortSeeker', + 'security_ministry_seeker' => 'Lacuna::DB::Result::Fleet::SecurityMinistrySeeker', }); with 'Lacuna::Role::Container'; @@ -122,7 +123,7 @@ sub max_occupants { sub arrive { my $self = shift; eval {$self->handle_arrival_procedures}; # throws exceptions to stop subsequent actions from happening - my $reason = $@; + my $reason = $@; if (ref $reason eq 'ARRAY' && $reason->[0] eq -1) { # this is an expected exception, it means one of the roles took over return; @@ -166,7 +167,7 @@ sub can_send_to_target { sub can_recall { my $self = shift; - unless ($self->task ~~ [qw(Defend Orbiting)]) { + unless ($self->task ~~ [qw(Defend Orbiting)]) { confess [1010, 'That ship is busy.']; } return 1; @@ -249,16 +250,16 @@ sub get_status { name => $body->name, type => 'body', }; - my $orbiting = { - id => $self->foreign_body_id, + my $orbiting = { + id => $self->foreign_body_id, name => $self->foreign_body->name, - type => 'body', - x => $self->foreign_body->x, - y => $self->foreign_body->y, + type => 'body', + x => $self->foreign_body->x, + y => $self->foreign_body->y, }; - $status{from} = $from; - $status{orbiting} = $orbiting; - } + $status{from} = $from; + $status{orbiting} = $orbiting; + } return \%status; } @@ -316,15 +317,15 @@ sub finish_construction { } sub orbit { - my ($self) = @_; - $self->task('Orbiting'); + my ($self) = @_; + $self->task('Orbiting'); $self->date_available(DateTime->now); return $self; } sub defend { - my ($self) = @_; - $self->task('Defend'); + my ($self) = @_; + $self->task('Defend'); $self->date_available(DateTime->now); return $self; } diff --git a/var/upgrades/3.fleet.sql b/var/upgrades/3.fleet.sql new file mode 100644 index 00000000..da71e190 --- /dev/null +++ b/var/upgrades/3.fleet.sql @@ -0,0 +1,31 @@ + +create table fleet ( + id int(11) not null auto_increment, + body_id int(11) not null, + shipyard_id int(11) not null, + date_started datetime not null, + date_available datetime not null, + mark varchar(10) not null, + type varchar(30) not null, + task varchar(30) not null, + name varchar(30) not null, + speed int(11) not null, + stealth int(11) not null, + combat int(11) not null, + hold_size int(11) not null, + payload mediumblob, + roundtrip tinyint(4) not null default 0, + direction varchar(3) not null, + foreign_body_id int(11), + foreign_star_id int(11), + berth_level tinyint(4) default 1, + primary key (id), + key f_mark (mark), + key f_idx_body_id (body_id), + key f_idx_foreign_body_id (foreign_body_id), + key f_idx_foreign_star_id (foreign_star_id), + constraint wc_f_body_id foreign key (body_id) references body (id), + constraint wc_f_foreign_body_id foreign key (foreign_body_id) references body (id), + constraint wc_f_foreign_star_id foreign key (foreign_star_id) references star (id) +); + -- 2.51.2 From bb34a44deecbb78173eeeeb3dfb38f4a09a80ab7 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 13 May 2012 05:19:39 -0400 Subject: [PATCH 082/105] Started adding new fleet action API calls --- lib/Lacuna/RPC/Building/SpacePort.pm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index f2267570..76e3776f 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -230,7 +230,11 @@ sub find_arrival { my $second = $arrival_params->{second}; if (not defined $day or $day < 1 or $day > $mon_end->day) { +<<<<<<< HEAD confess [1009, "Invalid day. [$day][".Dumper($arrival_params)."]"]; +======= + confess [1009, 'Invalid day.']; +>>>>>>> Started adding new fleet action API calls } if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { confess [1002, 'Invalid hour.']; @@ -238,8 +242,13 @@ sub find_arrival { if (not defined $minute or $minute != int($minute) or $minute < 0 or $minute > 59) { confess [1002, 'Invalid minute.']; } +<<<<<<< HEAD if (not defined $second or $second != 0 and $second != 15 and $second != 30 and $second != 45) { confess [1002, 'Invalid second. Must be 0, 15, 30 or 45']; +======= + if (not defined $second or $second != int($second) or $second < 0 or $second > 59) { + confess [1002, 'Invalid second.']; +>>>>>>> Started adding new fleet action API calls } if ($day < $now->day) { # Then it must be a day next month @@ -259,7 +268,11 @@ sub find_arrival { } sub send_ship_types { +<<<<<<< HEAD my ($self, $session_id, $body_id, $target_params, $type_params, $arrival_params) = @_; +======= + my ($self, $session_id, $from_body_id, $target_params, $type_params, $arrival) = @_; +>>>>>>> Started adding new fleet action API calls my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); @@ -309,7 +322,12 @@ sub send_ship_types { $do_captcha_check = 1; } foreach my $ship (@ships) { +<<<<<<< HEAD $ship_ref->{$ship->id} = $ship; +======= + my $hash = "${type}#${speed}#${stealth}#${combat}"; + $ship_ref->{$hash} = $ship; +>>>>>>> Started adding new fleet action API calls } } if ($do_captcha_check) { @@ -320,7 +338,11 @@ sub send_ship_types { $ship->fleet_speed(1); $ship->send(target => $target, arrival => $arrival); } +<<<<<<< HEAD return $self->get_fleet_for($session_id, $body_id, $target_params); +======= + +>>>>>>> Started adding new fleet action API calls } sub send_fleet { -- 2.51.2 From 9304e7f1e1bec79b59462b6a3acc9a4926809195 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 3 Jun 2012 06:25:13 -0400 Subject: [PATCH 083/105] Added Fleet files --- bin/convert_ships_to_fleets.pl | 81 +++++++++++++++++++ lib/Lacuna/DB/Result/Fleet/Barge.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/Bleeder.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/CargoShip.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/ColonyShip.pm | 30 +++++++ lib/Lacuna/DB/Result/Fleet/Detonator.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/Dory.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/Drone.pm | 24 ++++++ lib/Lacuna/DB/Result/Fleet/Excavator.pm | 25 ++++++ lib/Lacuna/DB/Result/Fleet/Fighter.pm | 24 ++++++ lib/Lacuna/DB/Result/Fleet/Freighter.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/Galleon.pm | 26 ++++++ .../Fleet/GasGiantSettlementPlatformShip.pm | 26 ++++++ lib/Lacuna/DB/Result/Fleet/Hulk.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/HulkFast.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/HulkHuge.pm | 28 +++++++ .../DB/Result/Fleet/MiningPlatformShip.pm | 27 +++++++ .../DB/Result/Fleet/ObservatorySeeker.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Placebo.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/Placebo2.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Placebo3.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Placebo4.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Placebo5.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Placebo6.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Probe.pm | 24 ++++++ lib/Lacuna/DB/Result/Fleet/Scanner.pm | 27 +++++++ lib/Lacuna/DB/Result/Fleet/Scow.pm | 27 +++++++ lib/Lacuna/DB/Result/Fleet/ScowFast.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/ScowLarge.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/ScowMega.pm | 28 +++++++ .../DB/Result/Fleet/SecurityMinistrySeeker.pm | 29 +++++++ .../DB/Result/Fleet/ShortRangeColonyShip.pm | 31 +++++++ lib/Lacuna/DB/Result/Fleet/SmugglerShip.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/Snark.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Snark2.pm | 31 +++++++ lib/Lacuna/DB/Result/Fleet/Snark3.pm | 31 +++++++ lib/Lacuna/DB/Result/Fleet/SpacePortSeeker.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/SpaceStation.pm | 31 +++++++ lib/Lacuna/DB/Result/Fleet/SpyPod.pm | 32 ++++++++ lib/Lacuna/DB/Result/Fleet/SpyShuttle.pm | 31 +++++++ lib/Lacuna/DB/Result/Fleet/Stake.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/SupplyPod.pm | 28 +++++++ lib/Lacuna/DB/Result/Fleet/SupplyPod2.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/SupplyPod3.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/SupplyPod4.pm | 29 +++++++ lib/Lacuna/DB/Result/Fleet/Surveyor.pm | 27 +++++++ lib/Lacuna/DB/Result/Fleet/Sweeper.pm | 27 +++++++ .../Result/Fleet/TerraformingPlatformShip.pm | 25 ++++++ lib/Lacuna/DB/Result/Fleet/Thud.pm | 29 +++++++ 49 files changed, 1436 insertions(+) create mode 100644 bin/convert_ships_to_fleets.pl create mode 100644 lib/Lacuna/DB/Result/Fleet/Barge.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Bleeder.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/CargoShip.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/ColonyShip.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Detonator.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Dory.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Drone.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Excavator.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Fighter.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Freighter.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Galleon.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/GasGiantSettlementPlatformShip.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Hulk.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/HulkFast.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/HulkHuge.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/MiningPlatformShip.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/ObservatorySeeker.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Placebo.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Placebo2.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Placebo3.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Placebo4.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Placebo5.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Placebo6.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Probe.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Scanner.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Scow.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/ScowFast.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/ScowLarge.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/ScowMega.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SecurityMinistrySeeker.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/ShortRangeColonyShip.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SmugglerShip.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Snark.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Snark2.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Snark3.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SpacePortSeeker.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SpaceStation.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SpyPod.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SpyShuttle.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Stake.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SupplyPod.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SupplyPod2.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SupplyPod3.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/SupplyPod4.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Surveyor.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Sweeper.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/TerraformingPlatformShip.pm create mode 100644 lib/Lacuna/DB/Result/Fleet/Thud.pm diff --git a/bin/convert_ships_to_fleets.pl b/bin/convert_ships_to_fleets.pl new file mode 100644 index 00000000..9c3c3c9c --- /dev/null +++ b/bin/convert_ships_to_fleets.pl @@ -0,0 +1,81 @@ +use 5.010; +use strict; +use feature "switch"; +use lib '/data/Lacuna-Server/lib'; +use Lacuna::DB; +use Lacuna; +use Lacuna::Util qw(randint format_date); +use Getopt::Long; +$|=1; +our $quiet; +GetOptions( + 'quiet' => \$quiet, +); + +out('Started'); +my $start = time; + +out('Loading DB'); +our $db = Lacuna->db; + +out('Complete all ships being built'); +my $ships = $db->resultset('Lacuna::DB::Result::Ships')->search({ + task => 'Building', +}); +my $now = DateTime->now; +while (my $ship = $ships->next) { + $ship->update({ + task => 'Docked', + date_available => $now, + }); +} + +out('Zip all ships to their destination'); +my $ships = $db->resultset('Lacuna::DB::Result::Ships')->search({ + task => 'Travelling' +}); +while (my $ship = $ships->next) { + out('Zooming ship '.$ship->id); + $ship->update({ + date_available => $now, + }); +} + +out('Do a final tick of all planets'); +my $planets_rs = $db->resultset('Lacuna::DB::Result::Map::Body'); +my $planets = $planets_rs->search({ empire_id => {'!=' => 0} }); +while (my $planet = $planets->next) { + out('Ticking '.$planet->name); + eval{$planet->tick}; + my $reason = $@; + if (ref $reason eq 'ARRAY' && $reason->[0] eq -1) { + # this is an expected exception, it means one of the roles took over + } + elsif ( ref $reason eq 'ARRAY') { + out(sprintf("Ticking %s resulted in errno: %d, %s\n", $planet->name, $reason->[0], $reason->[1])); + } + elsif ( $reason ) { + out(sprintf("Ticking %s resulted in: %s\n", $planet->name, $reason)); + } +} + +$ships = $db->resultset('Lacuna::DB::Result::Ships')->search({},{ + group_by => [qw(body_id type task name speed stealth combat hold_size)], +}); + +my $finish = time; +out('Finished'); +out((($finish - $start)/60)." minutes have elapsed"); + + +############### +## SUBROUTINES +############### + +sub out { + my ($message) = @_; + unless ($quiet) { + say format_date(DateTime->now), " ", $message; + } +} + diff --git a/lib/Lacuna/DB/Result/Fleet/Barge.pm b/lib/Lacuna/DB/Result/Fleet/Barge.pm new file mode 100644 index 00000000..4149490e --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Barge.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::Barge; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 5 } ]; +use constant base_food_cost => 650; +use constant base_water_cost => 1900; +use constant base_energy_cost => 6100; +use constant base_ore_cost => 10300; +use constant base_time_cost => 5000; +use constant base_waste_cost => 900; +use constant base_speed => 1100; +use constant base_stealth => 2450; +use constant base_hold_size => 800; +use constant base_berth_level => 1; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining Intelligence SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CaptureWithSpies"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; +with "Lacuna::Role::Ship::Arrive::PickUpSpies"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Bleeder.pm b/lib/Lacuna/DB/Result/Fleet/Bleeder.pm new file mode 100644 index 00000000..af4cab2f --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Bleeder.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Bleeder; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 12 } ]; +use constant base_food_cost => 8000; +use constant base_water_cost => 21000; +use constant base_energy_cost => 69010; +use constant base_ore_cost => 95020; +use constant base_time_cost => 60 * 60 * 13; +use constant base_waste_cost => 12200; +use constant base_speed => 600; +use constant base_stealth => 2850; +use constant base_combat => 1700; +use constant base_hold_size => 0; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DeployBleeder"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/CargoShip.pm b/lib/Lacuna/DB/Result/Fleet/CargoShip.pm new file mode 100644 index 00000000..36711848 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/CargoShip.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::CargoShip; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 10 } ]; +use constant base_food_cost => 1200; +use constant base_water_cost => 3600; +use constant base_energy_cost => 12000; +use constant base_ore_cost => 20400; +use constant base_time_cost => 7200; +use constant base_waste_cost => 1500; +use constant base_speed => 1050; +use constant base_stealth => 1500; +use constant base_hold_size => 1700; +use constant base_berth_level => 5; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining Intelligence SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CaptureWithSpies"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; +with "Lacuna::Role::Ship::Arrive::PickUpSpies"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/ColonyShip.pm b/lib/Lacuna/DB/Result/Fleet/ColonyShip.pm new file mode 100644 index 00000000..41505e9a --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/ColonyShip.pm @@ -0,0 +1,30 @@ +package Lacuna::DB::Result::Fleet::ColonyShip; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Observatory', level => 5 } ]; +use constant base_food_cost => 45000; +use constant base_water_cost => 45000; +use constant base_energy_cost => 45000; +use constant base_ore_cost => 45000; +use constant base_time_cost => 60 * 60 * 24; +use constant base_waste_cost => 10000; +use constant base_combat => 1000; +use constant base_speed => 455; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => ['Colonization']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Uninhabited"; +with "Lacuna::Role::Ship::Send::SpendNextColonyCost"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::Colonize"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Detonator.pm b/lib/Lacuna/DB/Result/Fleet/Detonator.pm new file mode 100644 index 00000000..6e7cd68d --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Detonator.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::Detonator; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 1 } ]; +use constant base_food_cost => 6000; +use constant base_water_cost => 15600; +use constant base_energy_cost => 113600; +use constant base_ore_cost => 97200; +use constant base_time_cost => 86400; +use constant base_waste_cost => 25200; +use constant base_combat => 1850; +use constant base_speed => 1000; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::AsteroidStarUninhabited"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DestroyProbes"; +with "Lacuna::Role::Ship::Arrive::DestroyMinersExcavators"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Dory.pm b/lib/Lacuna/DB/Result/Fleet/Dory.pm new file mode 100644 index 00000000..c6419c74 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Dory.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::Dory; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 1 } ]; +use constant base_food_cost => 350; +use constant base_water_cost => 700; +use constant base_energy_cost => 3250; +use constant base_ore_cost => 5500; +use constant base_time_cost => 3800; +use constant base_waste_cost => 400; +use constant base_speed => 1250; +use constant base_stealth => 4100; +use constant base_hold_size => 400; +use constant base_berth_level => 1; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining Intelligence SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CaptureWithSpies"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; +with "Lacuna::Role::Ship::Arrive::PickUpSpies"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Drone.pm b/lib/Lacuna/DB/Result/Fleet/Drone.pm new file mode 100644 index 00000000..28069c9a --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Drone.pm @@ -0,0 +1,24 @@ +package Lacuna::DB::Result::Fleet::Drone; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Security', level => 1 } ]; +use constant base_food_cost => 250; +use constant base_water_cost => 650; +use constant base_energy_cost => 4050; +use constant base_ore_cost => 3550; +use constant base_time_cost => 3650; +use constant base_waste_cost => 1050; +use constant base_speed => 0; +use constant base_combat => 6000; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::NotAllowed"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Excavator.pm b/lib/Lacuna/DB/Result/Fleet/Excavator.pm new file mode 100644 index 00000000..2abf774e --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Excavator.pm @@ -0,0 +1,25 @@ +package Lacuna::DB::Result::Fleet::Excavator; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Archaeology', level => 11 } ]; +use constant base_food_cost => 3000; +use constant base_water_cost => 5000; +use constant base_energy_cost => 20000; +use constant base_ore_cost => 80000; +use constant base_time_cost => 8 * 60 * 60; +use constant base_waste_cost => 10000; +use constant base_speed => 1000; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant build_tags => ['Exploration']; + +with "Lacuna::Role::Ship::Send::AsteroidAndUninhabited"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DeployExcavator"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Fighter.pm b/lib/Lacuna/DB/Result/Fleet/Fighter.pm new file mode 100644 index 00000000..8f53cc36 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Fighter.pm @@ -0,0 +1,24 @@ +package Lacuna::DB::Result::Fleet::Fighter; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::PilotTraining', level => 1 } ]; +use constant base_food_cost => 1000; +use constant base_water_cost => 2600; +use constant base_energy_cost => 16200; +use constant base_ore_cost => 14200; +use constant base_time_cost => 60 * 60 * 4; +use constant base_waste_cost => 4200; +use constant base_combat => 4000; +use constant base_speed => 2000; +use constant pilotable => 1; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Body"; +with "Lacuna::Role::Ship::Arrive::Defend"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Freighter.pm b/lib/Lacuna/DB/Result/Fleet/Freighter.pm new file mode 100644 index 00000000..20ecde1a --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Freighter.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::Freighter; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 20 } ]; +use constant base_food_cost => 3600; +use constant base_water_cost => 10800; +use constant base_energy_cost => 36000; +use constant base_ore_cost => 61000; +use constant base_time_cost => 15000; +use constant base_waste_cost => 4800; +use constant base_speed => 900; +use constant base_stealth => 0; +use constant base_hold_size => 4000; +use constant base_berth_level => 15; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; + + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Galleon.pm b/lib/Lacuna/DB/Result/Fleet/Galleon.pm new file mode 100644 index 00000000..436b69cb --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Galleon.pm @@ -0,0 +1,26 @@ +package Lacuna::DB::Result::Fleet::Galleon; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 15 } ]; +use constant base_food_cost => 2500; +use constant base_water_cost => 7500; +use constant base_energy_cost => 25000; +use constant base_ore_cost => 40200; +use constant base_time_cost => 11200; +use constant base_waste_cost => 3200; +use constant base_speed => 1250; +use constant base_stealth => 0; +use constant base_hold_size => 1750; +use constant base_berth_level => 10; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/GasGiantSettlementPlatformShip.pm b/lib/Lacuna/DB/Result/Fleet/GasGiantSettlementPlatformShip.pm new file mode 100644 index 00000000..42e21e55 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/GasGiantSettlementPlatformShip.pm @@ -0,0 +1,26 @@ +package Lacuna::DB::Result::Fleet::GasGiantSettlementPlatformShip; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::GasGiantLab', level => 1 } ]; +use constant base_food_cost => 36000; +use constant base_water_cost => 90000; +use constant base_energy_cost => 340000; +use constant base_ore_cost => 250000; +use constant base_time_cost => 48000; +use constant base_waste_cost => 53000; +use constant base_speed => 500; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => ['Colonization']; + +with "Lacuna::Role::Ship::Send::GasGiant"; +with "Lacuna::Role::Ship::Arrive::AddGasGiantPlatform"; + + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Hulk.pm b/lib/Lacuna/DB/Result/Fleet/Hulk.pm new file mode 100644 index 00000000..017bdc88 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Hulk.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::Hulk; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 25 }]; +use constant base_food_cost => 7300; +use constant base_water_cost => 23000; +use constant base_energy_cost => 75000; +use constant base_ore_cost => 124000; +use constant base_time_cost => 20000; +use constant base_waste_cost => 11000; +use constant base_speed => 600; +use constant base_stealth => 0; +use constant base_hold_size => 7900; +use constant base_berth_level => 20; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; + + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/HulkFast.pm b/lib/Lacuna/DB/Result/Fleet/HulkFast.pm new file mode 100644 index 00000000..d08a8dee --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/HulkFast.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::HulkFast; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 25 }, + { class=> 'Lacuna::DB::Result::Building::Propulsion', level => 30 } ]; +use constant base_food_cost => 15000; +use constant base_water_cost => 30000; +use constant base_energy_cost => 500000; +use constant base_ore_cost => 1000000; +use constant base_time_cost => 43200; +use constant base_waste_cost => 100000; +use constant base_speed => 750; +use constant base_stealth => 0; +use constant base_hold_size => 10000; +use constant base_berth_level => 25; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; + + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/HulkHuge.pm b/lib/Lacuna/DB/Result/Fleet/HulkHuge.pm new file mode 100644 index 00000000..c57e6bea --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/HulkHuge.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::HulkHuge; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Trade', level => 30 } ]; +use constant base_food_cost => 90000; +use constant base_water_cost => 150000; +use constant base_energy_cost => 15000000; +use constant base_ore_cost => 10000000; +use constant base_time_cost => 256000; +use constant base_waste_cost => 1000000; +use constant base_speed => 350; +use constant base_stealth => 0; +use constant base_hold_size => 170100; +use constant base_berth_level => 30; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; + + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/MiningPlatformShip.pm b/lib/Lacuna/DB/Result/Fleet/MiningPlatformShip.pm new file mode 100644 index 00000000..c02f702f --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/MiningPlatformShip.pm @@ -0,0 +1,27 @@ +package Lacuna::DB::Result::Fleet::MiningPlatformShip; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Ore::Ministry', level => 1 }]; +use constant base_food_cost => 4800; +use constant base_water_cost => 14400; +use constant base_energy_cost => 96000; +use constant base_ore_cost => 81600; +use constant base_time_cost => 28800; +use constant base_waste_cost => 12000; +use constant base_combat => 600; +use constant base_speed => 600; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => ['Mining']; + +with "Lacuna::Role::Ship::Send::Asteroid"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DeployMiningPlatform"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/ObservatorySeeker.pm b/lib/Lacuna/DB/Result/Fleet/ObservatorySeeker.pm new file mode 100644 index 00000000..f516a4d2 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/ObservatorySeeker.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::ObservatorySeeker; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 10 }]; +use constant base_food_cost => 20000; +use constant base_water_cost => 50000; +use constant base_energy_cost => 170000; +use constant base_ore_cost => 200000; +use constant base_time_cost => 58500; +use constant base_waste_cost => 40000; +use constant base_speed => 1000; +use constant base_combat => 2500; +use constant base_stealth => 2700; +use constant target_building => ['Lacuna::DB::Result::Building::Observatory']; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DamageBuilding"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Placebo.pm b/lib/Lacuna/DB/Result/Fleet/Placebo.pm new file mode 100644 index 00000000..fd59e7bc --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Placebo.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::Placebo; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::CloakingLab', level => 5 }]; +use constant base_food_cost => 2000; +use constant base_water_cost => 2000; +use constant base_energy_cost => 4000; +use constant base_ore_cost => 4000; +use constant base_time_cost => 3600; +use constant base_waste_cost => 400; +use constant base_speed => 500; +use constant base_combat => 0; +use constant base_stealth => 2500; +use constant base_hold_size => 0; +use constant build_tags => [qw(War)]; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::Scuttle"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Placebo2.pm b/lib/Lacuna/DB/Result/Fleet/Placebo2.pm new file mode 100644 index 00000000..ef2a8ee3 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Placebo2.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Placebo2; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::CloakingLab', level => 10 }]; +use constant base_food_cost => 2000; +use constant base_water_cost => 2000; +use constant base_energy_cost => 5000; +use constant base_ore_cost => 5000; +use constant base_time_cost => 3600; +use constant base_waste_cost => 500; +use constant base_speed => 1000; +use constant base_combat => 0; +use constant base_stealth => 4000; +use constant base_hold_size => 0; +use constant build_tags => [qw(War)]; +use constant type_formatted => 'Placebo II'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::Scuttle"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Placebo3.pm b/lib/Lacuna/DB/Result/Fleet/Placebo3.pm new file mode 100644 index 00000000..ff95f603 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Placebo3.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Placebo3; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::CloakingLab', level => 15 }]; +use constant base_food_cost => 2000; +use constant base_water_cost => 2000; +use constant base_energy_cost => 6000; +use constant base_ore_cost => 6000; +use constant base_time_cost => 3600; +use constant base_waste_cost => 600; +use constant base_speed => 1500; +use constant base_combat => 0; +use constant base_stealth => 5500; +use constant base_hold_size => 0; +use constant build_tags => [qw(War)]; +use constant type_formatted => 'Placebo III'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::Scuttle"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Placebo4.pm b/lib/Lacuna/DB/Result/Fleet/Placebo4.pm new file mode 100644 index 00000000..32149049 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Placebo4.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Placebo4; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::CloakingLab', level => 20 }]; +use constant base_food_cost => 2000; +use constant base_water_cost => 2000; +use constant base_energy_cost => 7000; +use constant base_ore_cost => 7000; +use constant base_time_cost => 3600; +use constant base_waste_cost => 700; +use constant base_speed => 2000; +use constant base_combat => 0; +use constant base_stealth => 7000; +use constant base_hold_size => 0; +use constant build_tags => [qw(War)]; +use constant type_formatted => 'Placebo IV'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::Scuttle"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Placebo5.pm b/lib/Lacuna/DB/Result/Fleet/Placebo5.pm new file mode 100644 index 00000000..8e798b56 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Placebo5.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Placebo5; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::CloakingLab', level => 25 }]; +use constant base_food_cost => 2000; +use constant base_water_cost => 2000; +use constant base_energy_cost => 8000; +use constant base_ore_cost => 8000; +use constant base_time_cost => 3600; +use constant base_waste_cost => 800; +use constant base_speed => 2500; +use constant base_combat => 0; +use constant base_stealth => 8500; +use constant base_hold_size => 0; +use constant build_tags => [qw(War)]; +use constant type_formatted => 'Placebo V'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::Scuttle"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Placebo6.pm b/lib/Lacuna/DB/Result/Fleet/Placebo6.pm new file mode 100644 index 00000000..3d5e2fd6 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Placebo6.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Placebo6; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::CloakingLab', level => 30 }]; +use constant base_food_cost => 2000; +use constant base_water_cost => 2000; +use constant base_energy_cost => 9000; +use constant base_ore_cost => 9000; +use constant base_time_cost => 3600; +use constant base_waste_cost => 900; +use constant base_speed => 3000; +use constant base_combat => 0; +use constant base_stealth => 10000; +use constant base_hold_size => 0; +use constant build_tags => [qw(War)]; +use constant type_formatted => 'Placebo VI'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::Scuttle"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Probe.pm b/lib/Lacuna/DB/Result/Fleet/Probe.pm new file mode 100644 index 00000000..5dbffcd2 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Probe.pm @@ -0,0 +1,24 @@ +package Lacuna::DB::Result::Fleet::Probe; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::Observatory', level => 1 }]; +use constant base_food_cost => 100; +use constant base_water_cost => 300; +use constant base_energy_cost => 2000; +use constant base_ore_cost => 1700; +use constant base_time_cost => 3600; +use constant base_waste_cost => 500; +use constant base_speed => 5000; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant build_tags => [qw(Exploration Intelligence)]; + +with "Lacuna::Role::Ship::Send::Star"; +with "Lacuna::Role::Ship::Arrive::DeployProbe"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Scanner.pm b/lib/Lacuna/DB/Result/Fleet/Scanner.pm new file mode 100644 index 00000000..aa101d90 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Scanner.pm @@ -0,0 +1,27 @@ +package Lacuna::DB::Result::Fleet::Scanner; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::Intelligence', level => 5 }]; +use constant base_food_cost => 150; +use constant base_water_cost => 250; +use constant base_energy_cost => 2500; +use constant base_ore_cost => 2900; +use constant base_time_cost => 3600; +use constant base_waste_cost => 520; +use constant base_speed => 3000; +use constant base_combat => 200; +use constant base_stealth => 1850; +use constant base_hold_size => 0; +use constant build_tags => [qw(Exploration Intelligence)]; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::MaybeHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::ScanSurface"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Scow.pm b/lib/Lacuna/DB/Result/Fleet/Scow.pm new file mode 100644 index 00000000..d1a6a1ca --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Scow.pm @@ -0,0 +1,27 @@ +package Lacuna::DB::Result::Fleet::Scow; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Waste::Sequestration', level => 10 } ]; +use constant base_food_cost => 2000; +use constant base_water_cost => 5200; +use constant base_energy_cost => 32400; +use constant base_ore_cost => 28400; +use constant base_time_cost => 14600; +use constant base_waste_cost => 8400; +use constant base_speed => 420; +use constant base_combat => 500; +use constant base_stealth => 0; +use constant base_hold_size => 2000; +use constant build_tags => [qw(War WasteChain)]; + +with "Lacuna::Role::Ship::Send::PlanetAndStar"; +with "Lacuna::Role::Ship::Send::MaybeHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DumpWaste"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/ScowFast.pm b/lib/Lacuna/DB/Result/Fleet/ScowFast.pm new file mode 100644 index 00000000..8a2d8c78 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/ScowFast.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::ScowFast; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [{ class=> 'Lacuna::DB::Result::Building::Waste::Sequestration', level => 25 }, + { class=> 'Lacuna::DB::Result::Building::Propulsion', level => 25 } ]; +use constant base_food_cost => 3000; +use constant base_water_cost => 10000; +use constant base_energy_cost => 100000; +use constant base_ore_cost => 60000; +use constant base_time_cost => 21600; +use constant base_waste_cost => 25000; +use constant base_speed => 700; +use constant base_combat => 500; +use constant base_stealth => 0; +use constant base_hold_size => 2000; +use constant base_berth_level => 20; +use constant build_tags => [qw(War WasteChain)]; + +with "Lacuna::Role::Ship::Send::PlanetAndStar"; +with "Lacuna::Role::Ship::Send::MaybeHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DumpWaste"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/ScowLarge.pm b/lib/Lacuna/DB/Result/Fleet/ScowLarge.pm new file mode 100644 index 00000000..55bd8e5a --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/ScowLarge.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::ScowLarge; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Waste::Sequestration', level => 20 } ]; +use constant base_food_cost => 10000; +use constant base_water_cost => 32000; +use constant base_energy_cost => 170000; +use constant base_ore_cost => 120000; +use constant base_time_cost => 32000; +use constant base_waste_cost => 50000; +use constant base_speed => 325; +use constant base_combat => 600; +use constant base_stealth => 0; +use constant base_hold_size => 12000; +use constant base_berth_level => 15; +use constant build_tags => [qw(War WasteChain)]; + +with "Lacuna::Role::Ship::Send::PlanetAndStar"; +with "Lacuna::Role::Ship::Send::MaybeHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DumpWaste"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/ScowMega.pm b/lib/Lacuna/DB/Result/Fleet/ScowMega.pm new file mode 100644 index 00000000..84443cd2 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/ScowMega.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::ScowMega; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Waste::Sequestration', level => 30 } ]; +use constant base_food_cost => 60000; +use constant base_water_cost => 180000; +use constant base_energy_cost => 6000000; +use constant base_ore_cost => 1500000; +use constant base_time_cost => 98000; +use constant base_waste_cost => 25000000; +use constant base_speed => 100; +use constant base_combat => 0; +use constant base_stealth => 0; +use constant base_hold_size => 300000; +use constant base_berth_level => 25; +use constant build_tags => [qw(War WasteChain)]; + +with "Lacuna::Role::Ship::Send::PlanetAndStar"; +with "Lacuna::Role::Ship::Send::MaybeHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DumpWaste"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SecurityMinistrySeeker.pm b/lib/Lacuna/DB/Result/Fleet/SecurityMinistrySeeker.pm new file mode 100644 index 00000000..4b7d61fa --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SecurityMinistrySeeker.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::SecurityMinistrySeeker; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 20 } ]; +use constant base_food_cost => 20000; +use constant base_water_cost => 50000; +use constant base_energy_cost => 180000; +use constant base_ore_cost => 200000; +use constant base_time_cost => 58500; +use constant base_waste_cost => 40000; +use constant base_speed => 1000; +use constant base_combat => 3500; +use constant base_stealth => 2700; +use constant target_building => ['Lacuna::DB::Result::Building::Security','Lacuna::DB::Result::Building::Module::PoliceStation']; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DamageBuilding"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/ShortRangeColonyShip.pm b/lib/Lacuna/DB/Result/Fleet/ShortRangeColonyShip.pm new file mode 100644 index 00000000..70a3545f --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/ShortRangeColonyShip.pm @@ -0,0 +1,31 @@ +package Lacuna::DB::Result::Fleet::ShortRangeColonyShip; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Observatory', level => 3 } ]; +use constant base_food_cost => 15000; +use constant base_water_cost => 15000; +use constant base_energy_cost => 15000; +use constant base_ore_cost => 15000; +use constant base_time_cost => 60 * 60 * 8; +use constant base_waste_cost => 7000; +use constant base_combat => 1000; +use constant base_speed => 700; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => ['Colonization']; + +with "Lacuna::Role::Ship::Send::Range"; +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Uninhabited"; +with "Lacuna::Role::Ship::Send::SpendNextColonyCost"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::Colonize"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SmugglerShip.pm b/lib/Lacuna/DB/Result/Fleet/SmugglerShip.pm new file mode 100644 index 00000000..c1a85463 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SmugglerShip.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::SmugglerShip; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::CloakingLab', level => 1 } ]; +use constant base_food_cost => 1500; +use constant base_water_cost => 3900; +use constant base_energy_cost => 27000; +use constant base_ore_cost => 16800; +use constant base_time_cost => 28800; +use constant base_waste_cost => 1800; +use constant base_speed => 1700; +use constant base_stealth => 5000; +use constant base_hold_size => 520; +use constant base_berth_level => 10; +use constant pilotable => 1; +use constant build_tags => [qw(Trade Mining Intelligence SupplyChain)]; + +with "Lacuna::Role::Ship::Send::UsePush"; +with "Lacuna::Role::Ship::Arrive::CaptureWithSpies"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; +with "Lacuna::Role::Ship::Arrive::PickUpSpies"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Snark.pm b/lib/Lacuna/DB/Result/Fleet/Snark.pm new file mode 100644 index 00000000..3fbf66ce --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Snark.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Snark; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 5 } ]; +use constant base_food_cost => 18000; +use constant base_water_cost => 46800; +use constant base_energy_cost => 145000; +use constant base_ore_cost => 195030; +use constant base_time_cost => 60 * 60 * 16; +use constant base_waste_cost => 39600; +use constant base_speed => 1000; +use constant base_stealth => 2400; +use constant base_combat => 2000; +use constant base_hold_size => 0; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DamageBuilding"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Snark2.pm b/lib/Lacuna/DB/Result/Fleet/Snark2.pm new file mode 100644 index 00000000..cd24da8a --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Snark2.pm @@ -0,0 +1,31 @@ +package Lacuna::DB::Result::Fleet::Snark2; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 18 } ]; +use constant base_food_cost => 37000; +use constant base_water_cost => 64600; +use constant base_energy_cost => 194000; +use constant base_ore_cost => 252230; +use constant base_time_cost => 58400; +use constant base_waste_cost => 59500; +use constant base_speed => 1000; +use constant base_stealth => 2600; +use constant base_combat => 4000; +use constant base_hold_size => 0; +use constant build_tags => ['War']; +use constant type_formatted => 'Snark II'; +use constant splash_radius => 1; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DamageBuilding"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Snark3.pm b/lib/Lacuna/DB/Result/Fleet/Snark3.pm new file mode 100644 index 00000000..62db2a19 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Snark3.pm @@ -0,0 +1,31 @@ +package Lacuna::DB::Result::Fleet::Snark3; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 25 } ]; +use constant base_food_cost => 47000; +use constant base_water_cost => 84600; +use constant base_energy_cost => 224000; +use constant base_ore_cost => 352230; +use constant base_time_cost => 58400; +use constant base_waste_cost => 69500; +use constant base_speed => 1000; +use constant base_stealth => 3000; +use constant base_combat => 5000; +use constant base_hold_size => 0; +use constant build_tags => ['War']; +use constant type_formatted => 'Snark III'; +use constant splash_radius => 2; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DamageBuilding"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SpacePortSeeker.pm b/lib/Lacuna/DB/Result/Fleet/SpacePortSeeker.pm new file mode 100644 index 00000000..0f53ee1b --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SpacePortSeeker.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::SpacePortSeeker; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 15 } ]; +use constant base_food_cost => 20000; +use constant base_water_cost => 50000; +use constant base_energy_cost => 160000; +use constant base_ore_cost => 200000; +use constant base_time_cost => 58500; +use constant base_waste_cost => 40000; +use constant base_speed => 1000; +use constant base_combat => 3000; +use constant base_stealth => 2700; +use constant target_building => ['Lacuna::DB::Result::Building::SpacePort']; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DamageBuilding"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SpaceStation.pm b/lib/Lacuna/DB/Result/Fleet/SpaceStation.pm new file mode 100644 index 00000000..fc809839 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SpaceStation.pm @@ -0,0 +1,31 @@ +package Lacuna::DB::Result::Fleet::SpaceStation; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Embassy', level => 20 } ]; +use constant base_food_cost => 8000000; +use constant base_water_cost => 8000000; +use constant base_energy_cost => 8000000; +use constant base_ore_cost => 8000000; +use constant base_time_cost => 60 * 60 * 72; +use constant base_waste_cost => 1000000; +use constant base_speed => 10; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => [qw(War Intelligence)]; +use constant type_formatted => 'Space Station Hull'; + +with "Lacuna::Role::Ship::Send::Planet"; +with 'Lacuna::Role::Ship::Send::Uninhabited'; +with 'Lacuna::Role::Ship::Send::MemberOfAlliance'; +with "Lacuna::Role::Ship::Send::SpendNextColonyCost"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::ConvertToStation"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SpyPod.pm b/lib/Lacuna/DB/Result/Fleet/SpyPod.pm new file mode 100644 index 00000000..474a2933 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SpyPod.pm @@ -0,0 +1,32 @@ +package Lacuna::DB::Result::Fleet::SpyPod; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Espionage', level => 1 } ]; +use constant base_food_cost => 200; +use constant base_water_cost => 600; +use constant base_energy_cost => 4000; +use constant base_ore_cost => 3400; +use constant base_time_cost => 3600; +use constant base_waste_cost => 1000; +use constant base_speed => 2000; +use constant base_stealth => 7000; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => ['Intelligence']; +use constant max_occupants => 1; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::LoadWithSpies"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::CaptureWithSpies"; +with "Lacuna::Role::Ship::Arrive::CargoExchange"; +with "Lacuna::Role::Ship::Arrive::Scuttle"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SpyShuttle.pm b/lib/Lacuna/DB/Result/Fleet/SpyShuttle.pm new file mode 100644 index 00000000..59b8bfa1 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SpyShuttle.pm @@ -0,0 +1,31 @@ +package Lacuna::DB::Result::Fleet::SpyShuttle; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Espionage', level => 15 } ]; +use constant base_food_cost => 750; +use constant base_water_cost => 2300; +use constant base_energy_cost => 15000; +use constant base_ore_cost => 13000; +use constant base_time_cost => 7200; +use constant base_waste_cost => 5000; +use constant base_speed => 2000; +use constant base_stealth => 6200; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => ['Intelligence']; +use constant max_occupants => 4; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::LoadWithSpies"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::CaptureWithSpies"; +with "Lacuna::Role::Ship::Arrive::Orbit"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Stake.pm b/lib/Lacuna/DB/Result/Fleet/Stake.pm new file mode 100644 index 00000000..90fa6759 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Stake.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Stake; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Observatory', level => 10 } ]; +use constant base_food_cost => 3000; +use constant base_water_cost => 4000; +use constant base_energy_cost => 10000; +use constant base_ore_cost => 10000; +use constant base_time_cost => 60 * 60 * 2; +use constant base_waste_cost => 3500; +use constant base_speed => 3000; +use constant base_combat => 250; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant pilotable => 0; +use constant build_tags => ['Colonization']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Uninhabited"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::StakeAClaim"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SupplyPod.pm b/lib/Lacuna/DB/Result/Fleet/SupplyPod.pm new file mode 100644 index 00000000..5ddd165e --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SupplyPod.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Fleet::SupplyPod; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::PlanetaryCommand', level => 10 } ]; +use constant base_food_cost => 1800; +use constant base_water_cost => 1900; +use constant base_energy_cost => 4500; +use constant base_ore_cost => 4500; +use constant base_time_cost => 60 * 60 * 2; +use constant base_waste_cost => 5000; +use constant base_speed => 1000; +use constant base_stealth => 0; +use constant base_hold_size => 400; +use constant pilotable => 0; +use constant build_tags => [qw(Colonization)]; +use constant supply_pod_level => 5; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::LoadSupplyPod"; +with "Lacuna::Role::Ship::Arrive::DeploySupplyPod"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SupplyPod2.pm b/lib/Lacuna/DB/Result/Fleet/SupplyPod2.pm new file mode 100644 index 00000000..36ff6d8b --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SupplyPod2.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::SupplyPod2; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::PlanetaryCommand', level => 15 } ]; +use constant base_food_cost => 29000; +use constant base_water_cost => 30000; +use constant base_energy_cost => 74000; +use constant base_ore_cost => 74000; +use constant base_time_cost => 60 * 60 * 4; +use constant base_waste_cost => 30000; +use constant base_speed => 1000; +use constant base_stealth => 0; +use constant base_hold_size => 900; +use constant pilotable => 0; +use constant build_tags => [qw(Colonization)]; +use constant supply_pod_level => 10; +use constant type_formatted => 'Supply Pod II'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::LoadSupplyPod"; +with "Lacuna::Role::Ship::Arrive::DeploySupplyPod"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SupplyPod3.pm b/lib/Lacuna/DB/Result/Fleet/SupplyPod3.pm new file mode 100644 index 00000000..c895ea91 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SupplyPod3.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::SupplyPod3; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::PlanetaryCommand', level => 20 } ]; +use constant base_food_cost => 480000; +use constant base_water_cost => 500000; +use constant base_energy_cost => 1200000; +use constant base_ore_cost => 1200000; +use constant base_time_cost => 60 * 60 * 6; +use constant base_waste_cost => 450000; +use constant base_speed => 1000; +use constant base_stealth => 0; +use constant base_hold_size => 2000; +use constant pilotable => 0; +use constant build_tags => [qw(Colonization)]; +use constant supply_pod_level => 15; +use constant type_formatted => 'Supply Pod III'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::LoadSupplyPod"; +with "Lacuna::Role::Ship::Arrive::DeploySupplyPod"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/SupplyPod4.pm b/lib/Lacuna/DB/Result/Fleet/SupplyPod4.pm new file mode 100644 index 00000000..5d0ef75a --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/SupplyPod4.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::SupplyPod4; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::PlanetaryCommand', level => 25 } ]; +use constant base_food_cost => 8000000; +use constant base_water_cost => 8500000; +use constant base_energy_cost => 20000000; +use constant base_ore_cost => 20000000; +use constant base_time_cost => 60 * 60 * 8; +use constant base_waste_cost => 2000000; +use constant base_speed => 1000; +use constant base_stealth => 0; +use constant base_hold_size => 3800; +use constant pilotable => 0; +use constant build_tags => [qw(Colonization)]; +use constant supply_pod_level => 20; +use constant type_formatted => 'Supply Pod IV'; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::LoadSupplyPod"; +with "Lacuna::Role::Ship::Arrive::DeploySupplyPod"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Surveyor.pm b/lib/Lacuna/DB/Result/Fleet/Surveyor.pm new file mode 100644 index 00000000..838f2b58 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Surveyor.pm @@ -0,0 +1,27 @@ +package Lacuna::DB::Result::Fleet::Surveyor; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::Intelligence', level => 10 } ]; +use constant base_food_cost => 1500; +use constant base_water_cost => 2500; +use constant base_energy_cost => 25000; +use constant base_ore_cost => 29000; +use constant base_time_cost => 60 * 60 * 6; +use constant base_waste_cost => 5200; +use constant base_speed => 3000; +use constant base_combat => 1000; +use constant base_stealth => 3000; +use constant base_hold_size => 0; +use constant build_tags => [qw(Exploration Intelligence)]; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::MaybeHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::SurveySurface"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Sweeper.pm b/lib/Lacuna/DB/Result/Fleet/Sweeper.pm new file mode 100644 index 00000000..97329ed1 --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Sweeper.pm @@ -0,0 +1,27 @@ +package Lacuna::DB::Result::Fleet::Sweeper; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 16 } ]; +use constant base_food_cost => 5000; +use constant base_water_cost => 12000; +use constant base_energy_cost => 70000; +use constant base_ore_cost => 75000; +use constant base_time_cost => 60 * 60 * 7; +use constant base_waste_cost => 20000; +use constant base_combat => 8100; +use constant base_speed => 2600; +use constant base_stealth => 2800; +use constant pilotable => 1; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Body"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/TerraformingPlatformShip.pm b/lib/Lacuna/DB/Result/Fleet/TerraformingPlatformShip.pm new file mode 100644 index 00000000..de1d8faa --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/TerraformingPlatformShip.pm @@ -0,0 +1,25 @@ +package Lacuna::DB::Result::Fleet::TerraformingPlatformShip; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::TerraformingLab', level => 1 } ]; +use constant base_food_cost => 96000; +use constant base_water_cost => 180000; +use constant base_energy_cost => 310000; +use constant base_ore_cost => 226000; +use constant base_time_cost => 45000; +use constant base_waste_cost => 45000; +use constant base_speed => 550; +use constant base_stealth => 0; +use constant base_hold_size => 0; +use constant pilotable => 1; +use constant build_tags => ['Colonization']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Arrive::AddTerraformingPlatform"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Fleet/Thud.pm b/lib/Lacuna/DB/Result/Fleet/Thud.pm new file mode 100644 index 00000000..5949b0dc --- /dev/null +++ b/lib/Lacuna/DB/Result/Fleet/Thud.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Fleet::Thud; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Fleet'; + +use constant prereq => [ { class=> 'Lacuna::DB::Result::Building::MunitionsLab', level => 3 } ]; +use constant base_food_cost => 7000; +use constant base_water_cost => 8000; +use constant base_energy_cost => 23000; +use constant base_ore_cost => 45000; +use constant base_time_cost => 60 * 60 * 2; +use constant base_waste_cost => 8400; +use constant base_speed => 700; +use constant base_stealth => 1600; +use constant base_combat => 2100; +use constant base_hold_size => 0; +use constant build_tags => ['War']; + +with "Lacuna::Role::Ship::Send::Planet"; +with "Lacuna::Role::Ship::Send::Inhabited"; +with "Lacuna::Role::Ship::Send::NotIsolationist"; +with "Lacuna::Role::Ship::Send::IsHostile"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; +with "Lacuna::Role::Ship::Arrive::DeploySmolderingCrater"; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); -- 2.51.2 From f8f96cbfb73fafe043833a9d5de89250cf8168c3 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 3 Jun 2012 07:04:33 -0400 Subject: [PATCH 084/105] Withdraw all trades before converting ships to fleets --- bin/convert_ships_to_fleets.pl | 9 ++++++++- lib/Lacuna/RPC/Building/SpacePort.pm | 22 ---------------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/bin/convert_ships_to_fleets.pl b/bin/convert_ships_to_fleets.pl index 9c3c3c9c..f4723ef5 100644 --- a/bin/convert_ships_to_fleets.pl +++ b/bin/convert_ships_to_fleets.pl @@ -41,6 +41,12 @@ while (my $ship = $ships->next) { }); } +out('Withdraw all trades'); +my $trades = $db->resultset('Lacuna::DB::Result::Market')->search; +while (my $trade = $trades->next) { + $trade->withdraw($trade->body); +} + out('Do a final tick of all planets'); my $planets_rs = $db->resultset('Lacuna::DB::Result::Map::Body'); my $planets = $planets_rs->search({ empire_id => {'!=' => 0} }); @@ -59,8 +65,9 @@ while (my $planet = $planets->next) { } } +out('Group ships into fleets'); $ships = $db->resultset('Lacuna::DB::Result::Ships')->search({},{ - group_by => [qw(body_id type task name speed stealth combat hold_size)], + group_by => [qw(body_id type task name speed stealth combat hold_size berth_level foreign_body_id foreign_star_id)], }); my $finish = time; diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 76e3776f..f2267570 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -230,11 +230,7 @@ sub find_arrival { my $second = $arrival_params->{second}; if (not defined $day or $day < 1 or $day > $mon_end->day) { -<<<<<<< HEAD confess [1009, "Invalid day. [$day][".Dumper($arrival_params)."]"]; -======= - confess [1009, 'Invalid day.']; ->>>>>>> Started adding new fleet action API calls } if (not defined $hour or $hour != int($hour) or $hour < 0 or $hour > 23) { confess [1002, 'Invalid hour.']; @@ -242,13 +238,8 @@ sub find_arrival { if (not defined $minute or $minute != int($minute) or $minute < 0 or $minute > 59) { confess [1002, 'Invalid minute.']; } -<<<<<<< HEAD if (not defined $second or $second != 0 and $second != 15 and $second != 30 and $second != 45) { confess [1002, 'Invalid second. Must be 0, 15, 30 or 45']; -======= - if (not defined $second or $second != int($second) or $second < 0 or $second > 59) { - confess [1002, 'Invalid second.']; ->>>>>>> Started adding new fleet action API calls } if ($day < $now->day) { # Then it must be a day next month @@ -268,11 +259,7 @@ sub find_arrival { } sub send_ship_types { -<<<<<<< HEAD my ($self, $session_id, $body_id, $target_params, $type_params, $arrival_params) = @_; -======= - my ($self, $session_id, $from_body_id, $target_params, $type_params, $arrival) = @_; ->>>>>>> Started adding new fleet action API calls my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); @@ -322,12 +309,7 @@ sub send_ship_types { $do_captcha_check = 1; } foreach my $ship (@ships) { -<<<<<<< HEAD $ship_ref->{$ship->id} = $ship; -======= - my $hash = "${type}#${speed}#${stealth}#${combat}"; - $ship_ref->{$hash} = $ship; ->>>>>>> Started adding new fleet action API calls } } if ($do_captcha_check) { @@ -338,11 +320,7 @@ sub send_ship_types { $ship->fleet_speed(1); $ship->send(target => $target, arrival => $arrival); } -<<<<<<< HEAD return $self->get_fleet_for($session_id, $body_id, $target_params); -======= - ->>>>>>> Started adding new fleet action API calls } sub send_fleet { -- 2.51.2 From b8790e242edb13a72138dcb6d142032ee68414bd Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 5 Jun 2012 10:16:06 -0600 Subject: [PATCH 085/105] More issues with true/false --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 8a56d25b..bdfb984b 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -154,11 +154,19 @@ sub replace_excav { # Check to see if excavs available my $avail = Lacuna->db->resultset('Lacuna::DB::Result::Ships') ->search({type=>'excavator', task=>'Docked',body_id=>$self->body_id}); - if ($avail) { - my $count = $avail->count; - my $ship = $avail->next; # Just grab first one - eval { $ship->can_send_to_target($body) }; - my $reason = $@; + my $count = $avail->count; + if ($count > 0) { + my $ship; + my $reason = "No Ship available"; + if ($ship = $avail->next) { # Just grab first one + my $ok = eval { $ship->can_send_to_target($body) }; + if ($ok) { + $reason = ""; + } + else { + $reason = $@; + } + } if ($reason) { if (ref $reason eq 'ARRAY') { $reason = join(":", @{$reason}); -- 2.51.2 From 222e4ca63f84b8a4b6ffd7ac19d7e6300e66be09 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Tue, 5 Jun 2012 22:02:47 -0400 Subject: [PATCH 086/105] Remove memory leak on Space Station modules --- lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm index 80050535..955d89e9 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm @@ -22,10 +22,6 @@ sub _build_parliament { my ($self) = @_; my ($parliament) = grep {$_->class =~ /Parliament$/} @{$self->building_cache}; - - if (defined $parliament) { - $parliament->body($self); - } return $parliament; } @@ -73,8 +69,6 @@ has command => ( sub _build_command { my ($self) = @_; my ($building) = grep {$_->class =~ /StationCommand$/} @{$self->building_cache}; - return undef unless defined $building; - $building->body($self); return $building; } -- 2.51.2 From fc2ea5349f680d03fdf79267ffe3ba333970ec2d Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 5 Jun 2012 23:27:53 -0600 Subject: [PATCH 087/105] delete_buildings wasn't cleaning off buildings. --- bin/puppet/setup_colony.pl | 1 + lib/Lacuna/AI.pm | 6 ++- lib/Lacuna/AI/Saben.pm | 2 + lib/Lacuna/DB/Result/Map/Body/Planet.pm | 37 +++++++++++-------- lib/Lacuna/RPC/Building/BlackHoleGenerator.pm | 3 +- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/bin/puppet/setup_colony.pl b/bin/puppet/setup_colony.pl index 812038e2..3267665c 100755 --- a/bin/puppet/setup_colony.pl +++ b/bin/puppet/setup_colony.pl @@ -59,6 +59,7 @@ our $quiet; say "Adding to ".$body->name; for my $build (@$builds) { + next if ($build->{level} < 1 or $build->{level} > 30); my ($x, $y) = $body->find_free_space; # next if $y > -1; my $bld = Lacuna->db->resultset('Lacuna::DB::Result::Building')->new({ diff --git a/lib/Lacuna/AI.pm b/lib/Lacuna/AI.pm index 7f4fcc66..749e764c 100644 --- a/lib/Lacuna/AI.pm +++ b/lib/Lacuna/AI.pm @@ -58,7 +58,8 @@ sub create_empire { my $empire = $db->resultset('Lacuna::DB::Result::Empire')->new(\%attributes)->insert; my $zone = $db->resultset('Lacuna::DB::Result::Map::Body')->get_column('zone')->max; my $home = $self->viable_colonies->search({zone => $zone},{rows=>1})->single; - $home->delete_buildings(@{$home->building_cache}); + my @to_demolish = @{$home->building_cache}; + $home->delete_buildings(\@to_demolish); $empire->found($home); $self->build_colony($home); return $empire; @@ -149,7 +150,8 @@ sub add_colonies { my $body = $self->viable_colonies->search({zone => $zone},{rows=>1})->single; if (defined $body) { say 'Clearing '.$body->name; - $body->delete_buildings(@{$body->building_cache}); + my @to_demolish = @{$body->building_cache}; + $body->delete_buildings(\@to_demolish); say 'Colonizing '.$body->name; $body->found_colony($empire); $self->build_colony($body); diff --git a/lib/Lacuna/AI/Saben.pm b/lib/Lacuna/AI/Saben.pm index 947e4ee6..0523da3e 100644 --- a/lib/Lacuna/AI/Saben.pm +++ b/lib/Lacuna/AI/Saben.pm @@ -127,6 +127,8 @@ sub destroy_world { )->single; if (defined $target) { say "Found ".$target->name; + my @to_demolish = @{$target->building_cache}; + $target->delete_buildings(\@to_demolish); $target->update({ class => 'Lacuna::DB::Result::Map::Body::Asteroid::A'.randint(1,21), size => randint(1,10), diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 9915b421..783cead2 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -33,27 +33,32 @@ sub _build_plan_cache { } sub delete_building { - my ($self, $building) = @_; + my ($self, $building) = @_; - my $i = 0; - BUILDING: - foreach my $b (@{$self->building_cache}) { - if ($b->id == $building->id) { - my @buildings = splice(@{$self->building_cache}, $i, 1); - $self->building_cache(\@buildings); - $b->delete; - last BUILDING; - } - $i++; + my $i = 0; + BUILDING: + foreach my $b (@{$self->building_cache}) { + if ($b->id == $building->id) { + my @buildings = splice(@{$self->building_cache}, $i, 1); + $self->building_cache(\@buildings); +# $b->delete; + last BUILDING; } + $i++; + } + $self->update; } sub delete_buildings { - my ($self, $buildings) = @_; - - foreach my $building (@$buildings) { - $self->delete_building($building); - } + my ($self, $buildings) = @_; + + foreach my $building (@$buildings) { + $self->delete_building($building); + $building->delete; + } + $self->needs_recalc(1); + $self->needs_surface_refresh(1); + $self->update; } sub surface { diff --git a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm index 164e024c..db49fdf6 100644 --- a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm +++ b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm @@ -562,7 +562,8 @@ sub bhg_make_asteroid { my ($building, $body) = @_; my $old_class = $body->class; my $old_size = $body->size; - $body->delete_buildings(@{$body->building_cache}); + my @to_demolish = @{$body->building_cache}; + $body->delete_buildings(\@to_demolish); my $new_size = int($building->level/5); $new_size = 10 if $new_size > 10; $body->update({ -- 2.51.2 From f9495f523d3928c6858aa0784c2d53569dd3da90 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Wed, 6 Jun 2012 07:59:58 -0400 Subject: [PATCH 088/105] Back-end support for fleet actions. --- lib/Lacuna.pm | 2 +- var/upgrades/{3.fleet.sql => 3.0854.sql} | 0 var/www/public/changes.txt | 3 +++ 3 files changed, 4 insertions(+), 1 deletion(-) rename var/upgrades/{3.fleet.sql => 3.0854.sql} (100%) diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index f6d62717..93891ec1 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0853; +our $VERSION = 3.0854; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1}); diff --git a/var/upgrades/3.fleet.sql b/var/upgrades/3.0854.sql similarity index 100% rename from var/upgrades/3.fleet.sql rename to var/upgrades/3.0854.sql diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index ee86dadc..1d9f3ce6 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,6 @@ +3.0854: + - Add: Backend support only for fleet actions. No changes to gameplay at this time. + 3.0853: - Mod: Excavator destruction will trigger a replacement excavator to be sent if available. - Add: Hooks for UI for excavator replacement added. (UI being updated soon.) -- 2.51.2 From e04c0ac186fd04990c1e10add34d4e28c768665d Mon Sep 17 00:00:00 2001 From: lemming552 Date: Wed, 6 Jun 2012 12:23:39 -0600 Subject: [PATCH 089/105] Check to make sure building over level 1 before stealing. --- lib/Lacuna/DB/Result/Spies.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 81bc9337..833c0343 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -2142,6 +2142,7 @@ sub steal_building { rand() <=> rand() } grep { + ($_->level > 1) and ($_->class ne 'Lacuna::DB::Result::Building::Permanent::EssentiaVein') and ($_->class ne 'Lacuna::DB::Result::Building::Permanent::TheDillonForge') and ($_->class ne 'Lacuna::DB::Result::Building::DeployedBleeder') -- 2.51.2 From b9295c129fd3e5dfb5876d731adf6754827affa4 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Wed, 6 Jun 2012 15:19:03 -0400 Subject: [PATCH 090/105] SQL to delete abandoned permanent buildings --- var/upgrades/3.0854.sql | 2 ++ var/www/public/changes.txt | 1 + 2 files changed, 3 insertions(+) diff --git a/var/upgrades/3.0854.sql b/var/upgrades/3.0854.sql index da71e190..36918486 100644 --- a/var/upgrades/3.0854.sql +++ b/var/upgrades/3.0854.sql @@ -29,3 +29,5 @@ create table fleet ( constraint wc_f_foreign_star_id foreign key (foreign_star_id) references star (id) ); +delete building from body,building where building.body_id=body.id and building.class not like "%Perm%" and body.empire_id is null; + diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 1d9f3ce6..3cc0a2dd 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,5 +1,6 @@ 3.0854: - Add: Backend support only for fleet actions. No changes to gameplay at this time. + - Fix: None-permanent buildings on abandoned planets have been cleared. 3.0853: - Mod: Excavator destruction will trigger a replacement excavator to be sent if available. -- 2.51.2 From 657b5fb14f2737963e10ff9a23b294fa8722a1ba Mon Sep 17 00:00:00 2001 From: lemming552 Date: Fri, 8 Jun 2012 17:29:44 -0600 Subject: [PATCH 091/105] More antifarming. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 92 +++++++++++--------- 1 file changed, 50 insertions(+), 42 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index bdfb984b..80e2e5c5 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -346,51 +346,59 @@ sub found_plan { } sub found_artifact { - my ($self, $body, $level) = @_; + my ($self, $body, $amlevel) = @_; - my $plan_types = plans_of_type(); - my $artifacts; - foreach my $building (@{$body->building_cache}) { - unless ( grep { $building->class eq $_ } @{$plan_types->{disallow}}) { - push @{$artifacts}, $building; + my $plan_types = plans_of_type(); + my $artifacts; + foreach my $building (@{$body->building_cache}) { + unless ( grep { $building->class eq $_ } @{$plan_types->{disallow}}) { + push @{$artifacts}, $building; + } + } + return (0,0,"Nothing") unless (defined($artifacts)); + my $select = random_element($artifacts); + my $class; my $plan_level; my $plus = 0; my $name; my $bld_destroy; + if ($amlevel > $select->level and randint(1, int(3 * $amlevel/2)) >= $select->level) { + $class = $select->class; + $plan_level = 1; + $plus = int( ($select->level - 1) * 3/5); #Max doable would be 1+17 + $name = $select->name; + $bld_destroy = 100; + } + elsif (randint(1,2) == 1) { + $class = $select->class; + if ($select->level == 1 and (randint(0,99) < 50) ) { + $plan_level = 0; + $bld_destroy = 100; + $name = "Nothing"; + } + else { + $plan_level = 1; + $bld_destroy = 10; + $name = $select->name; + } + $plus = 0; + } + else { + $class = $select->class; + $plan_level = randint(1,$amlevel); # Slight chance of getting a level 30 plan. + $plan_level = $select->level if ($plan_level > $select->level); + $plus = 0; + $name = $select->name; + $bld_destroy = 35; + } + $plan_level = 30 if ($plan_level > 30); + $plus = 30 if ($plus > 30); + $self->body->add_plan($class, $plan_level, $plus) if ($plan_level >= 1); + if ($select->level == 1 or randint(0,99) < $bld_destroy) { + $select->delete; + } + else { + $select->level($select->level - 1); + $select->update; } - } - return (0,0,"Nothing") unless (defined($artifacts)); - my $select = random_element($artifacts); - my $class; my $lvl; my $plus; my $name; my $bld_destroy; - if ($level > $select->level and randint(1, int(3 * $level/2)) >= $select->level) { - $class = $select->class; - $lvl = 1; - $plus = int( ($select->level - 1) * 2/3); #Max doable would be 1+18 - $name = $select->name; - $bld_destroy = 100; - } - elsif (randint(1,2) == 1) { - $class = $select->class; - $lvl = 1; - $plus = 0; - $name = $select->name; - $bld_destroy = 10; - } - else { - $class = $select->class; - $lvl = randint(1,$select->level); # Slight chance of getting a level 30 plan. - $plus = 0; - $name = $select->name; - $bld_destroy = 25; - } - $lvl = 30 if ($lvl > 30); - $plus = 30 if ($plus > 30); - $self->body->add_plan($class, $lvl, $plus); - if ($select->level == 1 or randint(0,99) < $bld_destroy) { - $select->delete; - } - else { - $select->level($select->level - 1); - $select->update; - } - return ($lvl, $plus, $name); + return ($plan_level, $plus, $name); } sub found_glyph { -- 2.51.2 From 8068439bfdecd1072693af53fe549ab34327f51d Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sat, 9 Jun 2012 09:57:49 -0600 Subject: [PATCH 092/105] Efficiency zero SAWs do not need to be added to defense. --- lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm index 7d0fb05a..d26909f3 100644 --- a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm +++ b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm @@ -27,8 +27,6 @@ after handle_arrival_procedures => sub { $body_attacked->set_last_attacked_by($ship_body->id); # get SAWs -# $self->saw_combat($body_attacked) if $is_planet; - $self->system_saw_combat; # get allies @@ -349,33 +347,35 @@ sub system_saw_combat { sub saw_stats { my ($self, $body) = @_; - my @saws = $body->get_buildings_of_class('Lacuna::DB::Result::Building::SAW'); + my $saws = $body->get_buildings_of_class('Lacuna::DB::Result::Building::SAW'); my $planet_combat = 0; my $cnt = 0; - foreach my $saw (@saws) { + my @defending_saws; + while (my $saw = $saws->next) { $cnt++; next if $saw->level < 1; next if $saw->efficiency < 1; $planet_combat += int( (5 * ($saw->level + 1) * ($saw->level+1) * $saw->efficiency)/2 + 0.5); - push @saws, $saw; + push @defending_saws, $saw; last if $cnt >= 10; } - return \@saws, $planet_combat; + return \@defending_saws, $planet_combat; } sub saw_combat { - my ($self, $saw, $saw_combat) = @_; + my ($self, $saw, $total_combat) = @_; + return if ($saw->combat == 0); # printf "ship:%6d:%5d saw:%6d:%2d:%3d total:%8d ", -# $self->id, $self->combat, $saw->id, $saw->level, $saw->efficiency, $saw_combat; - if ($self->combat >= $saw_combat) { +# $self->id, $self->combat, $saw->id, $saw->level, $saw->efficiency, $total_combat; + if ($self->combat >= $total_combat) { $saw->spend_efficiency(100); $self->saw_disabled($saw); # print "100\n"; } else { - my $perc_1 = int( ($self->combat * 100)/$saw_combat + 0.5); + my $perc_1 = int( ($self->combat * 100)/$total_combat + 0.5); my $perc_2 = int( $self->combat * 100/ (5 * ($saw->level + 1) * ($saw->level+1) * $saw->efficiency)); $perc_2 = 100 if $perc_2 > 99; @@ -391,7 +391,7 @@ sub saw_combat { $saw->start_work({}, 60 * 15); } $saw->update; - $self->damage_in_combat($saw, $saw_combat); + $self->damage_in_combat($saw, $total_combat); } 1; -- 2.51.2 From 6f7f0426d2d96b6e7149a653be62d2242df5794f Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sat, 9 Jun 2012 10:30:50 -0600 Subject: [PATCH 093/105] bad method call fix. --- lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm index d26909f3..55f7c492 100644 --- a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm +++ b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm @@ -347,12 +347,12 @@ sub system_saw_combat { sub saw_stats { my ($self, $body) = @_; - my $saws = $body->get_buildings_of_class('Lacuna::DB::Result::Building::SAW'); + my @planet_saws = $body->get_buildings_of_class('Lacuna::DB::Result::Building::SAW'); my $planet_combat = 0; my $cnt = 0; my @defending_saws; - while (my $saw = $saws->next) { + for my $saw (@planet_saws) { $cnt++; next if $saw->level < 1; next if $saw->efficiency < 1; -- 2.51.2 From 7caf162265e15daf4aa98be21ad2b9bd0f3e89d7 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sat, 9 Jun 2012 10:39:32 -0600 Subject: [PATCH 094/105] Sigh. --- lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm index 55f7c492..c6aa1ef3 100644 --- a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm +++ b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm @@ -366,7 +366,7 @@ sub saw_stats { sub saw_combat { my ($self, $saw, $total_combat) = @_; - return if ($saw->combat == 0); + return if ($saw->efficiency == 0); # printf "ship:%6d:%5d saw:%6d:%2d:%3d total:%8d ", # $self->id, $self->combat, $saw->id, $saw->level, $saw->efficiency, $total_combat; if ($self->combat >= $total_combat) { -- 2.51.2 From 889639de94989c7241d4394b7702d16aa493ebaa Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sat, 9 Jun 2012 19:54:24 -0600 Subject: [PATCH 095/105] Updated changes.txt --- var/www/public/changes.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 3cc0a2dd..fe8880e7 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,6 +1,8 @@ 3.0854: - Add: Backend support only for fleet actions. No changes to gameplay at this time. - Fix: None-permanent buildings on abandoned planets have been cleared. + - Fix: Spies no longer stealing level 1 buildings. + - Fix: 0% Efficiency Saws will no longer shoot down zero combat ships. 3.0853: - Mod: Excavator destruction will trigger a replacement excavator to be sent if available. -- 2.51.2 From e8e1b084a484297b29ba92e92697127243bc0eb9 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 11 Jun 2012 11:44:17 -0600 Subject: [PATCH 096/105] Inconsistant fleet numbers. --- lib/Lacuna/RPC/Building/SpacePort.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index f2267570..5d4be8c2 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -328,7 +328,7 @@ sub send_fleet { $set_speed //= 0; my $empire = $self->get_empire_by_session($session_id); my $target = $self->find_target($target_params); - my $max_ships = Lacuna->config->get('ships_per_fleet') || 50; + my $max_ships = Lacuna->config->get('ships_per_fleet') || 20; if (@$ship_ids > $max_ships) { confess [1009, 'Too many ships for a fleet.']; } -- 2.51.2 From 29df456996f7eb7d5a813c3231fd9b39500609df Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 12 Jun 2012 12:37:28 -0600 Subject: [PATCH 097/105] Spies being burned cost happy, training slightly cheaper. --- lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Building/Intelligence.pm | 3 ++- lib/Lacuna/DB/Result/Spies.pm | 12 ++++++++---- var/www/public/changes.txt | 4 ++++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 93891ec1..37b007d6 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0854; +our $VERSION = 3.0855; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1}); diff --git a/lib/Lacuna/DB/Result/Building/Intelligence.pm b/lib/Lacuna/DB/Result/Building/Intelligence.pm index a005b729..1bc52b7e 100644 --- a/lib/Lacuna/DB/Result/Building/Intelligence.pm +++ b/lib/Lacuna/DB/Result/Building/Intelligence.pm @@ -124,7 +124,8 @@ has training_multiplier => ( lazy => 1, default => sub { my $self = shift; - my $multiplier = $self->level +# my $multiplier = $self->level + my $multiplier = 1 - $self->body->empire->deception_affinity + $self->espionage_level + $self->security_level; diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 833c0343..5dba7ff5 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -380,10 +380,14 @@ sub burn { my $self = shift; my $old_empire = $self->empire; my $body = $self->from_body; - if ($body->add_news(10, 'This reporter has just learned that %s has a policy of burning its own loyal spies.', $old_empire->name)) { - $body->spend_happiness(5000); - $body->update; - } + my $unhappy = int($self->level * 1000 * 200/75); # Not factoring in Deception, always costs this much happiness. + $unhappy = 2000 if ($unhappy < 2000); + $body->spend_happiness($unhappy); + if ($body->add_news(25, 'This reporter has just learned that %s has a policy of burning its own loyal spies.', $old_empire->name)) { +# If the media finds out, even more unhappy. + $body->spend_happiness(int($unhappy/2)); + } + $body->update; if ($self->on_body->empire_id != $old_empire->id) { if (randint(1,100) < $self->level) { my $new_empire = $self->on_body->empire; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index fe8880e7..fe0b3240 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,7 @@ +3.0855: + - Mod: Intelligence Building Level doesn't factor into training costs. + - Mod: Burning a spy has more consequences. + 3.0854: - Add: Backend support only for fleet actions. No changes to gameplay at this time. - Fix: None-permanent buildings on abandoned planets have been cleared. -- 2.51.2 From f41b6e45d0ede3e8c088a70808c9583d1682a0d9 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Tue, 12 Jun 2012 15:56:05 -0400 Subject: [PATCH 098/105] Possible fix for SS that self destruct --- lib/Lacuna/DB/Result/Map/Body.pm | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index 9a39154e..386f8b3e 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -233,14 +233,12 @@ has building_cache => ( sub _build_building_cache { my ($self) = @_; - my @buildings_cache = $self->_buildings; - my @buildings; - for my $building (@buildings_cache) { -# push @buildings, weaken($building); - push @buildings, $building; + my $buildings = []; + my $bld_rs = $self->_buildings->search({},{prefetch => 'body'}); + while (my $building = $bld_rs->next) { + push @$buildings, $building; } - - return \@buildings; + return $buildings; } sub building_max_level { -- 2.51.2 From d1354797bcc5ae07d06c36489f8604459d41474a Mon Sep 17 00:00:00 2001 From: lemming552 Date: Fri, 22 Jun 2012 20:03:28 -0600 Subject: [PATCH 099/105] No burning sold prisoners. --- lib/Lacuna/RPC/Building/Intelligence.pm | 2 +- var/www/public/changes.txt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/RPC/Building/Intelligence.pm b/lib/Lacuna/RPC/Building/Intelligence.pm index 5fa0313e..de49c0d7 100644 --- a/lib/Lacuna/RPC/Building/Intelligence.pm +++ b/lib/Lacuna/RPC/Building/Intelligence.pm @@ -101,7 +101,7 @@ sub burn_spy { if ($spy->task eq 'Waiting On Trade' || $spy->task eq 'Mercenary Transport') { confess [1010, "You can't burn a spy involved in a trade. You must wait for the trade to complete."]; } - if ($spy->task eq 'Captured') { + if ($spy->task eq 'Captured' or $spy->task eq 'Prisoner Transport') { confess [1010, "You can't burn a spy that has been captured. If you did he would have no reason not to tell your enemy all your secrets."]; } if ($spy->task eq 'Killed In Action') { diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index fe0b3240..d44f8ae6 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,10 +1,11 @@ 3.0855: - Mod: Intelligence Building Level doesn't factor into training costs. - Mod: Burning a spy has more consequences. + - Fix: No burning spies while they're being transported. 3.0854: - Add: Backend support only for fleet actions. No changes to gameplay at this time. - - Fix: None-permanent buildings on abandoned planets have been cleared. + - Fix: Non-permanent buildings on abandoned planets have been cleared. - Fix: Spies no longer stealing level 1 buildings. - Fix: 0% Efficiency Saws will no longer shoot down zero combat ships. -- 2.51.2 From f77228d0bf38168380608588e59536b1d10744ba Mon Sep 17 00:00:00 2001 From: fireartist Date: Sat, 23 Jun 2012 21:01:37 +0100 Subject: [PATCH 100/105] show supply-chain stalled status in API --- lib/Lacuna/DB/Result/SupplyChain.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Lacuna/DB/Result/SupplyChain.pm b/lib/Lacuna/DB/Result/SupplyChain.pm index f34a9c72..899668fa 100644 --- a/lib/Lacuna/DB/Result/SupplyChain.pm +++ b/lib/Lacuna/DB/Result/SupplyChain.pm @@ -37,6 +37,7 @@ sub get_status { resource_hour => $self->resource_hour, resource_type => $self->resource_type, percent_transferred => $self->percent_transferred, + stalled => $self->stalled, }; } -- 2.51.2 From 019872d7e42f991919a1708626e840999d19f609 Mon Sep 17 00:00:00 2001 From: fireartist Date: Sat, 23 Jun 2012 21:05:13 +0100 Subject: [PATCH 101/105] add view_supply_chain {stalled} to docs --- docs/Trade.pod | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/Trade.pod b/docs/Trade.pod index 12bb177f..6aa23e94 100644 --- a/docs/Trade.pod +++ b/docs/Trade.pod @@ -597,6 +597,7 @@ Returns a list of the supply chains currently controlled by this Trade Ministry "resource_hour" : 10000000, "resource_type" : 'water', "percent_transferred" : 95, + "stalled" : 0, } ], "max_supply_chains" : 30 @@ -620,6 +621,8 @@ it is at or above 100. Above 100 and you have more ship capacity than you need, still only transfer the specified B, it just means some ships will be idle or not fully filled. +B is true if there are no more of the chain's resource available in storage to push. + =head2 view_waste_chains ( session_id, building_id ) -- 2.51.2 From 9fc4ca16149e22397acbeae90469447dc4549ead Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 24 Jun 2012 12:37:54 -0400 Subject: [PATCH 102/105] Updated changes.txt --- var/www/public/changes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index d44f8ae6..68bab8c3 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -2,6 +2,7 @@ - Mod: Intelligence Building Level doesn't factor into training costs. - Mod: Burning a spy has more consequences. - Fix: No burning spies while they're being transported. + - Add: Supply chain now shows 'stalled' status (API only) 3.0854: - Add: Backend support only for fleet actions. No changes to gameplay at this time. -- 2.51.2 From 893dfe9e3c61d180ad2155f35de51da3862195d0 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 24 Jun 2012 19:55:26 -0600 Subject: [PATCH 103/105] Space Station kludge --- lib/Lacuna/DB/Result/Building/Module.pm | 2 +- var/messages/space_station_destroyed.txt | 1 + var/www/public/changes.txt | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Lacuna/DB/Result/Building/Module.pm b/lib/Lacuna/DB/Result/Building/Module.pm index f2340c99..40a001c3 100644 --- a/lib/Lacuna/DB/Result/Building/Module.pm +++ b/lib/Lacuna/DB/Result/Building/Module.pm @@ -90,7 +90,7 @@ around demolish => sub { filename => 'space_station_destroyed.txt', params => [$body->id, $body->name], ); - $body->sanitize; +# $body->sanitize; } }; diff --git a/var/messages/space_station_destroyed.txt b/var/messages/space_station_destroyed.txt index c3e56d55..14643fe5 100644 --- a/var/messages/space_station_destroyed.txt +++ b/var/messages/space_station_destroyed.txt @@ -1,6 +1,7 @@ Space Station Destroyed ~~~ We have just received word that our station named {Planet %s %s} has been destroyed. +Dev Note: Temporary fix for seeing if we can track down the SS destruction bug. Contact an admin, so we can check the state of your station if you got this message. Regards, diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index d44f8ae6..141fb031 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -2,6 +2,7 @@ - Mod: Intelligence Building Level doesn't factor into training costs. - Mod: Burning a spy has more consequences. - Fix: No burning spies while they're being transported. + - Grr: Space Stations shouldn't turn into asteroids. However, they won't die if you want them until we fix the bug. 3.0854: - Add: Backend support only for fleet actions. No changes to gameplay at this time. -- 2.51.2 From fe14989c3dc924f7fedbd1faff900388a9ba191b Mon Sep 17 00:00:00 2001 From: ian docherty Date: Tue, 26 Jun 2012 04:13:43 -0400 Subject: [PATCH 104/105] Weakened several potential memory leak references --- lib/Lacuna/DB/Result/Building/Development.pm | 1 - .../DB/Result/Building/SubspaceSupplyDepot.pm | 1 - lib/Lacuna/DB/Result/Building/Trade.pm | 2 + lib/Lacuna/DB/Result/Empire.pm | 3 + lib/Lacuna/DB/Result/Map/Body.pm | 7 ++- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 56 ++++++++++++------- lib/Lacuna/DB/Result/Ships.pm | 2 + lib/Lacuna/DB/Result/Spies.pm | 25 +++++++-- t/TestHelper.pm | 3 +- 9 files changed, 68 insertions(+), 32 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Development.pm b/lib/Lacuna/DB/Result/Building/Development.pm index 619cf191..f103950c 100644 --- a/lib/Lacuna/DB/Result/Building/Development.pm +++ b/lib/Lacuna/DB/Result/Building/Development.pm @@ -9,7 +9,6 @@ sub subsidize_build_queue { my ($self) = @_; $self->body->tick; foreach my $build (@{$self->body->builds}) { - $build->body($self->body); $build->finish_upgrade; } } diff --git a/lib/Lacuna/DB/Result/Building/SubspaceSupplyDepot.pm b/lib/Lacuna/DB/Result/Building/SubspaceSupplyDepot.pm index 47c5c74a..bf551752 100644 --- a/lib/Lacuna/DB/Result/Building/SubspaceSupplyDepot.pm +++ b/lib/Lacuna/DB/Result/Building/SubspaceSupplyDepot.pm @@ -94,7 +94,6 @@ sub complete_build_queue { $self->work_ends($self->work_ends->subtract(seconds => $time_to_complete)); $self->update; foreach my $build (@{$self->body->builds}) { - $build->body($self->body); $build->finish_upgrade; } } diff --git a/lib/Lacuna/DB/Result/Building/Trade.pm b/lib/Lacuna/DB/Result/Building/Trade.pm index 5d4d668a..b42727e0 100644 --- a/lib/Lacuna/DB/Result/Building/Trade.pm +++ b/lib/Lacuna/DB/Result/Building/Trade.pm @@ -3,6 +3,7 @@ package Lacuna::DB::Result::Building::Trade; use Moose; use List::Util qw(max min); use Carp; +use Scalar::Util qw(weaken); use utf8; use List::Util qw(max); @@ -423,6 +424,7 @@ sub push_items { if ($options->{stay}) { $ship->body_id($target->id); $ship->body($target); + weaken($ship->{_relationship_data}{body}); $ship->send( target => $self->body, direction => 'in', diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 8a4547c1..3ff13021 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -5,6 +5,7 @@ use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result'; use DateTime; +use Scalar::Util qw(weaken); use Lacuna::Util qw(format_date); use Digest::SHA; use List::MoreUtils qw(uniq); @@ -502,6 +503,8 @@ sub found { $self->stage('founded'); $self->update; $self->home_planet($home_planet); + weaken($self->{_relationship_data}{home_planet}); + $self->add_probe($home_planet->star_id, $home_planet->id); # found colony diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index 386f8b3e..87071dde 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -232,11 +232,12 @@ has building_cache => ( sub _build_building_cache { my ($self) = @_; - my $buildings = []; - my $bld_rs = $self->_buildings->search({},{prefetch => 'body'}); + my $bld_rs = $self->_buildings->search({}); while (my $building = $bld_rs->next) { - push @$buildings, $building; + $building->body($self); + weaken($building->{_relationship_data}{body}); + push @$buildings,$building; } return $buildings; } diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 783cead2..2227d955 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -486,7 +486,8 @@ has command => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::PlanetaryCommand'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -498,7 +499,9 @@ has oversight => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Oversight'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); + return $building; }, ); @@ -510,7 +513,8 @@ has archaeology => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Archaeology'); return undef unless defined $building; -# #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -522,7 +526,8 @@ has mining_ministry => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Ore::Ministry'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -534,7 +539,8 @@ has network19 => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Network19'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -546,7 +552,8 @@ has development => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Development'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -558,7 +565,8 @@ has refinery => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Ore::Refinery'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -570,7 +578,8 @@ has spaceport => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::SpacePort'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -582,7 +591,8 @@ has embassy => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Embassy'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -688,19 +698,18 @@ has future_operating_resources => ( # adjust for what's already in build queue my @queued_builds = @{$self->builds}; foreach my $build (@queued_builds) { - $build->body($self); - my $other = $build->stats_after_upgrade; - foreach my $method ($self->operating_resource_names) { - $future{$method} += $other->{$method} - $build->$method; - } + my $other = $build->stats_after_upgrade; + foreach my $method ($self->operating_resource_names) { + $future{$method} += $other->{$method} - $build->$method; + } } return \%future; }, -); + ); sub has_resources_to_operate { my ($self, $building) = @_; - + # get future my $future = $self->future_operating_resources; @@ -710,7 +719,7 @@ sub has_resources_to_operate { # check our ability to sustain ourselves foreach my $method ($self->operating_resource_names) { my $delta = $after->{$method} - $building->$method; - # don't allow it if it sucks resources && its sucking more than we're producing + # don't allow it if it sucks resources && its sucking more than we're producing if ($delta < 0 && $future->{$method} + $delta < 0) { my $resource = $method; $resource =~ s/(\w+)_hour/$1/; @@ -722,13 +731,13 @@ sub has_resources_to_operate { sub has_resources_to_operate_after_building_demolished { my ($self, $building) = @_; - + # get future my $planet = $self->future_operating_resources; # check our ability to sustain ourselves foreach my $method ($self->operating_resource_names) { - # don't allow it if it sucks resources && its sucking more than we're producing + # don't allow it if it sucks resources && its sucking more than we're producing if ($planet->{$method} - $building->$method < 0) { my $resource = $method; $resource =~ s/(\w+)_hour/$1/; @@ -799,7 +808,8 @@ sub build_building { $building->body_id($self->id); $building->level(0) unless $building->level; $building->insert; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); $building->start_upgrade(undef, $in_parallel); $self->building_cache([@{$self->building_cache}, $building]); } @@ -808,10 +818,11 @@ sub found_colony { my ($self, $empire) = @_; $self->empire_id($empire->id); $self->empire($empire); + weaken($self->{_relationship_data}{empire}); $self->usable_as_starter_enabled(0); $self->last_tick(DateTime->now); $self->update; -# Excavators get cleared when being checked for results. + # Excavators get cleared when being checked for results. # award medal my $type = ref $self; @@ -859,6 +870,8 @@ sub convert_to_station { $self->plots_available(0); $self->empire_id($empire->id); $self->empire($empire); + weaken($self->{_relationship_data}{empire}); + $self->usable_as_starter_enabled(0); $self->last_tick(DateTime->now); $self->alliance_id($empire->alliance_id); @@ -1240,6 +1253,7 @@ sub tick { foreach my $key (sort keys %todo) { my ($object, $job) = ($todo{$key}{object}, $todo{$key}{type}); $object->body($self); + weaken($object->{_relationship_data}{body}); if ($job eq 'ship built') { $self->tick_to($object->date_available); $object->finish_construction; diff --git a/lib/Lacuna/DB/Result/Ships.pm b/lib/Lacuna/DB/Result/Ships.pm index f6941df7..3ab43752 100644 --- a/lib/Lacuna/DB/Result/Ships.pm +++ b/lib/Lacuna/DB/Result/Ships.pm @@ -6,6 +6,7 @@ no warnings qw(uninitialized); extends 'Lacuna::DB::Result'; use Lacuna::Util qw(format_date randint); use DateTime; +use Scalar::Util qw(weaken); use feature "switch"; has 'hostile_action' => ( @@ -291,6 +292,7 @@ sub send { if ($options{target}->isa('Lacuna::DB::Result::Map::Body')) { $self->foreign_body_id($options{target}->id); $self->foreign_body($options{target}); + weaken($self->{_relationship_data}{foreign_body}); $self->foreign_star_id(undef); $self->foreign_star(undef); } diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 5dba7ff5..36f88f4e 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -647,7 +647,10 @@ sub get_defender { empire_id => { 'not_in' => \@member_ids } }, { rows => 1, order_by => 'rand()' } )->single; - $defender->on_body($self->on_body) if defined $defender; + if (defined $defender) { + $defender->on_body($self->on_body); + weaken($defender->{_relationship_data}{on_body}); + } return $defender; } @@ -674,7 +677,10 @@ sub get_attacker { { rows => 1, order_by => 'rand()' } ) ->single; - $attacker->on_body($self->on_body) if defined $attacker; + if (defined $attacker) { + $attacker->on_body($self->on_body); + weaken($attacker->{_relationship_data}{on_body}); + } return $attacker; } @@ -702,7 +708,10 @@ sub get_idle_attacker { my $attacker = random_element(\@attackers); - $attacker->on_body($self->on_body) if defined $attacker; + if (defined $attacker) { + $attacker->on_body($self->on_body); + weaken($attacker->{_relationship_data}{on_body}); + } return $attacker; } @@ -716,7 +725,10 @@ sub get_random_prisoner { ) ->all; my $prisoner = random_element(\@prisoners); - $prisoner->on_body($self->on_body) if defined $prisoner; + if (defined $prisoner) { + $prisoner->on_body($self->on_body); + weaken($prisoner->{_relationship_data}{on_body}); + } return $prisoner; } @@ -1713,6 +1725,7 @@ sub abduct_operative { return $self->ship_not_found->id unless (defined $ship); return $self->no_contact->id unless (defined $defender); $ship->body($self->from_body); + weaken($ship->{_relationship_data}{from_body}); $ship->send( target => $self->on_body, direction => 'in', @@ -2018,6 +2031,7 @@ sub steal_resources { } $on_body->update; $ship->body($self->from_body); + weaken($ship->{_relationship_data}{body}); $ship->send( target => $self->on_body, direction => 'in', @@ -2067,6 +2081,7 @@ sub steal_glyph { my $glyph = $on_body->glyphs->search(undef, {rows => 1, order_by => 'rand()'})->single; return $self->mission_objective_not_found('glyph')->id unless defined $glyph; $ship->body($self->from_body); + weaken($ship->{_relationship_data}{body}); $ship->send( target => $self->on_body, direction => 'in', @@ -2113,6 +2128,7 @@ sub steal_ships { )->single; return $self->ship_not_found->id unless (defined $ship); $ship->body($self->from_body); + weaken($ship->{_relationship_data}{body}); $ship->send( target => $self->on_body, direction => 'in', @@ -2255,7 +2271,6 @@ sub shut_down_building { filename => 'building_loss_of_power.txt', params => [$building->name, $self->on_body->id, $self->on_body->name], ); - $building->body($self->on_body); $building->spend_efficiency($self->level)->update; $self->on_body->add_news(25, 'Employees at the %s on %s were left in the dark today during a power outage.', diff --git a/t/TestHelper.pm b/t/TestHelper.pm index 32007a26..6f83c68d 100644 --- a/t/TestHelper.pm +++ b/t/TestHelper.pm @@ -61,6 +61,8 @@ sub clear_all_test_empires { name => {like => $name}, }); while (my $empire = $empires->next) { + $empire->essentia(0); + $empire->update; my $planets = $empire->planets; while ( my $planet = $planets->next ) { @@ -68,7 +70,6 @@ sub clear_all_test_empires { $planet->delete_buildings(\@buildings); } - $empire->delete; } } -- 2.51.2 From 919c7fe4ac57dfe7d1ef80445afb2158ab34d9a8 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Tue, 26 Jun 2012 04:44:03 -0400 Subject: [PATCH 105/105] Added missing Scalar::Util calls --- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 1 + lib/Lacuna/DB/Result/Spies.pm | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 2227d955..3464e59a 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -10,6 +10,7 @@ use List::Util qw(shuffle max min); use Lacuna::Util qw(randint format_date); use DateTime; use Data::Dumper; +use Scalar::Util qw(weaken); no warnings 'uninitialized'; __PACKAGE__->has_many('ships','Lacuna::DB::Result::Ships','body_id'); diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 36f88f4e..c7e33a2b 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -7,6 +7,8 @@ extends 'Lacuna::DB::Result'; use List::Util qw(shuffle); use Lacuna::Util qw(format_date randint random_element); use DateTime; +use Scalar::Util qw(weaken); + use feature "switch"; use Lacuna::Constants qw(ORE_TYPES FOOD_TYPES SHIP_TYPES);
IdNameTypeStealthHold SizeSpeedCombatTaskDelete
%s%s%s%s%s%s%s%s
%s
%s (%d, %d)