diff --git a/lib/Lacuna/DB/Result/Building/Permanent/GasGiantPlatform.pm b/lib/Lacuna/DB/Result/Building/Permanent/GasGiantPlatform.pm index f4e78ebc..7df52e77 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/GasGiantPlatform.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/GasGiantPlatform.pm @@ -6,8 +6,8 @@ no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Building::Permanent'; around 'build_tags' => sub { - my ($orig, $class) = @_; - return ($orig->($class), qw(Infrastructure Construction)); + my ($orig, $class) = @_; + return ($orig->($class), qw(Infrastructure Construction)); }; use constant controller_class => 'Lacuna::RPC::Building::GasGiantPlatform'; @@ -15,50 +15,73 @@ use constant controller_class => 'Lacuna::RPC::Building::GasGiantPlatform'; use constant image => 'gas-giant-platform'; around can_build => sub { - my ($orig, $self, $body) = @_; - if ($body->get_plan(__PACKAGE__, 1)) { - return $orig->($self, $body); - } - confess [1013,"You can't directly build a Gas Giant Platform. You need a gas giant platform ship."]; + my ($orig, $self, $body) = @_; + if ($body->get_plan(__PACKAGE__, 1)) { + return $orig->($self, $body); + } + confess [1013,"You can't directly build a Gas Giant Platform. You need a gas giant platform ship."]; }; before 'can_demolish' => sub { - my $self = shift; - my $body = $self->body; - my $buildings = $body->buildings; - my $gas_giant_platforms = 0; - my @gas_giant_platforms = $buildings->search({ class => 'Lacuna::DB::Result::Building::Permanent::GasGiantPlatform' })->get_column('level')->all; - $gas_giant_platforms += $_ for @gas_giant_platforms; - my $excess_plots = $gas_giant_platforms - ($body->plots_available + $body->building_count); - my $available = $excess_plots > $body->plots_available ? $excess_plots : $body->plots_available; - if ($available < $self->level && $body->get_type eq "gas giant") { - confess [1013, 'You need to demolish a building before you can demolish this Gas Giant Settlement Platform.']; - } + 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) { + $gg_cnt++; + $gg_plots += int($gg_bld->level * $gg_bld->efficiency/100); + } + return if ($gg_cnt <= 1); # If we only have the one platform, they can destroy it. + my $bld_count = $body->building_count; + my $excess_plots = $gg_plots - $bld_count; + if ($excess_plots < 0) { + confess [1013, 'Your Gas Giant shows that you are at negative plots.']; + } + if ($excess_plots < int($self->level * $self->efficiency/100) ) { + confess [1013, 'You need to demolish a building before you can demolish this Gas Giant Settlement Platform.']; + } }; before 'can_downgrade' => sub { - my $self = shift; - my $body = $self->body; - my $buildings = $body->buildings; - my $gas_giant_platforms = 0; - my @gas_giant_platforms = $buildings->search({ class => 'Lacuna::DB::Result::Building::Permanent::GasGiantPlatform' })->get_column('level')->all; - $gas_giant_platforms += $_ for @gas_giant_platforms; - my $excess_plots = $gas_giant_platforms - ($body->plots_available + $body->building_count); - my $available = $excess_plots > $body->plots_available ? $excess_plots : $body->plots_available; - if ($available < 1) { - confess [1013, 'You need to demolish a building before you can downgrade this Gas Giant Settlement Platform.']; - } + 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) { + $gg_cnt++; + $gg_plots += int($gg_bld->level * $gg_bld->efficiency/100); + } + my $bld_count = $body->building_count; + my $excess_plots = $gg_plots - $bld_count; + if ($excess_plots < 1) { + confess [1013, 'You need to demolish at least one building before you can downgrade this Gas Giant Settlement Platform.']; + } }; before has_special_resources => sub { - my $self = shift; - my $planet = $self->body; - unless ($planet->get_plan(ref $self, $self->level + 1)) { - my $amount_needed = sprintf('%.0f', $self->ore_to_build * $self->upgrade_cost * 0.50); - if ($planet->rutile_stored + $planet->chromite_stored + $planet->bauxite_stored + $planet->magnetite_stored + $planet->beryl_stored + $planet->goethite_stored < $amount_needed) { - confess [1012,"You do not have a sufficient supply (".$amount_needed.") of structural minerals such as Rutile, Chromite, Bauxite, Magnetite, Beryl, and Goethite to build the components that can handle the stresses of gas giant missions."]; - } + my $self = shift; + my $planet = $self->body; + unless ($planet->get_plan(ref $self, $self->level + 1)) { + my $amount_needed = sprintf('%.0f', $self->ore_to_build * $self->upgrade_cost * 0.50); + if ($planet->rutile_stored + $planet->chromite_stored + + $planet->bauxite_stored + $planet->magnetite_stored + + $planet->beryl_stored + $planet->goethite_stored < $amount_needed) { + confess [1012,"You do not have a sufficient supply (". + $amount_needed. + ") of structural minerals such as Rutile, Chromite, Bauxite, Magnetite, Beryl, and Goethite to build the components that can handle the stresses of gas giant missions."]; } + } }; use constant name => 'Gas Giant Settlement Platform'; diff --git a/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm b/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm index cd045238..6f2f3cb5 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm @@ -6,57 +6,78 @@ no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Building::Permanent'; around 'build_tags' => sub { - my ($orig, $class) = @_; - return ($orig->($class), qw(Infrastructure Construction)); + my ($orig, $class) = @_; + return ($orig->($class), qw(Infrastructure Construction)); }; use constant controller_class => 'Lacuna::RPC::Building::TerraformingPlatform'; around can_build => sub { - my ($orig, $self, $body) = @_; - if ($body->get_plan(__PACKAGE__, 1)) { - return $orig->($self, $body); - } - confess [1013,"You can't directly build a Terraforming Platform. You need a terraforming platform ship."]; + my ($orig, $self, $body) = @_; + if ($body->get_plan(__PACKAGE__, 1)) { + return $orig->($self, $body); + } + confess [1013,"You can't directly build a Terraforming Platform. You need a terraforming platform ship."]; }; before 'can_demolish' => sub { - my $self = shift; - my $body = $self->body; - my $buildings = $body->buildings; - my $terraforming_platforms = 0; - my @terraforming_platforms = $buildings->search({ class => 'Lacuna::DB::Result::Building::Permanent::TerraformingPlatform' })->get_column('level')->all; - $terraforming_platforms += $_ for @terraforming_platforms; - my $excess_plots = $terraforming_platforms - ($self->body->plots_available + $self->body->building_count); - my $available = $excess_plots > $self->body->plots_available ? $excess_plots : $self->body->plots_available; - if ($available < $self->level && ($body->orbit > $body->empire->max_orbit || $body->orbit < $body->empire->min_orbit)) { - confess [1013, 'You need to demolish a building before you can demolish this Terraforming Platform.']; - } + 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' }); + + my $tp_plots = 0; + my $tp_cnt = 0; + + while (my $tp_bld = $tp_blds->next) { + $tp_cnt++; + $tp_plots += int($tp_bld->level * $tp_bld->efficiency/100); + } + return if ($tp_cnt <= 1); # If we only have the one platform, they can destroy it. + my $bld_count = $body->building_count; + my $excess_plots = $tp_plots - $bld_count; + if ($excess_plots < 0) { + confess [1013, 'Your planet shows that you are at negative plots.']; + } + if ($excess_plots < int($self->level * $self->efficiency/100) ) { + confess [1013, 'You need to demolish a building before you can demolish this Terraforming Platform.']; + } }; before 'can_downgrade' => sub { - my $self = shift; - my $body = $self->body; - my $buildings = $body->buildings; - my $terraforming_platforms = 0; - my @terraforming_platforms = $buildings->search({ class => 'Lacuna::DB::Result::Building::Permanent::TerraformingPlatform' })->get_column('level')->all; - $terraforming_platforms += $_ for @terraforming_platforms; - my $excess_plots = $terraforming_platforms - ($self->body->plots_available + $self->body->building_count); - my $available = $excess_plots > $self->body->plots_available ? $excess_plots : $self->body->plots_available; - if ($available < 1 && ($body->orbit > $body->empire->max_orbit || $body->orbit < $body->empire->min_orbit)) { - confess [1013, 'You need to demolish a building before you can downgrade this Terraforming Platform.']; - } + 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' }); + + my $tp_plots = 0; + my $tp_cnt = 0; + + while (my $tp_bld = $tp_blds->next) { + $tp_cnt++; + $tp_plots += int($tp_bld->level * $tp_bld->efficiency/100); + } + return if ($tp_cnt <= 1); # If we only have the one platform, they can destroy it. + my $bld_count = $body->building_count; + my $excess_plots = $tp_plots - $bld_count; + if ($excess_plots < 1) { + confess [1013, 'You need to demolish at least one building before you can downgrade this Terraforming Platform.']; + } }; before has_special_resources => sub { - my $self = shift; - my $planet = $self->body; - unless ($planet->get_plan(ref $self, $self->level + 1)) { - my $amount_needed = sprintf('%.0f', $self->ore_to_build * $self->upgrade_cost * 0.20); - if ($planet->gypsum_stored + $planet->sulfur_stored + $planet->monazite_stored < $amount_needed) { - confess [1012,"You do not have a sufficient supply (".$amount_needed.") of phosphorus from sources like Gypsum, Sulfur, and Monazite to create the chemical compounds to terraform a planet."]; - } + my $self = shift; + my $planet = $self->body; + unless ($planet->get_plan(ref $self, $self->level + 1)) { + my $amount_needed = sprintf('%.0f', $self->ore_to_build * $self->upgrade_cost * 0.20); + if ($planet->gypsum_stored + $planet->sulfur_stored + $planet->monazite_stored < $amount_needed) { + confess [1012,"You do not have a sufficient supply (".$amount_needed.") of phosphorus from sources like Gypsum, Sulfur, and Monazite to create the chemical compounds to terraform a planet."]; } + } }; use constant image => 'terraformingplatform'; diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index c4897086..d61b1654 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -1006,8 +1006,8 @@ sub recalc_stats { # Decrease happiness production if short on plots. if ($stats{plots_available} < 0) { my $plot_tax = int(50 * 1.62 ** (abs($stats{plots_available})-1)); - $plot_tax = 120_000_000_000 if ($plot_tax > 120_000_000_000); $stats{happiness_hour} -= $plot_tax; + $stats{happiness_hour} = -100_000_000_000 if ($stats{happiness_hour} < -100_000_000_000); } $self->update(\%stats);