sc: include upgraded cast costs
[sheet.git] / sc.plp
diff --git a/sc.plp b/sc.plp
index 5b7e4a7a1a1ef7cac4fc92c88063036a532f2190..28d22d71c56290b57b38df0ed8c7d43002bb975b 100644 (file)
--- a/sc.plp
+++ b/sc.plp
@@ -95,10 +95,11 @@ sub coltoggle {
 <thead><tr>
        <th></th>
        <th><:= coltoggle('name', '') :></th>
-       <th class="val min"><img src="/minerals.png" alt="min"></th>
-       <th class="val gas"><img src="/gas.png" alt="gas"></th>
+       <th class="val min" title=minerals>cost</th>
+       <th class="val gas">gas</th>
        <th class="val time"><:= coltoggle(qw'build cost') :></th>
-       <th class="unit" colspan="4"><:= coltoggle(qw'size size') :></th>
+       <th class="unit" colspan="2"><:= coltoggle(qw'size size') :></th>
+       <th class="unit" colspan="2">attr</th>
        <th class="val unit-hp">HP</th>
        <th class="val unit-shield">shield</th>
        <th class="val unit-armor" title="armor">⛨</th>
@@ -114,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]
@@ -129,6 +147,8 @@ sub showrange {
                $maxdamage += ($upattack->{upgrade} // $attack->{upgrade}) * 3;
 
                my $out = '<td class="val hurt">';
+               $out .= sprintf '<span title="%s">¤</span> ', showcost($attack, $row)
+                       if $attack->{cost};
                $out .= sprintf('<small>%s× </small>',
                        showrange($attack->{count}, $upattack->{count}),
                ) if $attack->{count} > 1;
@@ -216,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" : (),
                                        ),
                                ),
@@ -241,11 +256,17 @@ sub showrange {
                                !!$_->{base} && '<span class="unit-composed">+</span>',
                                $_->{build} || '0',
                        ),
-                       sprintf('<td class="unit unit-%s" title="%3$s">%s',
-                               $_->{cargo} < 0      ? ('supply', T => 'transport') :
+                       sprintf('<td class="unit unit-%s" title="%4$s%3$s">%s',
+                               $_->            {cargo} < 0 ? ('supply',           T => 'transport') :
+                               $_->{upgraded}->{cargo} < 0 ? ('supply magic-opt', T => 'optional transport') :
                                $_->{attr}->{flying}    ? ('air', F => 'flying') :
                                $_->{attr}->{structure} ? ('x',   B => 'building') :
-                               ([qw( x s m l l h h h h )]->[ $_->{cargo} ], $_->{cargo} || '-', ''),
+                               (
+                                       [qw( x s m l l h h h h )]->[ $_->{cargo} ],
+                                       $_->{cargo} || '-',
+                                       $_->{cargo} ? 'transportable' : 'untransportable',
+                               ),
+                               defined $_->{size} && sprintf('⌀%.1f ', $_->{size}),
                        ),
                        sprintf('<td class="val unit%s">%s',
                                defined $_->{pop} && $_->{pop} < 0 && ' unit-supply',
@@ -291,8 +312,6 @@ sub showrange {
                                showrange($_->{speed}, $_->{upgraded}->{speed}),
                        $_->{attr}->{jump}
                                && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
-                       $_->{attr}->{flying}
-                               && qq'<span class="unit unit-jump" title="flying">↑</span>',
                        '<td class="unit-magic">' . showmagic($_),
                        !$_->{attack}->[1] ? () : (
                                '<tr><td colspan=12>', showattack($_, 1), '<td colspan=3>'