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