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->{capacity}; # cost multiplier
+ my $maxmult = $unit->{upgraded}->{capacity} &&
+ 100 / $unit->{upgraded}->{capacity};
+
+ 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]
(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" : (),
),
),