From 8d622986d9301d32648c843a8ac6e128b3cc8765 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Fri, 14 Jan 2011 15:19:39 -0600 Subject: [PATCH] may have fixed ore concentration problem --- lib/Lacuna/DB/Result/Building.pm | 2 +- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index 88ad3e00..584a7cd4 100644 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -407,7 +407,7 @@ sub mining_production_bonus { sub ore_production_hour { my ($self) = @_; - my $base = $self->ore_production * $self->production_hour; + my $base = $self->ore_production * $self->production_hour * ($self->body->total_ore_concentration / 10000); return 0 if $base == 0; return sprintf('%.0f', $base * $self->mining_production_bonus); } diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 478e2866..5a654638 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -678,6 +678,19 @@ sub found_colony { return $self; } +has total_ore_concentration => ( + is => 'ro', + lazy => 1, + default => sub { + my $self = shift; + my $tally = 0; + foreach my $type (ORE_TYPES) { + $tally += $self->$type; + } + return $tally; + }, +); + sub recalc_stats { my ($self) = @_; my %stats = ( needs_recalc => 0 ); @@ -730,7 +743,7 @@ sub recalc_stats { my $overage; foreach my $type (ORE_TYPES) { my $method = $type.'_hour'; - my $planet_side = sprintf('%.0f',$self->$type * $stats{ore_hour} / 10000); # calculate local spend/prod + my $planet_side = sprintf('%.0f',$self->$type * $stats{ore_hour} / $self->total_ore_concentration); # calculate local spend/prod if ($planet_side < 0 && abs($planet_side) > $stats{$method}) { # local spend might be more than local production $overage += abs($planet_side) - $stats{$method}; # make up the difference with an overage $stats{$method} = 0; -- 2.54.0