2 use List::Util qw(max sum);
8 game => 'StarCraft BW',
12 name => 'Heart of the Swarm',
13 title => 'starcraft2 hots',
14 game => 'StarCraft II HotS',
18 name => 'Legacy of the Void',
19 title => 'starcraft2 lotv',
20 game => 'StarCraft II LotV',
28 my $requestver = $scvers{$Request ||= 'index'}
29 or Html(), Abort("Requested version <q>$Request</q> not available", '404 request not found');
31 if (ref $requestver ne 'HASH') {
32 $header{Location} = $requestver;
33 Abort("Canonical URL for $Request is at $requestver", '302 subpage alias');
36 my %scver = %{$requestver};
37 my $datafile = "sc-units-$Request.inc.pl";
40 title => "$scver{title} unit cheat sheet",
43 "Reference of $scver{game} unit properties,"
44 . " comparing various statistics of all the units in $scver{name}"
45 . ' including costs, damage, defense, speed, ranges, and abilities.',
49 starcraft game unit statistics stats comparison table sheet cheat
50 reference software attributes properties patch attribute multiplayer
52 $scver{major} < 2 ? qw' bw broodwar brood war ' :
53 qw' starcraft2 lotv hots wol ',
55 stylesheet => [qw( light dark )],
56 raw => '<link rel="stylesheet" type="text/css" media="all" href="/sc.css?1.2">',
60 say "<h1>$scver{game} units</h1>\n";
62 my $units = do $datafile;
63 Abort("Cannot open unit data", 501, $_) for $@ || $! || ();
64 my $patch = shift @{$units}
65 or Abort("Cannot open unit data: metadata not found", 501);
67 say "<p>Unit properties as seen or measured in $scver{name}\n$patch.";
68 say "Also see the $_ tables." for join(' and ',
69 (showlink('StarCraft 2: LotV', '/sc/lotv')) x ($Request ne 'lotv'),
70 (showlink( 'HotS', '/sc/hots')) x ($Request ne 'hots'),
71 (showlink('original SC: Brood War', '/sc/bw')) x ($Request ne 'bw'),
76 my ($ref, $increase, $org) = @_;
77 if (ref $increase eq 'HASH') {
78 addupgrade(\${$ref}->{$_}, $increase->{$_}, $org->{$_}) for keys %{$increase};
80 elsif (ref $increase eq 'ARRAY') {
81 addupgrade(\${$ref}->[$_], $increase->[$_], $org->[$_]) for 0 .. $#{$increase};
84 ${$ref} += $increase if $increase =~ /^-?[0-9.]+/;
87 for my $unit (@{$units}) {
88 for my $upgrade (@{ $unit->{upgrade} }) {
89 while (my ($col, $increase) = each %{$upgrade}) {
90 defined $unit->{$col} or next;
91 addupgrade(\$unit->{upgraded}->{$col}, $increase, $unit->{$col});
94 for my $special (@{ $unit->{special} }) {
95 for my $upgrade (@{ $special->{upgrade} }) {
96 while (my ($col, $increase) = each %{$upgrade}) {
97 defined $special->{$col} or next;
98 addupgrade(\$special->{upgraded}->{$col}, $increase, $special->{$col});
105 my ($name, $id, $nolink) = @_;
106 return "$name ▼" if defined $get{order} ? $get{order} eq $id : !$id;
107 return $name if $nolink;
108 return showlink($name, '?'.($id && "order=$id"));
110 :><table class="units">
112 <th><:= coltoggle(exists $get{order} ? 'race' : 'source' => '') :></th>
113 <th class="unit-name"><:= coltoggle(name => 'name') :></th>
114 <th class="val unit-min" title=minerals><:= coltoggle(cost => 'cost') :></th>
115 <th class="val unit-gas">gas</th>
116 <th class="val time"><:= coltoggle(build => 'build') :></th>
117 <th class="unit" colspan="2"><:= coltoggle(qw'size size') :></th>
118 <th class="unit unit-attr" colspan="2">attr</th>
119 <th class="val unit-hp"><:= coltoggle(HP => 'hp') :></th>
120 <th class="val unit-shield">shield</th>
121 <th class="val unit-armor" title="armor">⛨</th>
122 <th class="val hurt"><:= coltoggle(attack => 'attack') :></th>
123 <th class="hurt hurtrel">dps</th>
124 <th class="val unit-range" colspan=3>range</th>
125 <th class="val unit-sight">sight</th>
126 <th class="val unit-speed"><:= coltoggle(speed => 'speed') :></th>
127 <th class="unit-magic">specials</th>
131 my ($min, $max) = @_;
132 return '' if not defined $min;
133 return $min || '-' if !$max or $min == $max;
138 $_ &&= int($_ + .5) for @_; # round halves up
139 return showrange(@_);
143 my ($row, $unit) = @_;
145 sprintf('cost %s%%', join '-',
146 map { $_ && sprintf '%.0f', 100 * $row->{cost} / $_ } grep { defined $_ }
148 $unit->{upgraded}->{energy},
150 $unit->{upgraded}->{capacity},
152 !defined $row->{maint} ? () : sprintf('+%s%%/s', join '-',
153 map { sprintf '%.1f', 100 * $row->{maint} / $_ } grep $_,
155 $unit->{upgraded}->{capacity},
161 my ($row, $area) = @_;
162 my $attack = $row->{attack}->[$area]
163 or return '<td colspan=5 class="hurt">';
165 my $upattack = $row->{upgraded}->{attack}->[$area];
166 my $damage = $attack->{damage};
167 my $maxdamage = $upattack->{damage} // $damage;
168 $maxdamage += ($upattack->{upgrade} // $attack->{upgrade}) * 3;
170 my $out = '<td class="val hurt">';
171 $out .= sprintf '<span title="%s">¤</span> ', showcost($attack, $row)
173 $out .= sprintf('<small>%s× </small>',
174 showrangeint($attack->{count}, $upattack->{count}),
175 ) if $attack->{count} > 1;
176 $out .= '<span class="unit-l" title="explosive">*</span>'
177 if $attack->{type} eq 'explosive';
178 $out .= '<span class="unit-s" title="implosive">~</span>'
179 if $attack->{type} eq 'implosive';
180 if (my @bonus = sort grep { !/^-/ } keys %{ $attack->{bonus} }) {
181 $out .= sprintf('<span class="%s" title="%s">≥</span>',
183 $_ eq 'light' ? 'unit-s' :
184 $_ eq 'armored' ? 'unit-l' :
185 $_ eq 'organic' ? 'unit-o' :
186 $_ eq 'massive' ? 'unit-h' :
187 $_ eq 'shields' ? 'unit-shield' :
193 $attack->{bonus}->{$_},
194 ($upattack->{bonus} // $attack->{bonus})->{$_}
195 + ($upattack->{bonus} // $attack->{bonus})->{"-$_"} * 3,
202 $out .= '<span class="unit-pdd" title="projectile">•</span>'
203 if $attack->{type} eq 'projectile';
205 $out .= sprintf '<span title="%s">', $attack->{name} if $attack->{name};
206 $out .= showrangeint($damage, $maxdamage);
207 $out .= '</span>' if $attack->{name};
208 $out .= sprintf('<span class="unit-splash" title="%s">%s</span>',
209 $attack->{splash} eq 'line' ? ('linear', '+') : ('splash', '⁜')
210 ) if $attack->{splash};
212 $out .= '<td class="val hurt hurtrel">';
213 if ($attack->{dps}) {
214 # precalculated dps, do not touch
215 $out .= showrangeint($attack->{dps}->[0],
216 $upattack->{dps}->[-1] // $attack->{dps}->[-1]
219 elsif ($attack->{cooldown}) {
220 if (my $type = $attack->{type}) {
221 if ($type eq 'explosive') {
224 elsif ($type eq 'implosive') {
228 $damage *= ($attack->{count} // 1) / $attack->{cooldown};
229 if (my $bonus = $upattack->{bonus} // $attack->{bonus}) {
230 $maxdamage += $_ for max(
231 map { $bonus->{$_} + $bonus->{"-$_"} * 3 }
232 grep { !/^-/ } keys %{$bonus}
235 $maxdamage *= ($upattack->{count} // $attack->{count} // 1)
236 / ($upattack->{cooldown} // $attack->{cooldown});
237 $out .= showrangeint($damage, $maxdamage);
240 $out .= '<td class="unit hurt-g">' . '▽' x !!($attack->{anti} & 1);
241 $out .= '<td class="unit hurt-a">' . '△' x !!($attack->{anti} & 2);
243 $out .= '<td class="val unit-range">' .
244 showrangeint($attack->{range}, $upattack->{range});
251 my $specials = $row->{special} or return '';
252 return join ' ', map {
253 sprintf '<span%s title="%s">%s</span>',
254 $_->{duration} < 0 && ' class="magic-perma"',
257 $_->{desc} ? ": $_->{desc}" : '',
258 (map { $_ && " ($_)" } join ', ',
259 #TODO: apply upgrades
260 $_->{range} ? "range $_->{range}" : (),
261 $_->{cost} ? showcost($_, $row) :
262 $_->{cooldown} ? "cooldown $_->{cooldown}s" : (),
265 sprintf($_->{build} ? '(%s)' : '%s', $_->{abbr}),
266 } grep { defined $_->{abbr} } @{$specials};
272 $_->{hp} += $_->{shield} if $_->{shield};
275 '<td class="val unit-min">' . ($_->{min} // ''),
276 '<td class="val unit-gas">' . ($_->{gas} || ''),
277 defined $_->{transform} ? sprintf('<td class="val time">%.0f',
280 !defined $_->{build} ? '<td>' : sprintf('<td class="val time"%s>%s%.0f',
281 defined $_->{warp} && qq(title="$_->{build} without warpgate"),
282 !!$_->{base} && sprintf(
283 '<span class="unit-composed" title="%s">+</span>',
284 'from '.join('+', @{ $_->{base} }),
286 $_->{warp} // $_->{build} || '0',
288 sprintf('<td class="unit unit-%s" title="%4$s%3$s">%s',
289 $_-> {cargo} < 0 ? ('supply', T => 'transport') :
290 $_->{upgraded}->{cargo} < 0 ? ('supply magic-opt', T => 'optional transport') :
291 $_-> {attr}->{flying} ? ('air', F => 'flying') :
292 $_->{upgraded}->{attr}->{flying} ? ('air magic-opt', F => 'potentially flying') :
293 $_->{attr}->{structure} ? ('x', B => 'building') :
295 [qw( x s m l l h h h h )]->[ $_->{cargo} ],
297 $_->{cargo} ? 'transportable' : 'untransportable',
299 defined $_->{size} && sprintf('⌀%.1f ', $_->{size}),
301 sprintf('<td class="val unit unit-pop%s">%s',
302 defined $_->{pop} && $_->{pop} < 0 && ' unit-supply',
303 defined $_->{pop} && $_->{pop} == .5 ? '½' : $_->{pop},
305 '<td class="unit unit-type">' . join('', grep { $_ }
306 (defined $_->{organic} ? !$_->{organic} : $_->{attr}->{mech})
307 && '<span class="unit-u" title="mechanic">m</span>',
308 ($_->{organic} || $_->{attr}->{organic})
309 && '<span class="unit-o" title="organic">o</span>',
310 $_->{attr}->{psionic}
311 && '<span class="unit-p" title="psionic">ψ</span>',
313 '<td class="unit unit-attr">' . join('', grep { $_ }
314 $_->{attr}->{armored}
315 && '<span class="unit unit-l" title="armored">A</span>',
317 && '<span class="unit unit-s" title="light">L</span>',
318 $_->{suit} && sprintf(
319 '<span class="unit unit-%s" title="%3$s">%s</span>',
327 $_->{attr}->{massive}
328 && '<span class="unit-massive" title="massive">⚓</span>',
330 $_->{hp} < 0 ? '<td class="val unit-hp" title="invulnerable">∞' :
331 '<td class="val unit-hp">' . showrangeint($_->{hp}, $_->{upgraded}->{hp}),
332 $_->{shield} ? sprintf('<td class="val unit-shield">%.0f%%<td',
333 100 * $_->{shield} / $_->{hp}
335 ' class="val unit-armor">' .
336 showrangeint($_->{armor}, $_->{upgraded}->{armor}),
338 '<td class="val unit-sight">' . sprintf(
339 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
340 showrangeint($_->{sight}, $_->{upgraded}->{sight})
342 sprintf('<td class="val unit-speed"%2$s>%s',
344 map { $_ && sprintf '%.1f', $_ }
345 $_->{speed}, $_->{upgraded}->{speed}
347 defined $_->{creep} && sprintf(' title="%s on creep"',
348 $_->{creep} == 1 ? 'same' : showrange(
349 map { $_ && sprintf '%.1f', $_ }
350 $_->{speed} * $_->{creep},
351 $_->{upgraded}->{speed} && $_->{upgraded}->{speed} *
352 ($_->{upgraded}->{creep} // $_->{creep}),
357 && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
358 '<td class="unit-magic">' . showmagic($_),
359 !$_->{attack}->[1] ? () : (
360 '<tr><th class="cat" colspan="2"><td colspan=10>', showattack($_, 1), '<td colspan=3>'
362 !$_->{attack}->[2] ? () : (
363 '<tr><th class="cat" colspan="2"><td colspan=10>', showattack($_, 2), '<td colspan=3>'
369 my @rows = @{$units};
370 my $grouped = 1; # race headers
371 if (exists $get{order}) {
374 if ($get{order} eq 'name') {
375 @rows = sort {$a->{name} cmp $b->{name}} @rows;
377 elsif ($get{order} eq 'cost') {
379 $_->{gas}*1.5 + $_->{min} + $_->{pop}/8 + $_->{build}/256/8
382 elsif ($get{order} eq 'build') {
383 my %unittime = map { ($_->{name} => $_->{warp} // $_->{build}) } @rows;
384 $unittime{Templar} = $unittime{'High Templar'};
386 ($_->{warp} // $_->{build})
387 + ($_->{gas}*1.5 + $_->{min} + $_->{pop}/8)/1024
388 + ($_->{base} ? ($unittime{$_->{base}->[0]} // 100) + 1 : 0)
391 elsif ($get{order} eq 'size') {
393 $_->{pop}*16 + ($_->{size} // $_->{suit}) + $_->{cargo}/8
394 + $_->{hp}/512 + $_->{min}/8192
397 elsif ($get{order} eq 'hp') {
399 $_->{hp}*1.01 + $_->{armor} + $_->{shield} + $_->{size}/1024,
402 elsif ($get{order} eq 'attack') {
403 $_->{order} = $_->{hp} / 1024 + $_->{shield} / 1008 + max(
405 ($_->{dps} ? $_->{dps}->[-1] :
406 ($_->{damage} + $_->{upgrade} * 3)
407 * ($_->{count} // 1) / ($_->{cooldown} // 1)
409 * ($_->{splash} ? 1.01 : 1)
410 * ($_->{type} eq 'implosive' ? .96 : 1)
411 * ($_->{type} eq 'explosive' ? .98 : 1)
415 elsif ($get{order} eq 'speed') {
417 ($_->{upgraded}->{speed} // $_->{speed}*1.01)
418 + $_->{sight}/1024 + $_->{detect}/2048
421 @rows = sort {$a->{order} <=> $b->{order}} @rows if exists $rows[0]->{order};
424 my ($race, $cat) = ('', '');
427 say sprintf '<tbody id="%s"><tr class="race"><th colspan="20"><h2>%s</h2>',
428 $race = $_->{race}, ucfirst $race
429 unless $race eq $_->{race};
432 $_->{cat} = $_->{race};
437 '<th class="cat">', $cat ne $_->{cat} && ($cat = $_->{cat}),
442 for my $subrow (@{ $_->{special} }) {
443 $subrow->{alt} or next;
445 '<tr class="alt"><th class="cat"><td>', $subrow->{alt},
446 showunitcols($subrow),
458 <dd><span class="unit-min">minerals</span> and
459 <span class="unit-gas">gas</span> required to create one unit
460 <dd>includes total expenses if based on existing units
462 <dd>relative time needed to create at least one unit
463 <dd>excludes construction of dependencies such as buildings
464 and <span class="unit-composed">+</span>parent units
466 <dd><span class="unit unit-supply">T</span>ransports can fit upto
467 8 non-<span class="unit unit-air">F</span>lying cargo units
468 <dd>number of command points taken while alive
470 if ($scver{major} > 1) {
471 :>received damage depends on
472 <span class="unit unit-o">o</span>rganic,
473 <span class="unit unit-u">m</span>echanic,
474 <span class="unit unit-p">ψ</span>(ps)ionic,
475 <span class="unit unit-s">L</span>ight, and
476 <span class="unit unit-l">A</span>rmored
478 <dd>massive <span class="unit-massive">⚓</span> units
479 cannot be lifted or slowed and can break force fields<:
481 :>abilities may hit only <span class="unit unit-o">o</span>rganic
482 or <span class="unit unit-u">m</span>echanic targets
483 <dd>affected by <span class="unit unit-s">S</span>mall,
484 <span class="unit unit-m">M</span>edium, or
485 <span class="unit unit-l">L</span>arge damage<:
488 <dd>total number of hitpoints (including shields)
489 <dd>everything zerg (except for eggs) regenerates one point every
490 <:= $scver{major} == 1 ? '4½' : '3.7' :> seconds
492 <dd>percentage of HP in shields
494 if ($scver{major} > 1) {
495 :>shields always take full damage, irrelevant of unit size
498 :>does not take armor bonuses,
499 but upgrades can decrease damage to any shield hit by upto 3
501 if ($scver{major} > 1) {
502 :>after 10 seconds out of combat, 2 points are recharged per game second<:
504 :>recharges one point every 2½ seconds<:
508 <dd>can be increased by upto 3 at various facilities
509 <dd>each point decreases damage per hit by one, upto a minimum of ½
510 <dd>reduction applies to initial damage, before size penalties
511 <small>(so a plasma hit of 12 to 4 armor large deals 2 damage, not ½)</small>
513 <dd>damage per single hit
514 <dd>some weapons fire multiple × times, multiplying armor penalties
515 <dd>splash damage hits all objects nearby <span class="unit-splash">⁜</span>
516 or in a straight line <span class="unit-splash">+</span>.
518 if ($scver{major} > 1) {
519 :>does not include <span>≥</span>bonus damage
520 dealt to susceptible unit types
521 <dd><span class="unit-pdd">•</span>projectile shots are negated by
522 Point Defense Drones<:
524 :><span class="unit-l">*</span>explosive damage does only
525 50% damage to <span class="unit unit-s">S</span>mall units,
526 75% to <span class="unit unit-m">M</span>edium,
527 100% to <span class="unit unit-l">L</span>arge
528 <dd><span class="unit-s">~</span>concussive/plasma damage does
529 25% to <span class="unit unit-l">L</span>arge,
530 50% <span class="unit unit-m">M</span>edium,
531 100% to <span class="unit unit-s">S</span>mall units<:
533 <dd><span class="hurtrel">dps</span> indicates relative total amount of damage
534 done in 1 second of <:= $scver{major} > 1 ? '<em>Normal</em> in-game time' :
535 'time on <em>Fast</em> game speed' :>
536 <dd>targets <span class="hurt-g">▽</span> ground
537 and/or <span class="hurt-a">△</span> air
539 <dd>maximum hex distance a weapon can fire (note Sieged Tank also has a minimum)
541 <dd>range in which the unit detects other units
542 <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
544 <dd>top movement speed in hex per second
545 <dd>acceleration and deceleration ignored
547 <dd>parentheses () indicate that it needs to be researched first
548 <dd><span class="magic-perma">passive</span> abilities are always enabled
549 <dd>hover for description
550 <dd>range is maximum distance allowed to activate
551 <dd>cost describes energy loss percentage on spawn and when fully charged
555 When two values are given (1-2), the second value indicates the attribute
556 after all possible upgrades.