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