2 use List::Util qw(max);
12 if ($ENV{PATH_INFO} and $ENV{PATH_INFO} eq '/2') {
15 name => 'Heart of the Swarm',
16 title => 'starcraft2',
17 game => 'StarCraft II',
21 my $datafile = "sc-units-$scver{id}.inc.pl";
24 title => "$scver{title} unit cheat sheet",
27 "Reference of $scver{game} unit properties,"
28 . " comparing various statistics of all the units in $scver{name}"
29 . ' including costs, damage, defense, speed, ranges, and abilities.',
33 starcraft game unit statistics stats comparison table sheet cheat
34 reference software attributes properties
36 $scver{major} < 2 ? qw' bw broodwar brood war ' : qw' starcraft2 hots ',
38 stylesheet => [qw'light'],
39 raw => '<link rel="stylesheet" type="text/css" media="all" href="/sc.css?1.1" title="light">',
43 print "<h1>$scver{game} units</h1>\n\n";
45 my $units = do $datafile;
46 die "Cannot open unit data: $_\n" for $@ || $! || ();
47 my $patch = shift @{$units}
48 or die "Cannot open unit data: metadata not found\n";
50 print "<p>Unit properties as seen or measured in $scver{name}\n$patch.\n</p>\n\n";
53 my ($ref, $increase) = @_;
54 if (ref $increase eq 'HASH') {
55 addupgrade(\${$ref}->{$_}, $increase->{$_}) for keys %{$increase};
57 elsif (ref $increase eq 'ARRAY') {
58 addupgrade(\${$ref}->[$_], $increase->[$_]) for 0 .. $#{$increase};
60 ${$ref} += $increase if $increase =~ /^-?[0-9.]+/;
63 for my $unit (@{$units}) {
64 for my $upgrade (@{ $unit->{upgrade} }) {
65 while (my ($col, $increase) = each %{$upgrade}) {
66 defined $unit->{$col} or next;
67 addupgrade(\( $unit->{upgraded}->{$col} //= $unit->{$col} ), $increase);
75 (defined $get{order} ? $get{order} eq $id : !$id) ? '%2$s ▼'
76 : '<a href="?%s">%s</a>',
77 $id && "order=$id", $name
80 :><table class="units">
83 <th><:= coltoggle('name', '') :></th>
84 <th class="val min"><img src="/minerals.png" alt="min"></th>
85 <th class="val gas"><img src="/gas.png" alt="gas"></th>
86 <th class="val time"><:= coltoggle(qw'build cost') :></th>
87 <th class="unit" colspan="4"><:= coltoggle(qw'size size') :></th>
88 <th class="val unit-hp">HP</th>
89 <th class="val unit-shield">shield</th>
90 <th class="val unit-armor" title="armor">⛨</th>
91 <th class="val hurt" colspan=3>attack</th>
92 <th class="hurt hurtrel">dps</th>
93 <th class="val unit-range">range</th>
94 <th class="val unit-sight">sight</th>
95 <th class="val unit-speed">speed</th>
96 <th class="unit-magic">specials</th>
100 my ($min, $max) = @_;
101 return '' if not defined $min;
102 $_ &&= int($_ + .5) for $min, $max; # round halves up
103 return $min if not defined $max or $min == $max;
108 my ($row, $area) = @_;
109 my $attack = $row->{attack}->[$area]
110 or return '<td colspan=4 class="hurt">';
113 $out .= '<td class="unit hurt-g">' . '▽' x !!($attack->{anti} & 1);
114 $out .= '<td class="unit hurt-a">' . '△' x !!($attack->{anti} & 2);
115 $out .= '<td class="val hurt">';
117 my $upattack = $row->{upgraded}->{attack}->[$area];
118 my $damage = $attack->{damage};
119 my $maxdamage = $upattack->{damage} // $damage;
120 $damage = $damage->[0] if ref $damage;
121 $maxdamage = $maxdamage->[-1] if ref $maxdamage;
123 $out .= "<small>$attack->{count}× </small>" if $attack->{count} > 1;
124 $out .= '<span class="unit-l" title="explosive">*</span>'
125 if $attack->{type} eq 'explosive';
126 $out .= '<span class="unit-s" title="implosive">~</span>'
127 if $attack->{type} eq 'implosive';
128 $out .= sprintf('<span class="%s" title="%s">≥</span>',
130 $_ =~ /^light/ ? 'unit-s' :
131 $_ eq 'armored' ? 'unit-l' :
132 $_ eq 'organic' ? 'unit-o' :
133 $_ =~ /^massive/ ? 'unit-h' :
134 $_ eq 'shields' ? 'unit-shield' :
136 } join '_', keys %{ $attack->{bonus} }),
140 ref $_ ? showrange($_->[0], $_->[-1]) : $_
141 } $attack->{bonus}->{$_}),
144 )} keys %{ $attack->{bonus} }),
145 ) if $attack->{bonus};
146 $out .= showrange($damage, $maxdamage);
147 $out .= sprintf('<span class="unit-splash" title="%s">%s</span>',
148 $attack->{splash} eq 'line' ? ('linear', '×') : ('splash', '+')
149 ) if $attack->{splash};
151 $out .= '<td class="val hurt hurtrel">';
152 if ($attack->{cooldown}) {
153 if (my $type = $attack->{type}) {
154 if ($type eq 'explosive') {
157 elsif ($type eq 'implosive') {
161 $damage *= ($attack->{count} // 1) / $attack->{cooldown};
162 if (my $bonus = $upattack->{bonus} // $attack->{bonus}) {
163 $maxdamage += $_ for max(
164 map { ref $_ ? $_->[-1] : $_ } values %{$bonus}
167 $maxdamage *= ($upattack->{count} // $attack->{count} // 1)
168 / ($upattack->{cooldown} // $attack->{cooldown});
169 $out .= showrange($damage, $maxdamage);
177 my $specials = $row->{special} or return '';
178 return join ' ', map {
179 sprintf '<span%s title="%s">%s</span>',
180 $_->{duration} < 0 && ' class="magic-perma"',
183 $_->{desc} ? ": $_->{desc}" : '',
184 $_->{range} || $_->{cost} ? sprintf(' (%s)', join ', ',
185 $_->{range} ? "range $_->{range}" : (),
186 $_->{cost} ? sprintf('cost %.0f%%%s',
187 100 * $_->{cost} / $row->{energy},
188 defined $_->{maint} && sprintf('+%.1f%%/s',
189 100 * $_->{maint} / $row->{energy},
194 sprintf($_->{build} ? '(%s)' : '%s', $_->{abbr}),
195 } grep { defined $_->{abbr} } @{$specials};
201 $_->{hp} += $_->{shield} if $_->{shield};
203 if ($_->{attr}->{structure}) {
207 $suitchar = [qw/? s m l/]->[$_->{suit}];
209 elsif ($_->{cargo} > 0) {
210 $suitchar = [qw/? s m l l h h h h/]->[abs $_->{cargo}];
213 $suitchar = [qw/s m l h h h/]->[$_->{size}];
215 elsif ($_->{attr} and $_->{attr}->{light}) {
218 elsif ($_->{attr} and $_->{attr}->{armored}) {
223 '<td class="val min">' . ($_->{min} // ''),
224 '<td class="val gas">' . ($_->{gas} || ''),
225 !defined $_->{build} ? '<td>' : sprintf('<td class="val time">%s%.0f',
226 !!$_->{base} && '<span class="unit-composed">+</span>',
229 !$suitchar ? '<td>' : sprintf('<td class="unit unit-%s">%s%s',
230 $suitchar, ucfirst $suitchar,
231 $_->{attr}->{massive}
232 && '<span class="unit-massive" title="massive">⚓</span>',
234 '<td class="val unit">' . (
235 defined $_->{unit} && $_->{unit} == .5 ? '½' : $_->{unit}
237 '<td class="unit unit-type">' . join('', grep { $_ }
238 (defined $_->{organic} ? !$_->{organic} : $_->{attr}->{mech})
239 && '<span class="unit-u" title="mechanic">m</span>',
240 ($_->{organic} || $_->{attr}->{organic})
241 && '<span class="unit-o" title="organic">o</span>',
242 $_->{attr}->{psionic}
243 && '<span class="unit-p" title="psionic">ψ</span>',
245 '<td class="unit unit-attr">' . join('', grep { $_ }
246 $_->{attr}->{armored}
247 && '<span class="unit unit-l" title="armored">A</span>',
249 && '<span class="unit unit-s" title="light">L</span>',
251 '<td class="val unit-hp">' . $_->{hp} // '',
252 $_->{shield} ? sprintf('<td class="val unit-shield">%.0f%%<td',
253 100 * $_->{shield} / $_->{hp}
255 ' class="val unit-armor">' .
256 showrange($_->{armor}, $_->{upgraded}->{armor}),
258 '<td class="val unit-range">' .
259 showrange(map { $_->{attack}->[0]->{range} } $_, $_->{upgraded}),
260 '<td class="val unit-sight">' . sprintf(
261 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
262 showrange($_->{sight}, $_->{upgraded}->{sight})
264 '<td class="val unit-speed">' .
265 showrange($_->{speed}, $_->{upgraded}->{speed}),
267 && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
269 && qq'<span class="unit unit-jump" title="flying">↑</span>',
270 '<td class="unit-magic">' . showmagic($_),
271 !$_->{attack}->[1] ? () : (
272 '<tr><td colspan=12>', showattack($_, 1), '<td colspan=4>'
278 my $grouped = 1; # race headers
279 if (exists $get{order}) {
282 if ($get{order} eq 'size') {
283 $_->{order} = $_->{unit}*8 + $_->{suit} + $_->{hp}/512 + $_->{min}/8192 for @$units;
285 elsif ($get{order} eq 'cost') {
286 $_->{order} = $_->{gas}*1.5 + $_->{min} + $_->{unit}/8 + $_->{build}/256/8 for @$units;
289 $units->[$_]->{order} = $_ for 0 .. $#$units;
292 my @rows = @{$units};
293 @rows = sort {$a->{order} <=> $b->{order}} @rows unless $grouped;
295 my ($race, $cat) = ('', '');
298 printf '<tbody id="%s"><tr class="race"><th colspan="20"><h2>%s</h2>'."\n",
299 $race = $_->{race}, ucfirst $race
300 unless $race eq $_->{race};
303 $_->{cat} = $_->{race};
308 '<th class="cat">', $cat ne $_->{cat} && ($cat = $_->{cat}),
313 for my $subrow (@{ $_->{special} }) {
314 $subrow->{alt} or next;
316 '<tr class="alt"><th class="cat"><td>', $subrow->{alt},
317 showunitcols($subrow),
329 <dd>minerals+gas required to create one unit
330 <dd>includes total expenses if based on existing units
332 <dd>relative time needed to create at least one unit
333 <dd>excludes construction of dependencies such as buildings
334 and <span class="unit-composed">+</span>parent units
337 if ($scver{major} > 1) {
338 :>transports can fit 8 <span class="unit unit-s">S</span>mall,
339 4 <span class="unit unit-m">M</span>edium,
340 2 <span class="unit unit-l">L</span>arge,
341 or a single <span class="unit unit-h">H</span>uge unit
342 <dd>massive <span class="unit-massive">⚓</span> units
343 cannot be lifted or slowed and can break force fields<:
345 :>affected by <span class="unit unit-s">S</span>mall,
346 <span class="unit unit-m">M</span>edium, or
347 <span class="unit unit-l">L</span>arge unit damage<:
349 <dd>number of command points taken per unit
351 if ($scver{major} > 1) {
352 :>received damage depends on
353 <span class="unit unit-o">o</span>rganic,
354 <span class="unit unit-u">m</span>echanic,
355 <span class="unit unit-p">ψ</span>(ps)ionic,
356 <span class="unit unit-s">L</span>ight, and
357 <span class="unit unit-l">A</span>rmored
360 :><span class="unit unit-o">o</span>rganic/<span class="unit unit-u">m</span>echanic unit<:
363 total number of hitpoints (including shields)
365 <dd>percentage of HP in shields
366 <dd>shields always take full damage, irrelevant of unit size
367 <dd>does not take armor bonuses, but upgrades can decrease damage to any shield hit by upto 3
370 <dd>can be increased by upto 3 at various facilities
371 <dd>each point decreases damage per hit by one, upto a minimum of ½
372 <dd>reduction applies to initial damage, before size penalties
373 <small>(so a plasma hit of 12 to 4 armor large deals 2 damage, not ½)</small>
375 <dd>targets <span class="hurt-g">▽</span> ground
376 and/or <span class="hurt-a">△</span> air
377 <dd>damage given per single hit
378 <dd><span class="hurtrel">dps</span> indicates relative amount of damage
379 done in 1 second of in-game time
380 <dd>splash damage hits all objects nearby <span class="unit-splash">+</span>
381 or in a straight line <span class="unit-splash">×</span>.
383 if ($scver{major} > 1) {
384 :>does not include <span>≥</span>bonus damage
385 dealt to susceptible unit types<:
387 :><span class="unit-l">*</span>explosive damage does only
388 50% damage to small units, 75% to medium, 100% to large
389 <dd><span class="unit-s">~</span>concussive/plasma damage does
390 25% to large, 50% medium, 100% to small units<:
393 <dd>range in which the unit detects other units
394 <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
396 <dd>maximum range of weapon (note siege tank also has a minimum range)
398 <dd>relative speed of movement (when in full motion, startup speed ignored)
400 <dd>special abilities are usually casted manually, but some are <span class="magic-perma">always active</span>
401 <dd>parentheses () indicate that it needs to be researched first
402 <dd>hover for description
403 <dd>range is maximum range required to activate
404 <dd>cost is percentage of total energy lost
408 When two values are given (1-2), second value indicates attribute after all