From d6bab0ba90e30c076717a768df4b7496cec773f4 Mon Sep 17 00:00:00 2001 From: fireartist Date: Thu, 17 May 2012 14:58:26 +0100 Subject: [PATCH 01/28] 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 02/28] 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 03/28] 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 04/28] 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 05/28] 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 06/28] 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 07/28] 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 08/28] 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 09/28] 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 10/28] 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 11/28] 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 12/28] 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 13/28] 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 14/28] 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 15/28] 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 16/28] 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 17/28] 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 18/28] 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 19/28] 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 20/28] 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 21/28] 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 22/28] 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 23/28] 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 24/28] 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 25/28] 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 26/28] 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 27/28] 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 28/28] 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