sc: hidden order by attack damage
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 19 Jun 2015 10:14:09 +0000 (12:14 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 22 Jun 2015 13:38:51 +0000 (15:38 +0200)
sc.plp

diff --git a/sc.plp b/sc.plp
index 2217dc6..2b8112d 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;
                }