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