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