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