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