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