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 f09ddfe3d2950014794c1828ae137f1dae2e761c Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 20 May 2012 16:27:56 -0400 Subject: [PATCH 02/79] 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 03/79] 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 04/79] 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 05/79] 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 06/79] 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 07/79] 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 08/79] 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 09/79] 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 10/79] 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 11/79] 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 12/79] 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 13/79] 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 14/79] 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 15/79] 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 16/79] 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 17/79] 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 18/79] 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 19/79] 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 20/79] 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 21/79] 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 22/79] 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 23/79] 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 24/79] 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 25/79] 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 26/79] 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 27/79] 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 d6bab0ba90e30c076717a768df4b7496cec773f4 Mon Sep 17 00:00:00 2001 From: fireartist Date: Thu, 17 May 2012 14:58:26 +0100 Subject: [PATCH 28/79] admin: new delete-building button bypasses demolish requirements/costs --- lib/Lacuna/Web/Admin.pm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Lacuna/Web/Admin.pm b/lib/Lacuna/Web/Admin.pm index 82eab0aa..947f19f7 100644 --- a/lib/Lacuna/Web/Admin.pm +++ b/lib/Lacuna/Web/Admin.pm @@ -294,7 +294,10 @@ sub www_view_buildings { $out .= sprintf('',$building->level); $out .= sprintf('%s',$building->is_upgrading, $building->id); $out .= sprintf('', $building->efficiency); - $out .= sprintf(''); + $out .= sprintf(''); + $out .= sprintf('
'); + $out .= sprintf('', $building->id); + $out .= sprintf('
'); } $out .= ''; return $self->wrap($out); @@ -312,6 +315,18 @@ sub www_set_efficiency { return $self->www_view_buildings($request, $building->body_id); } +sub www_delete_building { + my ($self, $request) = @_; + my $building = Lacuna->db->resultset('Lacuna::DB::Result::Building')->find($request->param('building_id')); + my $body = $building->body; + $building->delete; + $body->needs_recalc(1); + $body->needs_surface_refresh(1); + $body->update; + $body->tick; + return $self->www_view_buildings($request, $building->body_id); +} + sub www_view_ships { my ($self, $request, $body_id) = @_; $body_id ||= $request->param('body_id'); -- 2.51.2 From af4bc08d33ddaf385d9393fbc796e3941ad18acf Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 17 May 2012 09:14:14 -0600 Subject: [PATCH 29/79] Cleaned changes. --- var/www/public/changes.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index a2f6c868..4f347683 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,5 +1,5 @@ 3.0851: - - Mod: Multiple plans buildable in Archaeology Ministry. + - Mod: Multiple plans buildable with one call from Archaeology Ministry. - Mod: view_plans from Planetary and Station Commands consolidated. UI updated to reflect. - Mod: You don't have to build all Halls of Vrbansk to sacrifice (only one) - Add: Supply chain to any planet or SS. @@ -13,7 +13,7 @@ - Fix: Deployed Bleeders no longer count toward population totals. - Mod: Supply Pods no longer use a plot. - Mod: Being at negative plots makes your people unhappy. - - Mod: Stockpile rules change in testing. + - Mod: Stockpile rules change. University levels higher than 25 gives bonus. - Mod: Short Range Colony Ships faster, but limited in range. 3.0850: -- 2.51.2 From 0bfbed63478ce309e2d016e4be7bad09aa3462f2 Mon Sep 17 00:00:00 2001 From: fireartist Date: Thu, 17 May 2012 21:25:15 +0100 Subject: [PATCH 30/79] 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 1c04b581297b6444b00dbdff750ef655e8d8bed4 Mon Sep 17 00:00:00 2001 From: fireartist Date: Thu, 17 May 2012 16:32:42 +0100 Subject: [PATCH 31/79] 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 e1930604a28e749767f49e63f93861490931ab3d Mon Sep 17 00:00:00 2001 From: fireartist Date: Thu, 17 May 2012 16:34:42 +0100 Subject: [PATCH 32/79] 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 8c5c6db483af470fbc79d21989d05e74a6c23518 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 20 May 2012 11:07:26 -0600 Subject: [PATCH 33/79] 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 66bfb2908c597b2157cf2237efa548cf97317c89 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 20 May 2012 11:37:41 -0600 Subject: [PATCH 34/79] 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 1bdd8c770426df48c2efa2df030efd3d06866704 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 20 May 2012 12:03:20 -0600 Subject: [PATCH 35/79] 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 d1f5a82e6d290215ee70e583b16f84f31665b7bb Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 20 May 2012 13:30:43 -0600 Subject: [PATCH 36/79] 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 e9443d4fe867cef98a51cab2c7253ea90c49d013 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Mon, 21 May 2012 16:27:57 -0400 Subject: [PATCH 37/79] Fixed problem with building count --- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index e7ccc21d..07f12e0d 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -407,6 +407,13 @@ 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}; + return $count; +} + sub get_buildings_of_class { my ($self, $class) = @_; return Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( -- 2.51.2 From 471338b35d799c1389bf8702c4f412ffd8155578 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Mon, 21 May 2012 16:38:27 -0400 Subject: [PATCH 38/79] Can upgrade a building with a plan --- lib/Lacuna/DB/Result/Building.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index ffc00769..14c581ed 100755 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -752,6 +752,7 @@ 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; -- 2.51.2 From d106791614243bde2d8afba66084135e939c5ba4 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 21 May 2012 17:26:48 -0600 Subject: [PATCH 39/79] 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 2a8fd8ffb9e680065ef4013586cac68393f2a324 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 07:41:33 -0600 Subject: [PATCH 40/79] 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 07f12e0d..7614272d 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -950,6 +950,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) { @@ -969,6 +970,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 98e31e31b7e54b95c7a47536920512f906e1b24d Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 07:55:36 -0600 Subject: [PATCH 41/79] 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 5bec4c3c7ab585005e9b493dadac47092f0c8141 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 11:57:16 -0600 Subject: [PATCH 42/79] 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 42c54c9cea69e2a04809348fb53ecefb6a55e969 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 12:09:55 -0600 Subject: [PATCH 43/79] 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 a451b6c0b4673cbc95f08014fe1249a768a0eccb Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 13:53:15 -0600 Subject: [PATCH 44/79] 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 087c15026cd4136eac8a5a00f2527de1f5233d39 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 13:56:25 -0600 Subject: [PATCH 45/79] 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 f75b38909ad2ed4df60da4da38f351c612d1d726 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 13:58:43 -0600 Subject: [PATCH 46/79] 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 d26fe4ecaf94c01d89827f1d2645d152fd89003e Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 15:57:24 -0600 Subject: [PATCH 47/79] 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 0bb6f5de5480d5c51493522d58186e2dcd238b41 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 16:43:02 -0600 Subject: [PATCH 48/79] 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 84553271c585998c69724dc35cb68b05c4d45d37 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 17:26:43 -0600 Subject: [PATCH 49/79] 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 88612866dd68cb7818fe934b3e43087a2b32552e Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 17:47:36 -0600 Subject: [PATCH 50/79] 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 1f49eb2416985cc43a08d275096e53c5f45c77ac Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 17:58:12 -0600 Subject: [PATCH 51/79] 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 7248f405c704af9f865a4cc07fd950e0c5d1c7fe Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 22 May 2012 18:23:39 -0600 Subject: [PATCH 52/79] 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 3e77c0d7eb738e100fe607f74a5549f928f3affc Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 23 May 2012 14:49:37 -0400 Subject: [PATCH 53/79] 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 7614272d..79d6eee4 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -409,8 +409,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 0fe077d2bdc425471305e360452d93c9a2178d0d Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 7 May 2012 19:48:29 -0600 Subject: [PATCH 54/79] Fix for waste chains after bhg swap --- lib/Lacuna/RPC/Building/BlackHoleGenerator.pm | 9 +++++++++ var/www/public/changes.txt | 1 + 2 files changed, 10 insertions(+) diff --git a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm index 8ae8a299..57c6feb2 100644 --- a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm +++ b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm @@ -503,6 +503,7 @@ 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) { @@ -512,6 +513,14 @@ 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, diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 2ca4c728..b79ee7b1 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -19,6 +19,7 @@ - Mod: Being at negative plots makes your people unhappy. - Mod: Stockpile rules change. University levels higher than 25 gives bonus. - Mod: Short Range Colony Ships faster, but limited in range. + - Fix: Bleeders no longer count toward population totals. 3.0850: - Fix: All non-trade inflight ships self destruct from an insurrected planet. -- 2.51.2 From caa1d96b7581c3c4220f97dcc9206ebf3b06c0ff Mon Sep 17 00:00:00 2001 From: ian docherty Date: Wed, 23 May 2012 16:41:53 -0400 Subject: [PATCH 55/79] 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 b20900ee..3461116e 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm @@ -47,7 +47,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 987b51729fb1f33429728ae88c9ab7be7e178567 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 24 May 2012 17:23:42 -0600 Subject: [PATCH 56/79] 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 57/79] 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 58/79] 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 59/79] 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 60/79] 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 61/79] 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 62/79] 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 63/79] 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 64/79] 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 65/79] 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 66/79] 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 011519e507ba52dd98d6c29ce3a8da578f14bb16 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 3 Jun 2012 15:20:58 -0400 Subject: [PATCH 67/79] 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 68/79] 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 69/79] 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 70/79] 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 71/79] 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 72/79] 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 73/79] 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 74/79] 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 75/79] 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 76/79] 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 77/79] 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 b8790e242edb13a72138dcb6d142032ee68414bd Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 5 Jun 2012 10:16:06 -0600 Subject: [PATCH 78/79] 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 fc2ea5349f680d03fdf79267ffe3ba333970ec2d Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 5 Jun 2012 23:27:53 -0600 Subject: [PATCH 79/79] 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({
IdNameTypeStealthHold SizeSpeedCombatTaskDelete
%s%s%s%s%s%s%s%s
%s
%s (%d, %d)