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