X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/4a625d5eed49b9c5b46fa9c7d4b6e04fa355fc64..011f00a2bb1ee8611b9fc8e4a1598c167f673c5f:/sc.plp diff --git a/sc.plp b/sc.plp index 5d82a8d..28d22d7 100644 --- a/sc.plp +++ b/sc.plp @@ -115,10 +115,27 @@ sub showrange { my ($min, $max) = @_; return '' if not defined $min; $_ &&= int($_ + .5) for $min, $max; # round halves up - return $min || '-' if not defined $max or $min == $max; + return $min || '-' if !$max or $min == $max; return "$min-$max"; } + sub showcost { + my ($row, $unit) = @_; + my $minmult = 100 / $unit->{energy}; # cost multiplier + my $maxmult = $unit->{upgraded}->{energy} && + 100 / $unit->{upgraded}->{energy}; + + return join(' ', + sprintf('cost %s%%', + showrange($row->{cost} * $minmult, $row->{cost} * $maxmult), + ), + !defined $row->{maint} ? () : sprintf('+%.1f%s%%/s', + $row->{maint} * $minmult, + !!$maxmult && sprintf('-%.1f', $row->{maint} * $maxmult), + ), + ); + } + sub showattack { my ($row, $area) = @_; my $attack = $row->{attack}->[$area] @@ -130,6 +147,8 @@ sub showrange { $maxdamage += ($upattack->{upgrade} // $attack->{upgrade}) * 3; my $out = ''; + $out .= sprintf '¤ ', showcost($attack, $row) + if $attack->{cost}; $out .= sprintf('%s× ', showrange($attack->{count}, $upattack->{count}), ) if $attack->{count} > 1; @@ -217,12 +236,7 @@ sub showrange { (map { $_ && " ($_)" } join ', ', #TODO: apply upgrades $_->{range} ? "range $_->{range}" : (), - $_->{cost} ? sprintf('cost %.0f%%%s', - 100 * $_->{cost} / $row->{energy}, - defined $_->{maint} && sprintf('+%.1f%%/s', - 100 * $_->{maint} / $row->{energy}, - ), - ) : + $_->{cost} ? showcost($_, $row) : $_->{cooldown} ? "cooldown $_->{cooldown}s" : (), ), ),