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