sc: unexceptional header tags for empty category cells
[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         raw => '<link rel="stylesheet" type="text/css" media="all" href="/sc.css?1.1" title="light">',
22         data => [$datafile],
23 });
24
25 :>
26 <h1>StarCraft units</h1>
27
28 <p>
29 Unit properties as seen or measured in Brood War
30 <span title="no known changes as of v1.16.1">version≥1.08</span>.
31 </p>
32
33 <:
34 sub coltoggle {
35         my ($name, $id) = @_;
36         return sprintf(
37                 (defined $get{order} ? $get{order} eq $id : !$id) ? '%2$s ▼'
38                         : '<a href="?%s">%s</a>',
39                 $id && "order=$id", $name
40         );
41 }
42 :><table class="units">
43 <thead><tr>
44         <th></th>
45         <th><:= coltoggle('name', '') :></th>
46         <th class="val min"><img src="/minerals.png" alt="min"></th>
47         <th class="val gas"><img src="/gas.png" alt="gas"></th>
48         <th class="val time"><:= coltoggle(qw'build cost') :></th>
49         <th class="unit" colspan="2"><:= coltoggle(qw'size size') :></th>
50         <th class="val unit-hp">HP</th>
51         <th class="val unit-shield">shield</th>
52         <th class="val unit-armor">armor</th>
53         <th class="val hurt" colspan="2">ground</th>
54         <th class="val hurt" colspan="2">air</th>
55         <th class="val unit-range">range</th>
56         <th class="val unit-sight">sight</th>
57         <th class="val unit-speed">speed</th>
58         <th class="unit-magic">specials</th>
59 </tr></thead>
60 <:
61 sub showrange {
62         my ($min, $max) = @_;
63         $_ = int($_ + .5) for $min, $max;  # round halves up
64         return $min == $max ? $min : "$min-$max";
65 }
66
67 sub showval {
68         my ($row, @elements) = @_;
69         my ($min, $max);
70
71         my $value = $row;
72         $value = ref $value eq 'HASH' && $value->{$_} or last for @elements;
73         if (ref $value eq 'ARRAY') {
74                 $min = $value->[0];
75                 $max = $value->[-1];
76         }
77         else {
78                 $min = $max = $value;
79         }
80         defined $min or return '';
81
82         if ($row->{upgrade}) {
83                 for (@{ $row->{upgrade} }) {
84                         my $increase = $_ or next;
85                         $increase = ref $increase eq 'HASH' && $increase->{$_} or last for @elements;
86                         $increase = $increase->[-1] if ref $increase eq 'ARRAY';
87                         $max += $increase if $increase;
88                 }
89         }
90
91         if ($elements[0] eq 'attack' and $elements[1] ne 'range' and $elements[2] eq 'dps') {{
92                 my $attack = $row->{ $elements[0] }->{ $elements[1] };
93                 ref $attack or $attack = $row->{ $elements[0] }->{$attack}; # follow
94                 my $type = $attack->{type} or next;
95                 if ($type eq 'explosive') {
96                         $min /= 2;
97                 }
98                 elsif ($type eq 'implosive') {
99                         $min /= 4;
100                 }
101         }}
102         return showrange($min, $max);
103 }
104
105         sub showattack {
106                 my ($row, $area) = @_;
107                 my $attack = $row->{attack}->{$area};
108                 if (not ref $attack) {
109                         # reference to another area
110                         $area = $attack;
111                         $attack = $row->{attack}->{$area};
112                 }
113
114                 return '<td colspan="2" class="hurt">' unless $attack;
115
116                 my $tagbase = '<td class="val hurt';
117                 if (ref $attack and $attack->{type}) {
118                         if ($attack->{type} eq 'explosive') {
119                                 $tagbase .= ' unit-l';
120                         }
121                         elsif ($attack->{type} eq 'implosive') {
122                                 $tagbase .= ' unit-s';
123                         }
124                 }
125                 $tagbase .= '">';
126
127                 my $out = showval($row, 'attack', $area, 'damage');
128                 $out .= '<span class="unit-splash">+</span>' if $attack->{splash};
129                 $attack->{dps} = $attack->{cooldown} && [
130                         map { 24 * $_ / $attack->{cooldown} * ($attack->{count} // 1) }
131                         map { ref $_ ? @{$_} : $_ }
132                         $attack->{damage}
133                         #TODO: upgrade (zergling)
134                 ];
135                 $out .= '<td class="val hurt hurtrel">' . showval($row, 'attack', $area, 'dps');
136                 return $tagbase . $out;
137         }
138
139         sub showmagic {
140                 my ($row) = @_;
141                 my $specials = $row->{special} or return '';
142                 return join ' ', map {
143                         sprintf '<span%s title="%s">%s</span>',
144                                 $_->{duration} < 0 && ' class="magic-perma"',
145                                 join('',
146                                         $_->{name},
147                                         $_->{desc} ? ": $_->{desc}" : '',
148                                         $_->{range} || $_->{cost} ? sprintf(' (%s)', join ', ',
149                                                 $_->{range} ? "range $_->{range}" : (),
150                                                 $_->{cost} ? sprintf('cost %.0f%%',
151                                                         100 * $_->{cost} / $row->{energy}
152                                                 ) : (),
153                                         ) : '',
154                                 ),
155                                 sprintf($_->{build} ? '(%s)' : '%s', $_->{abbr}),
156                 } grep { defined $_->{abbr} } @{$specials};
157         }
158
159         sub showunitcols {
160                 my ($row) = @_;
161                 local $_ = $row;
162                 $_->{hp} += $_->{shield} if $_->{shield};
163                 my $suitchar = '';
164                 if ($_->{suit}) {
165                         $suitchar = [qw/? s m l/]->[$_->{suit}];
166                 }
167
168                 return (
169                         '<td class="val min">' . ($_->{min} // ''),
170                         '<td class="val gas">' . ($_->{gas} || ''),
171                         !defined $_->{build} ? '<td>' : sprintf('<td class="val time">%s%.0f',
172                                 !!$_->{base} && '<span class="unit-composed">+</span>',
173                                 $_->{build} || '0',
174                         ),
175                         !$suitchar ? '<td>' : sprintf('<td class="unit unit-%s">%s', $suitchar, ucfirst $suitchar),
176                         '<td class="val unit">' . join('',
177                                 defined $_->{unit} && $_->{unit} == .5 ? '½' : $_->{unit},
178                                 defined $_->{organic} && sprintf(
179                                         '<span class="unit-%s" title="%s">%s</span>',
180                                         $_->{organic} ? 'o' : 'u',
181                                         $_->{organic} ? 'organic' : 'mechanic',
182                                         $_->{organic} ? 'o' : 'm',
183                                 ),
184                         ),
185                         '<td class="val unit-hp">' . $_->{hp} // '',
186                         '<td class="val unit-shield">' . (
187                                 $_->{shield} ? sprintf('%.0f%%', 100 * $_->{shield} / $_->{hp}) : '&nbsp;'
188                         ),
189                         '<td class="val unit-armor">' . showval($_, 'armor'),
190                         showattack($_, 'ground'),
191                         showattack($_, 'air'),
192                         '<td class="val unit-range">' . showval($_, 'attack', 'range'),
193                         '<td class="val unit-sight">' . sprintf(
194                                 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
195                                 showval($_, 'sight')
196                         ),
197                         '<td class="val unit-speed">' . showval($_, 'speed'),
198                         '<td class="unit-magic">' . showmagic($_),
199                         "\n"
200                 );
201         }
202
203         my $units = do $datafile;
204         die "Cannot open unit data: $_\n" for $@ || $! || ();
205         my $grouped = 1;  # race headers
206         if (exists $get{order}) {
207                 $grouped = 0;
208                 $get{order} ||= '';
209                 if ($get{order} eq 'size') {
210                         $_->{order} = $_->{unit}*8 + $_->{suit} + $_->{hp}/512 + $_->{min}/8192 for @$units;
211                 }
212                 elsif ($get{order} eq 'cost') {
213                         $_->{order} = $_->{gas}*1.5 + $_->{min} + $_->{unit}/8 + $_->{build}/256/8 for @$units;
214                 }
215                 else {
216                         $units->[$_]->{order} = $_ for 0 .. $#$units;
217                 }
218         }
219         my @rows = @{$units};
220         @rows = sort {$a->{order} <=> $b->{order}} @rows unless $grouped;
221
222         my ($race, $cat) = ('', '');
223         for (@rows) {
224                 if ($grouped) {
225                         printf '<tbody id="%s"><tr class="race"><th colspan="18"><h2>%s</h2>'."\n",
226                                 $race = $_->{race}, ucfirst $race
227                                         unless $race eq $_->{race};
228                 }
229                 else {
230                         $_->{cat} = $_->{race};
231                 }
232
233                 print(
234                         '<tr>',
235                         '<th class="cat">', $cat ne $_->{cat} && ($cat = $_->{cat}),
236                         '<td>', $_->{name},
237                         showunitcols($_),
238                 );
239
240                 for my $subrow (@{ $_->{special} }) {
241                         $subrow->{alt} or next;
242                         print(
243                                 '<tr class="alt"><td class="cat"><td>', $subrow->{alt},
244                                 showunitcols($subrow),
245                         );
246                 }
247         }
248 :>
249 </table>
250
251 <div class="legend">
252 <h2>Legend</h2>
253
254 <dl>
255 <dt>cost
256         <dd>minerals+gas required to create one unit
257         <dd>includes total expenses if based on existing units
258 <dt>build
259         <dd>relative time needed to create at least one unit
260         <dd>excludes construction of dependencies such as buildings
261                 and <span class="unit-composed">+</span>parent units
262 <dt>size
263         <dd>affected by <span class="unit unit-s">S</span>mall,
264                 <span class="unit unit-m">M</span>edium,
265                 or <span class="unit unit-l">L</span>arge unit damage
266         <dd>number of command points taken per unit
267         <dd><span class="unit unit-o">o</span>rganic/<span class="unit unit-u">m</span>echanic unit
268 <dt>HP<dd>
269         total number of hitpoints (including shields)
270 <dt>shield
271         <dd>percentage of HP in shields
272         <dd>shields always take full damage, irrelevant of unit size
273         <dd>does not take armor bonuses, but upgrades can decrease damage to any shield hit by upto 3
274 <dt>armor
275         <dd>base unit armor
276         <dd>can be increased by upto 3 at various facilities
277         <dd>each point decreases damage per hit by one, upto a minimum of ½
278         <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>
279 <dt>ground/air
280         <dd>damage done per single attack against ground/air units
281         <dd>2nd column indicates relative amount of damage done in
282                 1 second of fastest game time
283         <dd>splash damage<span class="unit-splash">+</span> hits nearby objects as well
284         <dd><span class="hurt unit-l">explosive</span> damage does only
285                 50% damage to small units, 75% to medium, 100% to large
286         <dd><span class="hurt unit-s">concussive/plasma</span> damage does
287                 25% to large, 50% medium, 100% to small units
288 <dt>sight
289         <dd>range in which the unit detects other units
290         <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
291 <dt>range
292         <dd>maximum range of weapon (note siege tank also has a minimum range)
293 <dt>speed
294         <dd>relative speed of movement (when in full motion, startup speed ignored)
295 <dt>specials
296         <dd>special abilities are usually casted manually, but some are <span class="magic-perma">always active</span>
297         <dd>parentheses () indicate that it needs to be researched first
298         <dd>hover for description
299         <dd>range is maximum range required to activate
300         <dd>cost is percentage of total energy lost
301 </dl>
302
303 <p>
304 When two values are given (1-2), second value indicates attribute after all
305 possible upgrades.
306 </p>
307
308 </div>
309