sc: hidden order by attack damage
[sheet.git] / sc.plp
diff --git a/sc.plp b/sc.plp
index 2217dc67d09b634cb84d6ffb377c0fd76d64c466..2b8112dc79fbd1ad196fd54a08eb4f5caaf09d5b 100644 (file)
--- a/sc.plp
+++ b/sc.plp
@@ -1,5 +1,5 @@
 <(common.inc.plp)><:
-use List::Util qw(max);
+use List::Util qw(max sum);
 
 my %scver = (
        id => 'bw',
@@ -75,10 +75,10 @@ for my $unit (@{$units}) {
 }
 
 sub coltoggle {
-       my ($name, $id) = @_;
+       my ($name, $id, $nolink) = @_;
        return sprintf(
                (defined $get{order} ? $get{order} eq $id : !$id) ? '%2$s ▼'
-                       : '<a href="?%s">%s</a>',
+                       : $nolink ? '%2$s' : '<a href="?%s">%s</a>',
                $id && "order=$id", $name
        );
 }
@@ -94,7 +94,7 @@ sub coltoggle {
        <th class="val unit-shield">shield</th>
        <th class="val unit-armor" title="armor">⛨</th>
        <th class="val hurt" colspan=3>attack</th>
-       <th class="hurt hurtrel">dps</th>
+       <th class="hurt hurtrel"><:= coltoggle(qw'dps attack 1') :></th>
        <th class="val unit-range">range</th>
        <th class="val unit-sight">sight</th>
        <th class="val unit-speed">speed</th>
@@ -295,6 +295,17 @@ sub showrange {
                                $_->{gas}*1.5 + $_->{min} + $_->{unit}/8 + $_->{build}/256/8
                        ) for @$units;
                }
+               elsif ($get{order} eq 'attack') {
+                       $_->{order} = $_->{hp} / 1024 + $_->{shield} / 1008 + max(
+                               map {
+                                       ((map { ref $_ ? $_->[-1] : $_ } $_->{damage})[0])
+                                       * ($_->{count} // 1) / ($_->{cooldown} // 1)
+                                       * ($_->{splash} ? 1.01 : 1)
+                                       * ($_->{type} eq 'implosive' ? .96 : 1)
+                                       * ($_->{type} eq 'explosive' ? .98 : 1)
+                               } @{ $_->{attack} }
+                       ) for @$units;
+               }
                else {
                        $units->[$_]->{order} = $_ for 0 .. $#$units;
                }