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