export and check last-modified header
[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 <tbody>
158 <:
159 sub showrange {
160         my ($row, @elements) = @_;
161         my ($min, $max);
162
163         my $value = $row;
164         $value = ref $value eq 'HASH' && $value->{$_} or last for @elements;
165         if (ref $value eq 'ARRAY') {
166                 $min = $value->[0];
167                 $max = $value->[-1];
168         }
169         else {
170                 $min = $max = $value;
171         }
172         defined $min or return '';
173
174         if ($row->{upgrade}) {
175                 for (@{ $row->{upgrade} }) {
176                         my $increase = $_ or next;
177                         $increase = ref $increase eq 'HASH' && $increase->{$_} or last for @elements;
178                         $increase = $increase->[-1] if ref $increase eq 'ARRAY';
179                         $max += $increase if $increase;
180                 }
181         }
182
183         if ($elements[0] eq 'attack' and $elements[1] ne 'range' and $elements[2] eq 'cmp') {{
184                 my $type = $row->{$elements[0]}->{$elements[1]}->{type} or next;
185                 if ($type eq 'explosive') {
186                         $min /= 2;
187                 }
188                 elsif ($type eq 'implosive') {
189                         $min /= 4;
190                 }
191                 $min = int($min + .5);  # round halves up
192         }}
193
194         return $min == $max ? $min : "$min-$max";
195 }
196
197         sub showattack {
198                 my ($row, $area) = @_;
199                 local $_ = $row->{attack}->{$area};
200
201                 return '<td colspan="2" class="hurt">' unless $_;
202
203                 my $tagbase = '<td class="val hurt';
204                 if (ref $_ and $_->{type}) {
205                         if ($_->{type} eq 'explosive') {
206                                 $tagbase .= ' unit-l';
207                         }
208                         elsif ($_->{type} eq 'implosive') {
209                                 $tagbase .= ' unit-s';
210                         }
211                 }
212                 $tagbase .= '">';
213
214                 my $out = showrange($row, 'attack', $area, 'damage');
215                 $out .= '<span class="unit-splash">+</span>' if $_->{splash};
216                 $out .= '<td class="val hurt hurtrel">' . showrange($row, 'attack', $area, 'cmp');
217                 return $tagbase . $out;
218         }
219
220         sub showmagic {
221                 my ($row) = @_;
222                 my $specials = $row->{special} or return '';
223                 return join ' ', map {
224                         sprintf '<span title="%s">%s</span>',
225                                 join('',
226                                         $_->{name},
227                                         $_->{desc} ? ": $_->{desc}" : '',
228                                         $_->{range} ? sprintf(' (%s)', join ', ',
229                                                 "range $_->{range}",
230 #                                               "cost $_->{cost}",
231                                         ) : '',
232                                 ),
233                                 $_->{abbr},
234                 } @$specials;
235         }
236
237         my $units = do 'sc-units.inc.pl';
238         die "Cannot open unit data: $_\n" for $! || $@ || ();
239         my $grouped = !exists $get{order};
240         if (exists $get{order}) {
241                 $get{order} ||= '';
242                 if ($get{order} eq 'size') {
243                         $_->{order} = $_->{unit}*8 + $_->{size} + $_->{hp}/512 + $_->{min}/8192 for @$units;
244                 }
245                 elsif ($get{order} eq 'cost') {
246                         $_->{order} = $_->{gas}*1.5 + $_->{min} + $_->{unit}/8 + $_->{build}/256/8 for @$units;
247                 }
248                 else {
249                         $units->[$_]->{order} = $_ for 0 .. $#$units;
250                 }
251         }
252         my @rows = $grouped ? @$units : sort {$a->{order} <=> $b->{order}} @$units;
253
254         my ($race, $cat) = ('', '');
255         for (@rows) {
256                 $race = $_->{race},
257                 printf '</tbody><tbody id="%s"><tr class="race"><th colspan="18"><h2>%s</h2>'."\n", $race, ucfirst $race
258                         if $grouped and $race ne $_->{race};
259                 $_->{cat} = $_->{race} if not $grouped;
260                 my $sizechar = [qw/? s m l/]->[$_->{size}];
261                 print(
262                         '<tr>',
263                         sprintf('<t%s class="cat">%s', $cat ne $_->{cat} ? ('h', $cat = $_->{cat}) : ('d', '&nbsp;')),
264                         '<td>' . $_->{name},
265                         '<td class="val min">' . ($_->{min} || '0'),
266                         '<td class="val gas">' . ($_->{gas} || ''),
267                         '<td class="val time">' . sprintf('%.0f', $_->{build} || '0'),
268                         sprintf('<td class="unit unit-%s">%s', $sizechar, ucfirst $sizechar),
269                         '<td class="val unit">' . join('',
270                                 $_->{unit} ? $_->{unit} == .5 ? '½' : $_->{unit} : '&nbsp;',
271                                 defined $_->{organic} && sprintf(
272                                         '<img class="unit-%s" src="s%s.png" alt="%s">',
273                                         $_->{organic} ? 'o' : 'u',
274                                         $_->{race} . ($_->{organic} ? 'o' : ''),
275                                         $_->{organic} ? 'o' : 'm'
276                                 ),
277                         ),
278                         '<td class="val unit-hp">' . $_->{hp},
279                         '<td class="val unit-shield">' . ($_->{shield} ? $_->{shield}.'%' : '&nbsp;'),
280                         '<td class="val unit-armor">' . showrange($_, 'armor'),
281                         showattack($_, 'ground'),
282                         showattack($_, 'air'),
283                         '<td class="val unit-range">' . showrange($_, 'attack', 'range'),
284                         '<td class="val unit-sight">' . sprintf(
285                                 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
286                                 showrange($_, 'sight')
287                         ),
288                         '<td class="val unit-speed">' . showrange($_, 'speed'),
289                         '<td class="unit-magic">' . showmagic($_),
290                         "\n"
291                 );
292
293                 for my $alt (grep { $_->{alt} } @{ $_->{special} }) {
294                         print(
295                                 '<tr class="alt"><td class="cat"><td colspan="9">' . $alt->{alt},
296                                 showattack($alt, 'ground'),
297                                 showattack($alt, 'air'),
298                                 '<td class="val unit-range">' . showrange($alt, 'attack', 'range'),
299                                 '<td class="val unit-sight">' . sprintf(
300                                         $alt->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
301                                         showrange($alt, 'sight')
302                                 ),
303                                 '<td class="val unit-speed">' . showrange($alt, 'speed'),
304                                 '<td>',
305                                 "\n",
306                         );
307                 }
308         }
309 :>
310 </tbody>
311 </table>
312
313 <div class="legend">
314 <h2>Legend</h2>
315
316 <dl>
317 <dt>cost
318         <dd>minerals+gas required to create one unit
319 <dt>build
320         <dd>relative time needed to create at least one unit
321 <dt>size
322         <dd><span class="unit unit-s">S</span>mall,
323                 <span class="unit unit-m">M</span>edium,
324                 or <span class="unit unit-l">L</span>arge unit damage
325         <dd>number of command points taken per unit
326         <dd><span class="unit unit-o">organic</span>/<span class="unit unit-u">mechanic</span> unit
327 <dt>HP<dd>
328         total number of hitpoints (including shields)
329 <dt>shield
330         <dd>percentage of HP in shields
331         <dd>shields always take full damage, irrelevant of unit size
332         <dd>does not take armor bonuses, but upgrades can decrease damage to any shield hit by upto 3
333 <dt>armor
334         <dd>base unit armor
335         <dd>can be increased by upto 3 at various facilities
336         <dd>each point decreases damage per hit by one, upto a minimum of ½
337         <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>
338 <dt>ground/air
339         <dd>damage done per single attack against ground/air units
340         <dd>2nd column indicates relative amount of damage done in
341                 <span title="the time in which a dragoon fires a shot">a certain
342                 amount</span> of time
343         <dd>splash damage<span class="unit-splash">+</span> hits nearby objects as well
344         <dd><span class="hurt unit-l">explosive</span> damage does only
345                 50% damage to small units, 75% to medium, 100% to large
346         <dd><span class="hurt unit-s">concussive/plasma</span> damage does
347                 25% to large, 50% medium, 100% to small units
348 <dt>sight
349         <dd>range in which the unit detects other units
350         <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
351 <dt>range
352         <dd>maximum range of weapon (note siege tank also has a minimum range)
353 <dt>speed
354         <dd>relative speed of movement (when in full motion, startup speed ignored)
355 <dt>specials
356         <dd>special abilities
357         <dd>parentheses () indicate that it needs to be researched first
358         <dd>hover for description
359         <dd>range is maximum range required to activate
360         <dd>cost is percentage of total energy lost
361 </dl>
362
363 <p>
364 When two values are given (1-2), second value indicates attribute after all
365 possible upgrades.
366 </p>
367
368 </div>
369