From b53eb5282fd3cdf60ee1636ac5b92ca7bc569623 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Tue, 4 Oct 2011 13:34:13 -0400 Subject: [PATCH] Fixed #35 Space ports can no longer hold ships when they are damaged --- lib/Lacuna/DB/Result/Building.pm | 34 +++++++++++----------- lib/Lacuna/DB/Result/Building/Shipyard.pm | 6 +++- lib/Lacuna/DB/Result/Building/SpacePort.pm | 6 +++- var/www/public/changes.txt | 4 ++- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index 59849957..c6e60530 100755 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -903,23 +903,23 @@ sub repair { my $body = $self->body; my $fix = 100; my $c_eff = $self->efficiency; - unless ($body->food_stored >= $costs->{food} or $costs->{food} == 0) { - my $teff = int(($body->food_stored-50)*100/$costs->{food}); - $fix = $teff if ($teff < $fix); + if ($body->food_stored < $costs->{food} and $costs->{food} > 0) { + my $teff = int(($body->food_stored-50)*100/$costs->{food}); + $fix = $teff if ($teff < $fix); } - unless ($body->water_stored >= $costs->{water} or $costs->{water} == 0) { - my $teff = int($body->water_stored*100/$costs->{water}); - $fix = $teff if ($teff < $fix); + if ($body->water_stored < $costs->{water} and $costs->{water} > 0) { + my $teff = int($body->water_stored*100/$costs->{water}); + $fix = $teff if ($teff < $fix); } - unless ($body->ore_stored >= $costs->{ore} or $costs->{ore} == 0) { - my $teff = int(($body->ore_stored-50)*100/$costs->{ore}); - $fix = $teff if ($teff < $fix); + if ($body->ore_stored < $costs->{ore} and $costs->{ore} > 0) { + my $teff = int(($body->ore_stored-50)*100/$costs->{ore}); + $fix = $teff if ($teff < $fix); } - unless ($body->energy_stored >= $costs->{energy} or $costs->{energy} == 0) { - my $teff = int($body->energy_stored*100/$costs->{energy}); - $fix = $teff if ($teff < $fix); + if ($body->energy_stored < $costs->{energy} and $costs->{energy} > 0) { + my $teff = int($body->energy_stored*100/$costs->{energy}); + $fix = $teff if ($teff < $fix); } - unless ($fix > 0) { + if ($fix <= 0) { confess [1011, 'Not enough resources to do a partial repair.']; } $costs->{food} = int($fix*$costs->{food}/100); @@ -928,10 +928,10 @@ sub repair { $costs->{energy} = int($fix*$costs->{energy}/100); my $n_eff = 100; if ($fix < 100) { - my $p_add = int( (100 - $c_eff) * $fix/100 + 0.5); - $p_add = 1 if $p_add < 1; - $n_eff = $c_eff + $p_add; - $n_eff = 100 if ($n_eff > 100); + my $p_add = int( (100 - $c_eff) * $fix/100 + 0.5); + $p_add = 1 if $p_add < 1; + $n_eff = $c_eff + $p_add; + $n_eff = 100 if ($n_eff > 100); } $self->efficiency($n_eff); $self->update; diff --git a/lib/Lacuna/DB/Result/Building/Shipyard.pm b/lib/Lacuna/DB/Result/Building/Shipyard.pm index cf0446a7..8de79936 100644 --- a/lib/Lacuna/DB/Result/Building/Shipyard.pm +++ b/lib/Lacuna/DB/Result/Building/Shipyard.pm @@ -65,7 +65,11 @@ has max_ships => ( lazy => 1, default => sub { my $self = shift; - return Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { class => $self->class, body_id => $self->body_id } )->get_column('level')->sum; + return Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { + class => $self->class, + body_id => $self->body_id, + efficiency => 100, + } )->get_column('level')->sum; }, ); diff --git a/lib/Lacuna/DB/Result/Building/SpacePort.pm b/lib/Lacuna/DB/Result/Building/SpacePort.pm index d85dec4e..f11b5023 100755 --- a/lib/Lacuna/DB/Result/Building/SpacePort.pm +++ b/lib/Lacuna/DB/Result/Building/SpacePort.pm @@ -71,7 +71,11 @@ has max_ships => ( lazy => 1, default => sub { my $self = shift; - my $levels = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { class => $self->class, body_id => $self->body_id } )->get_column('level')->sum; + my $levels = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( { + class => $self->class, + body_id => $self->body_id, + efficiency => 100, + } )->get_column('level')->sum; return $levels * 2; }, ); diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index fdb6571c..4d054ca2 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -2,10 +2,12 @@ - Fix: Alliance Stats now shows number of space stations and influence - Fix: Updated documentation for Shipyard - Fix: API - Added surface version number for bodies to better indicate that a refresh is needed - - Fix: It is no longer possible to downgrade a spaceport if it could no longer support the number of ships. + - Fix: It is no longer possible to downgrade a spaceport if it could not support the number of ships present. - Fix: Very high negative happiness, and very long building times should not now crash the planet - Fix: Empires no longer show a 'ghost' alliance when they leave in the stats page - Fix: Partial repairs on buildings, dependent upon resources, is now possible + - Fix: Damaged Space Ports no longer count towards the max ships a colony can support + - Fix: Damaged Shipyards no longer count towards the max ships a colony can build 3.0814 - Fix: creating a munitions lab does not break isolation status -- 2.51.2