From bbe1c1a5e6f4573537689843597bf2d380fc690c Mon Sep 17 00:00:00 2001 From: ysth Date: Sun, 2 Dec 2012 11:20:46 -0800 Subject: [PATCH 1/3] Partial repair cost fix --- lib/Lacuna/DB/Result/Building.pm | 47 +++++++++++++++----------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index f5d19cf8..9bb3e79e 100755 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -916,24 +916,25 @@ sub can_repair { my ($self, $costs) = @_; $costs ||= $self->get_repair_costs; my $body = $self->body; - my $fix = 100; + my $damage = 100 - $self->efficiency; + my $fix = $damage; if ($body->food_stored < $costs->{food} and $costs->{food} > 0) { - my $teff = int(($body->food_stored-50)*100/$costs->{food}); + my $teff = int($body->food_stored * $damage / $costs->{food}); $fix = $teff if ($teff < $fix); } if ($body->water_stored < $costs->{water} and $costs->{water} > 0) { - my $teff = int($body->water_stored*100/$costs->{water}); + my $teff = int($body->water_stored * $damage / $costs->{water}); $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}); + my $teff = int($body->ore_stored * $damage / $costs->{ore}); $fix = $teff if ($teff < $fix); } if ($body->energy_stored < $costs->{energy} and $costs->{energy} > 0) { - my $teff = int($body->energy_stored*100/$costs->{energy}); + my $teff = int($body->energy_stored * $damage / $costs->{energy}); $fix = $teff if ($teff < $fix); } - if ($fix <= 0) { + if ($damage && $fix <= 0) { confess [1011, 'Not enough resources to do a partial repair.']; } return 1; @@ -943,39 +944,35 @@ sub repair { my ($self, $costs) = @_; $costs ||= $self->get_repair_costs; my $body = $self->body; - my $fix = 100; - my $c_eff = $self->efficiency; + my $damage = 100 - $self->efficiency; + if ($damage <= 0) { + return 0; + } + my $fix = $damage; if ($body->food_stored < $costs->{food} and $costs->{food} > 0) { - my $teff = int(($body->food_stored-50)*100/$costs->{food}); + my $teff = int($body->food_stored * $damage / $costs->{food}); $fix = $teff if ($teff < $fix); } if ($body->water_stored < $costs->{water} and $costs->{water} > 0) { - my $teff = int($body->water_stored*100/$costs->{water}); + my $teff = int($body->water_stored * $damage / $costs->{water}); $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}); + my $teff = int($body->ore_stored * $damage / $costs->{ore}); $fix = $teff if ($teff < $fix); } if ($body->energy_stored < $costs->{energy} and $costs->{energy} > 0) { - my $teff = int($body->energy_stored*100/$costs->{energy}); + my $teff = int($body->energy_stored * $damage / $costs->{energy}); $fix = $teff if ($teff < $fix); } if ($fix <= 0) { -# confess [1011, 'Not enough resources to do a partial repair.']; - return 0; - } - $costs->{food} = int($fix*$costs->{food}/100); - $costs->{water} = int($fix*$costs->{water}/100); - $costs->{ore} = int($fix*$costs->{ore}/100); - $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); + return 0; } + $costs->{food} = int($fix*$costs->{food}/$damage); + $costs->{water} = int($fix*$costs->{water}/$damage); + $costs->{ore} = int($fix*$costs->{ore}/$damage); + $costs->{energy} = int($fix*$costs->{energy}/$damage); + my $n_eff = $self->efficiency + $fix; $self->efficiency($n_eff); $self->update; $body->spend_food($costs->{food}, 0); -- 2.51.2 From 843890ff64dd0aa479a66a820e42ac4845d61b63 Mon Sep 17 00:00:00 2001 From: ysth Date: Sun, 2 Dec 2012 14:53:01 -0800 Subject: [PATCH 2/3] waste chain capacity: truncate, don't round, so .5% doesn't round up to 1% (essentially doubling capacity) --- 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 9df24aeb..cbf440c9 100644 --- a/lib/Lacuna/DB/Result/Building/Trade.pm +++ b/lib/Lacuna/DB/Result/Building/Trade.pm @@ -264,7 +264,7 @@ sub recalc_waste_production { while (my $waste_chain = $waste_chains->next) { $chain_wphpd += $body->calculate_distance_to_target($waste_chain->star) * 2 * $waste_chain->waste_hour; } - my $shipping_capacity = $chain_wphpd ? sprintf('%.0f',($ship_wphpd / $chain_wphpd) * 100) : 0; + my $shipping_capacity = $chain_wphpd ? int(100 * $ship_wphpd / $chain_wphpd) : 0; $waste_chains->reset; while (my $waste_chain = $waste_chains->next) { -- 2.51.2 From 5c8e963e093709cc4c19d44a6dd1d2081777466d Mon Sep 17 00:00:00 2001 From: ysth Date: Sun, 2 Dec 2012 15:11:47 -0800 Subject: [PATCH 3/3] repair: don't run food and ore down to 0 --- lib/Lacuna/DB/Result/Building.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index 9bb3e79e..2da8d2d5 100755 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -918,16 +918,16 @@ sub can_repair { my $body = $self->body; my $damage = 100 - $self->efficiency; my $fix = $damage; - if ($body->food_stored < $costs->{food} and $costs->{food} > 0) { - my $teff = int($body->food_stored * $damage / $costs->{food}); + if ($body->food_stored-50 < $costs->{food} and $costs->{food} > 0) { + my $teff = int(($body->food_stored-50) * $damage / $costs->{food}); $fix = $teff if ($teff < $fix); } if ($body->water_stored < $costs->{water} and $costs->{water} > 0) { my $teff = int($body->water_stored * $damage / $costs->{water}); $fix = $teff if ($teff < $fix); } - if ($body->ore_stored < $costs->{ore} and $costs->{ore} > 0) { - my $teff = int($body->ore_stored * $damage / $costs->{ore}); + if ($body->ore_stored-50 < $costs->{ore} and $costs->{ore} > 0) { + my $teff = int(($body->ore_stored-50) * $damage / $costs->{ore}); $fix = $teff if ($teff < $fix); } if ($body->energy_stored < $costs->{energy} and $costs->{energy} > 0) { @@ -949,16 +949,16 @@ sub repair { return 0; } my $fix = $damage; - if ($body->food_stored < $costs->{food} and $costs->{food} > 0) { - my $teff = int($body->food_stored * $damage / $costs->{food}); + if ($body->food_stored-50 < $costs->{food} and $costs->{food} > 0) { + my $teff = int(($body->food_stored-50) * $damage / $costs->{food}); $fix = $teff if ($teff < $fix); } if ($body->water_stored < $costs->{water} and $costs->{water} > 0) { my $teff = int($body->water_stored * $damage / $costs->{water}); $fix = $teff if ($teff < $fix); } - if ($body->ore_stored < $costs->{ore} and $costs->{ore} > 0) { - my $teff = int($body->ore_stored * $damage / $costs->{ore}); + if ($body->ore_stored-50 < $costs->{ore} and $costs->{ore} > 0) { + my $teff = int(($body->ore_stored-50) * $damage / $costs->{ore}); $fix = $teff if ($teff < $fix); } if ($body->energy_stored < $costs->{energy} and $costs->{energy} > 0) { -- 2.51.2