sc: describe bonus damage in legend for hots mode
[sheet.git] / sc.plp
1 <(common.inc.plp)><:
2
3 my %scver = (
4         id => 'bw',
5         name => 'Brood War',
6         title => 'starcraft',
7         game => 'StarCraft',
8         major => 1,
9 );
10
11 if ($ENV{PATH_INFO} and $ENV{PATH_INFO} eq '/2') {
12         %scver = (
13                 id => 'hots',
14                 name => 'Heart of the Swarm',
15                 title => 'starcraft2',
16                 game => 'StarCraft II',
17                 major => 2,
18         );
19 }
20 my $datafile = "sc-units-$scver{id}.inc.pl";
21
22 Html({
23         title => "$scver{title} unit cheat sheet",
24         version => 'v1.1',
25         description => [
26                 "Reference of $scver{game} unit properties,"
27                 . " comparing various statistics of all the units in $scver{name}"
28                 . ' including costs, damage, defense, speed, ranges, and abilities.',
29         ],
30         keywords => [
31                 qw'
32                 starcraft game unit statistics stats comparison table sheet cheat
33                 reference software attributes properties
34                 ',
35                 $scver{major} < 2 ? qw' bw broodwar brood war ' : qw' starcraft2 hots ',
36         ],
37         stylesheet => [qw'light'],
38         raw => '<link rel="stylesheet" type="text/css" media="all" href="/sc.css?1.1" title="light">',
39         data => [$datafile],
40 });
41
42 print "<h1>$scver{game} units</h1>\n\n";
43
44 my $units = do $datafile;
45 die "Cannot open unit data: $_\n" for $@ || $! || ();
46 my $patch = shift @{$units}
47         or die "Cannot open unit data: metadata not found\n";
48
49 print "<p>Unit properties as seen or measured in $scver{name}\n$patch.\n</p>\n\n";
50
51 sub addupgrade {
52         my ($ref, $increase) = @_;
53         if (ref $increase eq 'HASH') {
54                 addupgrade(\${$ref}->{$_}, $increase->{$_}) for keys %{$increase};
55         }
56         elsif (ref $increase eq 'ARRAY') {
57                 addupgrade(\${$ref}->[$_], $increase->[$_]) for 0 .. $#{$increase};
58         }
59         ${$ref} += $increase if $increase =~ /^-?[0-9.]+/;
60 }
61
62 for my $unit (@{$units}) {
63         for my $upgrade (@{ $unit->{upgrade} }) {
64                 while (my ($col, $increase) = each %{$upgrade}) {
65                         defined $unit->{$col} or next;
66                         addupgrade(\( $unit->{upgraded}->{$col} //= $unit->{$col} ), $increase);
67                 }
68         }
69 }
70
71 sub coltoggle {
72         my ($name, $id) = @_;
73         return sprintf(
74                 (defined $get{order} ? $get{order} eq $id : !$id) ? '%2$s ▼'
75                         : '<a href="?%s">%s</a>',
76                 $id && "order=$id", $name
77         );
78 }
79 :><table class="units">
80 <thead><tr>
81         <th></th>
82         <th><:= coltoggle('name', '') :></th>
83         <th class="val min"><img src="/minerals.png" alt="min"></th>
84         <th class="val gas"><img src="/gas.png" alt="gas"></th>
85         <th class="val time"><:= coltoggle(qw'build cost') :></th>
86         <th class="unit" colspan="4"><:= coltoggle(qw'size size') :></th>
87         <th class="val unit-hp">HP</th>
88         <th class="val unit-shield">shield</th>
89         <th class="val unit-armor" title="armor">⛨</th>
90         <th class="val hurt" colspan=3>attack</th>
91         <th class="hurt hurtrel">dps</th>
92         <th class="val unit-range">range</th>
93         <th class="val unit-sight">sight</th>
94         <th class="val unit-speed">speed</th>
95         <th class="unit-magic">specials</th>
96 </tr></thead>
97 <:
98 sub showrange {
99         my ($min, $max) = @_;
100         return '' if not defined $min;
101         $_ &&= int($_ + .5) for $min, $max;  # round halves up
102         return $min if not defined $max or $min == $max;
103         return "$min-$max";
104 }
105
106         sub showattack {
107                 my ($row, $area) = @_;
108                 my $attack = $row->{attack}->[$area]
109                         or return '<td colspan=4 class="hurt">';
110
111                 my $out = '';
112                 $out .= '<td class="unit hurt-g">' . '▽' x !!($attack->{anti} & 1);
113                 $out .= '<td class="unit hurt-a">' . '△' x !!($attack->{anti} & 2);
114                 $out .= '<td class="val hurt">';
115
116                 my $upattack = $row->{upgraded}->{attack}->[$area];
117                 my $damage = $attack->{damage};
118                 my $maxdamage = $upattack->{damage} // $damage;
119                 $damage = $damage->[0] if ref $damage;
120                 $maxdamage = $maxdamage->[-1] if ref $maxdamage;
121
122                 $out .= "<small>$attack->{count}× </small>" if $attack->{count} > 1;
123                 $out .= '<span class="unit-l" title="explosive">*</span>'
124                         if $attack->{type} eq 'explosive';
125                 $out .= '<span class="unit-s" title="implosive">~</span>'
126                         if $attack->{type} eq 'implosive';
127                 $out .= sprintf('<span class="%s" title="%s">&ge;</span>',
128                         (map {
129                                 $_ =~ /^light/ ? 'unit-s' :
130                                 $_ eq 'armored' ? 'unit-l' :
131                                 $_ eq 'organic' ? 'unit-o' :
132                                 $_ =~ /^massive/ ? 'unit-h' :
133                                 '',
134                         } join '_', keys %{ $attack->{bonus} }),
135                         join(', ', map {(
136                                 sprintf('+%s vs %s',
137                                         (map {
138                                                 ref $_ ? showrange($_->[0], $_->[-1]) : $_
139                                         } $attack->{bonus}->{$_}),
140                                         $_,
141                                 ),
142                         )} keys %{ $attack->{bonus} }),
143                 ) if $attack->{bonus};
144                 $out .= showrange($damage, $maxdamage);
145                 $out .= sprintf('<span class="unit-splash" title="%s">%s</span>',
146                         $attack->{splash} eq 'line' ? ('linear', '×') : ('splash', '+')
147                 ) if $attack->{splash};
148
149                 $out .= '<td class="val hurt hurtrel">';
150                 if ($attack->{cooldown}) {
151                         if (my $type = $attack->{type}) {
152                                 if ($type eq 'explosive') {
153                                         $damage /= 2;
154                                 }
155                                 elsif ($type eq 'implosive') {
156                                         $damage /= 4;
157                                 }
158                         }
159                         $damage *= ($attack->{count} // 1) / $attack->{cooldown};
160                         $maxdamage *= ($upattack->{count} // $attack->{count} // 1)
161                                     / ($upattack->{cooldown} // $attack->{cooldown});
162                         $out .= showrange($damage, $maxdamage);
163                 }
164
165                 return $out;
166         }
167
168         sub showmagic {
169                 my ($row) = @_;
170                 my $specials = $row->{special} or return '';
171                 return join ' ', map {
172                         sprintf '<span%s title="%s">%s</span>',
173                                 $_->{duration} < 0 && ' class="magic-perma"',
174                                 join('',
175                                         $_->{name},
176                                         $_->{desc} ? ": $_->{desc}" : '',
177                                         $_->{range} || $_->{cost} ? sprintf(' (%s)', join ', ',
178                                                 $_->{range} ? "range $_->{range}" : (),
179                                                 $_->{cost} ? sprintf('cost %.0f%%%s',
180                                                         100 * $_->{cost} / $row->{energy},
181                                                         defined $_->{maint} && sprintf('+%.1f%%/s',
182                                                                 100 * $_->{maint} / $row->{energy},
183                                                         ),
184                                                 ) : (),
185                                         ) : '',
186                                 ),
187                                 sprintf($_->{build} ? '(%s)' : '%s', $_->{abbr}),
188                 } grep { defined $_->{abbr} } @{$specials};
189         }
190
191         sub showunitcols {
192                 my ($row) = @_;
193                 local $_ = $row;
194                 $_->{hp} += $_->{shield} if $_->{shield};
195                 my $suitchar = '';
196                 if ($_->{attr}->{structure}) {
197                         $suitchar = 'b';
198                 }
199                 elsif ($_->{suit}) {
200                         $suitchar = [qw/? s m l/]->[$_->{suit}];
201                 }
202                 elsif ($_->{cargo} > 0) {
203                         $suitchar = [qw/? s m l l h h h h/]->[abs $_->{cargo}];
204                 }
205                 elsif ($_->{size}) {
206                         $suitchar = [qw/s m l h h h/]->[$_->{size}];
207                 }
208                 elsif ($_->{attr} and $_->{attr}->{light}) {
209                         $suitchar = 's';
210                 }
211                 elsif ($_->{attr} and $_->{attr}->{armored}) {
212                         $suitchar = 'l';
213                 }
214
215                 return (
216                         '<td class="val min">' . ($_->{min} // ''),
217                         '<td class="val gas">' . ($_->{gas} || ''),
218                         !defined $_->{build} ? '<td>' : sprintf('<td class="val time">%s%.0f',
219                                 !!$_->{base} && '<span class="unit-composed">+</span>',
220                                 $_->{build} || '0',
221                         ),
222                         !$suitchar ? '<td>' : sprintf('<td class="unit unit-%s">%s%s',
223                                 $suitchar, ucfirst $suitchar,
224                                 $_->{attr}->{massive}
225                                         && '<span class="unit-massive" title="massive">⚓</span>',
226                         ),
227                         '<td class="val unit">' . (
228                                 defined $_->{unit} && $_->{unit} == .5 ? '½' : $_->{unit}
229                         ),
230                         '<td class="unit unit-type">' . join('', grep { $_ }
231                                 (defined $_->{organic} ? !$_->{organic} : $_->{attr}->{mech})
232                                         && '<span class="unit-u" title="mechanic">m</span>',
233                                 ($_->{organic} || $_->{attr}->{organic})
234                                         && '<span class="unit-o" title="organic">o</span>',
235                                 $_->{attr}->{psionic}
236                                         && '<span class="unit-p" title="psionic">ψ</span>',
237                         ),
238                         '<td class="unit unit-attr">' . join('', grep { $_ }
239                                 $_->{attr}->{armored}
240                                         && '<span class="unit unit-l" title="armored">A</span>',
241                                 $_->{attr}->{light}
242                                         && '<span class="unit unit-s" title="light">L</span>',
243                         ),
244                         '<td class="val unit-hp">' . $_->{hp} // '',
245                         $_->{shield} ? sprintf('<td class="val unit-shield">%.0f%%<td',
246                                 100 * $_->{shield} / $_->{hp}
247                         ) : '<td colspan=2',
248                         ' class="val unit-armor">' .
249                                 showrange($_->{armor}, $_->{upgraded}->{armor}),
250                         showattack($_, 0),
251                         '<td class="val unit-range">' .
252                                 showrange(map { $_->{attack}->[0]->{range} } $_, $_->{upgraded}),
253                         '<td class="val unit-sight">' . sprintf(
254                                 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
255                                 showrange($_->{sight}, $_->{upgraded}->{sight})
256                         ),
257                         '<td class="val unit-speed">' .
258                                 showrange($_->{speed}, $_->{upgraded}->{speed}),
259                         $_->{attr}->{jump}
260                                 && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
261                         $_->{attr}->{flying}
262                                 && qq'<span class="unit unit-jump" title="flying">↑</span>',
263                         '<td class="unit-magic">' . showmagic($_),
264                         !$_->{attack}->[1] ? () : (
265                                 '<tr><td colspan=12>', showattack($_, 1), '<td colspan=4>'
266                         ),
267                         "\n"
268                 );
269         }
270
271         my $grouped = 1;  # race headers
272         if (exists $get{order}) {
273                 $grouped = 0;
274                 $get{order} ||= '';
275                 if ($get{order} eq 'size') {
276                         $_->{order} = $_->{unit}*8 + $_->{suit} + $_->{hp}/512 + $_->{min}/8192 for @$units;
277                 }
278                 elsif ($get{order} eq 'cost') {
279                         $_->{order} = $_->{gas}*1.5 + $_->{min} + $_->{unit}/8 + $_->{build}/256/8 for @$units;
280                 }
281                 else {
282                         $units->[$_]->{order} = $_ for 0 .. $#$units;
283                 }
284         }
285         my @rows = @{$units};
286         @rows = sort {$a->{order} <=> $b->{order}} @rows unless $grouped;
287
288         my ($race, $cat) = ('', '');
289         for (@rows) {
290                 if ($grouped) {
291                         printf '<tbody id="%s"><tr class="race"><th colspan="20"><h2>%s</h2>'."\n",
292                                 $race = $_->{race}, ucfirst $race
293                                         unless $race eq $_->{race};
294                 }
295                 else {
296                         $_->{cat} = $_->{race};
297                 }
298
299                 print(
300                         '<tr>',
301                         '<th class="cat">', $cat ne $_->{cat} && ($cat = $_->{cat}),
302                         '<td>', $_->{name},
303                         showunitcols($_),
304                 );
305
306                 for my $subrow (@{ $_->{special} }) {
307                         $subrow->{alt} or next;
308                         print(
309                                 '<tr class="alt"><th class="cat"><td>', $subrow->{alt},
310                                 showunitcols($subrow),
311                         );
312                 }
313         }
314 :>
315 </table>
316
317 <div class="legend">
318 <h2>Legend</h2>
319
320 <dl>
321 <dt>cost
322         <dd>minerals+gas required to create one unit
323         <dd>includes total expenses if based on existing units
324 <dt>build
325         <dd>relative time needed to create at least one unit
326         <dd>excludes construction of dependencies such as buildings
327                 and <span class="unit-composed">+</span>parent units
328 <dt>size
329         <dd><:
330 if ($scver{major} > 1) {
331                 :>transports can fit 8 <span class="unit unit-s">S</span>mall,
332                 4 <span class="unit unit-m">M</span>edium,
333                 2 <span class="unit unit-l">L</span>arge,
334                 or a single <span class="unit unit-h">H</span>uge unit
335         <dd>massive <span class="unit-massive">⚓</span> units
336                 cannot be lifted or slowed and can break force fields<:
337 } else {
338                 :>affected by <span class="unit unit-s">S</span>mall,
339                 <span class="unit unit-m">M</span>edium, or
340                 <span class="unit unit-l">L</span>arge unit damage<:
341 } :>
342         <dd>number of command points taken per unit
343         <dd><:
344 if ($scver{major} > 1) {
345                 :>received damage depends on
346                 <span class="unit unit-o">o</span>rganic,
347                 <span class="unit unit-u">m</span>echanic,
348                 <span class="unit unit-p">ψ</span>(ps)ionic,
349                 <span class="unit unit-s">L</span>ight, and
350                 <span class="unit unit-l">A</span>rmored
351                 attributes<:
352 } else {
353                 :><span class="unit unit-o">o</span>rganic/<span class="unit unit-u">m</span>echanic unit<:
354 } :>
355 <dt>HP<dd>
356         total number of hitpoints (including shields)
357 <dt>shield
358         <dd>percentage of HP in shields
359         <dd>shields always take full damage, irrelevant of unit size
360         <dd>does not take armor bonuses, but upgrades can decrease damage to any shield hit by upto 3
361 <dt>armor
362         <dd>base unit armor
363         <dd>can be increased by upto 3 at various facilities
364         <dd>each point decreases damage per hit by one, upto a minimum of ½
365         <dd>reduction applies to initial damage, before size penalties
366                 <small>(so a plasma hit of 12 to 4 armor large deals 2 damage, not ½)</small>
367 <dt>attack
368         <dd>targets <span class="hurt-g">▽</span>&nbsp;ground
369                 and/or  <span class="hurt-a">△</span>&nbsp;air
370         <dd>damage given per single hit
371         <dd><span class="hurtrel">dps</span> indicates relative amount of damage
372                 done in 1 second of in-game time
373         <dd>splash damage hits all objects nearby <span class="unit-splash">+</span>
374                 or in a straight line <span class="unit-splash">×</span>.
375         <dd><:
376 if ($scver{major} > 1) {
377                 :>does not include <span>&ge;</span>bonus damage
378                 dealt to susceptible unit types<:
379 } else {
380                 :><span class="unit-l">*</span>explosive damage does only
381                 50% damage to small units, 75% to medium, 100% to large
382         <dd><span class="unit-s">~</span>concussive/plasma damage does
383                 25% to large, 50% medium, 100% to small units<:
384 } :>
385 <dt>sight
386         <dd>range in which the unit detects other units
387         <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
388 <dt>range
389         <dd>maximum range of weapon (note siege tank also has a minimum range)
390 <dt>speed
391         <dd>relative speed of movement (when in full motion, startup speed ignored)
392 <dt>specials
393         <dd>special abilities are usually casted manually, but some are <span class="magic-perma">always active</span>
394         <dd>parentheses () indicate that it needs to be researched first
395         <dd>hover for description
396         <dd>range is maximum range required to activate
397         <dd>cost is percentage of total energy lost
398 </dl>
399
400 <p>
401 When two values are given (1-2), second value indicates attribute after all
402 possible upgrades.
403 </p>
404
405 </div>
406