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} = "/sc/$requestver";
33 Abort("Canonical URL for $Request is at $requestver", '302 subpage alias');
36 my %scver = %{$requestver};
37 my $datafile = "sc-units-$Request";
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 raw => '<link rel="stylesheet" type="text/css" media="all" href="/sc.css?1.3">',
56 data => ["$datafile.inc.pl"],
59 say "<h1>$scver{game} units</h1>\n";
61 my $units = Data($datafile);
62 my $patch = shift @{$units}
63 or Abort("Cannot open unit data: metadata not found", 501);
65 say "<p>Unit properties as seen or measured in $scver{name}\n$patch.";
66 say "Also see the $_ tables." for join(' and ',
67 (showlink('StarCraft 2: LotV', '/sc/lotv')) x ($Request ne 'lotv'),
68 (showlink( 'HotS', '/sc/hots')) x ($Request ne 'hots'),
69 (showlink('original SC: Brood War', '/sc/bw')) x ($Request ne 'bw'),
74 my ($ref, $increase, $org) = @_;
75 if (ref $increase eq 'HASH') {
76 addupgrade(\${$ref}->{$_}, $increase->{$_}, $org->{$_}) for keys %{$increase};
78 elsif (ref $increase eq 'ARRAY') {
79 addupgrade(\${$ref}->[$_], $increase->[$_], $org->[$_]) for 0 .. $#{$increase};
82 ${$ref} += $increase if $increase =~ /^-?[0-9.]+/;
85 for my $unit (@{$units}) {
86 for my $upgrade (@{ $unit->{upgrade} }) {
87 while (my ($col, $increase) = each %{$upgrade}) {
88 defined $unit->{$col} or next;
89 addupgrade(\$unit->{upgraded}->{$col}, $increase, $unit->{$col});
92 for my $special (@{ $unit->{special} }) {
93 for my $upgrade (@{ $special->{upgrade} }) {
94 while (my ($col, $increase) = each %{$upgrade}) {
95 defined $special->{$col} or next;
96 addupgrade(\$special->{upgraded}->{$col}, $increase, $special->{$col});
103 my ($name, $id, $nolink) = @_;
104 return "$name ▼" if defined $get{order} ? $get{order} eq $id : !$id;
105 return $name if $nolink;
106 return showlink($name, '?'.($id && "order=$id"));
108 :><table class="units">
110 <th><:= coltoggle(exists $get{order} ? 'race' : 'source' => '') :></th>
111 <th class="unit-name"><:= coltoggle(name => 'name') :></th>
112 <th class="val unit-min" title=minerals><:= coltoggle(cost => 'cost') :></th>
113 <th class="val unit-gas">gas</th>
114 <th class="val time"><:= coltoggle(build => 'build') :></th>
115 <th class="unit" colspan="2"><:= coltoggle(qw'size size') :></th>
116 <th class="unit unit-attr" colspan="2">attr</th>
117 <th class="val unit-hp"><:= coltoggle(HP => 'hp') :></th>
118 <th class="val unit-shield">shield</th>
119 <th class="val unit-armor" title="armor">⛨</th>
120 <th class="val hurt"><:= coltoggle(attack => 'attack') :></th>
121 <th class="hurt hurtrel">dps</th>
122 <th class="val unit-range" colspan=3>range</th>
123 <th class="val unit-sight">sight</th>
124 <th class="val unit-speed"><:= coltoggle(speed => 'speed') :></th>
125 <th class="unit-magic">specials</th>
129 my ($min, $max) = @_;
130 return '' if not defined $min;
131 return $min || '-' if !$max or $min == $max;
136 $_ &&= int($_ + .5) for @_; # round halves up
137 return showrange(@_);
141 my ($row, $unit) = @_;
143 sprintf('cost %s%%', join '-',
144 map { $_ && sprintf '%.0f', 100 * $row->{cost} / $_ } grep { defined $_ }
146 $unit->{upgraded}->{energy},
148 $unit->{upgraded}->{capacity},
150 !defined $row->{maint} ? () : sprintf('+%s%%/s', join '-',
151 map { sprintf '%.1f', 100 * $row->{maint} / $_ } grep $_,
153 $unit->{upgraded}->{capacity},
159 my ($row, $area) = @_;
160 my $attack = $row->{attack}->[$area]
161 or return '<td colspan=5 class="hurt">';
163 my $upattack = $row->{upgraded}->{attack}->[$area];
164 my $damage = $attack->{damage};
165 my $maxdamage = $upattack->{damage} // $damage;
166 $maxdamage += ($upattack->{upgrade} // $attack->{upgrade}) * 3;
168 my $out = '<td class="val hurt">';
169 $out .= sprintf '<span title="%s">¤</span> ', showcost($attack, $row)
171 $out .= sprintf('<small>%s× </small>',
172 showrangeint($attack->{count}, $upattack->{count}),
173 ) if $attack->{count} > 1;
174 $out .= '<span class="unit-l" title="explosive">*</span>'
175 if $attack->{type} eq 'explosive';
176 $out .= '<span class="unit-s" title="implosive">~</span>'
177 if $attack->{type} eq 'implosive';
178 if (my @bonus = sort grep { !/^-/ } keys %{ $attack->{bonus} }) {
179 $out .= sprintf('<span class="%s" title="%s">≥</span>',
181 $_ eq 'light' ? 'unit-s' :
182 $_ eq 'armored' ? 'unit-l' :
183 $_ eq 'organic' ? 'unit-o' :
184 $_ eq 'massive' ? 'unit-h' :
185 $_ eq 'shields' ? 'unit-shield' :
186 $_ eq 'structure' ? 'unit-x' :
192 $attack->{bonus}->{$_},
193 ($upattack->{bonus} // $attack->{bonus})->{$_}
194 + ($upattack->{bonus} // $attack->{bonus})->{"-$_"} * 3,
201 $out .= '<span class="unit-pdd" title="projectile">•</span>'
202 if $attack->{type} eq 'projectile';
204 $out .= sprintf '<span title="%s">', $attack->{name} if $attack->{name};
205 $out .= showrangeint($damage, $maxdamage);
206 $out .= '</span>' if $attack->{name};
207 $out .= sprintf('<span class="unit-splash" title="%s">%s</span>',
208 $attack->{splash} eq 'line' ? ('linear', '+') : ('splash', '⁜')
209 ) if $attack->{splash};
211 $out .= '<td class="val hurt hurtrel">';
212 if ($attack->{dps}) {
213 # precalculated dps, do not touch
214 $out .= showrangeint($attack->{dps}->[0],
215 $upattack->{dps}->[-1] // $attack->{dps}->[-1]
218 elsif ($attack->{cooldown}) {
219 if (my $type = $attack->{type}) {
220 if ($type eq 'explosive') {
223 elsif ($type eq 'implosive') {
227 $damage *= ($attack->{count} // 1) / $attack->{cooldown};
228 if (my $bonus = $upattack->{bonus} // $attack->{bonus}) {
229 $maxdamage += $_ for max(
230 map { $bonus->{$_} + $bonus->{"-$_"} * 3 }
231 grep { !/^-/ } keys %{$bonus}
234 $maxdamage *= ($upattack->{count} // $attack->{count} // 1)
235 / ($upattack->{cooldown} // $attack->{cooldown});
236 $out .= showrangeint($damage, $maxdamage);
239 $out .= '<td class="unit hurt-g">' . '▽' x !!($attack->{anti} & 1);
240 $out .= '<td class="unit hurt-a">' . '△' x !!($attack->{anti} & 2);
242 $out .= '<td class="val unit-range">' .
243 showrangeint($attack->{range}, $upattack->{range});
250 my $specials = $row->{special} or return '';
251 return join ' ', map {
252 sprintf '<span%s title="%s">%s</span>',
254 $_->{duration} < 0 && ' class="magic-perma"',
255 $_->{detect} && ' class="unit-detect"',
258 $_->{name} // $_->{alt},
259 $_->{desc} ? ": $_->{desc}" : '',
260 (map { $_ && " ($_)" } join ', ',
261 #TODO: apply upgrades
262 $_->{range} ? "range $_->{range}" : (),
263 $_->{cost} ? showcost($_, $row) :
264 $_->{cooldown} ? "cooldown $_->{cooldown}s" : (),
267 sprintf($_->{build} ? '(%s)' : '%s', $_->{abbr}),
268 } grep { defined $_->{abbr} } @{$specials};
274 $_->{hp} += $_->{shield} if $_->{shield};
277 '<td class="val unit-min">' . ($_->{min} // ''),
278 '<td class="val unit-gas">' . ($_->{gas} || ''),
279 defined $_->{transform} ? sprintf('<td class="val time">%.0f',
282 !defined $_->{build} ? '<td>' : sprintf('<td class="val time"%s>%s%.0f',
283 defined $_->{warp} && sprintf(' title="%.0f without warpgate"', $_->{build}),
284 !!$_->{base} && sprintf(
285 '<span class="unit-composed" title="%s">+</span>',
286 'from '.join('+', @{ $_->{base} }),
288 $_->{warp} // $_->{build} || '0',
290 sprintf('<td class="unit unit-%s" title="%4$s%3$s">%s',
291 $_-> {cargo} < 0 ? ('supply', T => 'transport') :
292 $_->{upgraded}->{cargo} < 0 ? ('supply magic-opt', T => 'optional transport') :
293 $_-> {attr}->{flying} ? ('air', F => 'flying') :
294 $_->{upgraded}->{attr}->{flying} ? ('air magic-opt', F => 'potentially flying') :
295 $_->{attr}->{structure} ? ('x', B => 'building') :
297 [qw( x s m l l h h h h )]->[ $_->{cargo} ],
299 $_->{cargo} ? 'transportable' : 'untransportable',
301 defined $_->{size} && sprintf('⌀%.1f ', $_->{size}),
303 sprintf('<td class="val unit unit-pop%s">%s',
304 defined $_->{pop} && $_->{pop} < 0 && ' unit-supply',
305 defined $_->{pop} && $_->{pop} == .5 ? '½' : $_->{pop},
307 '<td class="unit unit-type">' . join('', grep { $_ }
308 (defined $_->{organic} ? !$_->{organic} : $_->{attr}->{mech})
309 && '<span class="unit-u" title="mechanic">m</span>',
310 ($_->{organic} || $_->{attr}->{organic})
311 && '<span class="unit-o" title="organic">o</span>',
312 $_->{attr}->{psionic}
313 && '<span class="unit-p" title="psionic">ψ</span>',
315 '<td class="unit unit-attr">' . join('', grep { $_ }
316 $_->{attr}->{armored}
317 && '<span class="unit unit-l" title="armored">A</span>',
319 && '<span class="unit unit-s" title="light">L</span>',
320 $_->{suit} && sprintf(
321 '<span class="unit unit-%s" title="%3$s">%s</span>',
329 $_->{attr}->{massive}
330 && '<span class="unit-massive" title="massive">⚓</span>',
332 $_->{hp} < 0 ? '<td class="val unit-hp" title="invulnerable">∞' :
333 '<td class="val unit-hp">' . showrangeint($_->{hp}, $_->{upgraded}->{hp}),
334 $_->{shield} ? sprintf('<td class="val unit-shield">%.0f%%<td',
335 100 * $_->{shield} / $_->{hp}
337 ' class="val unit-armor">' .
338 showrangeint($_->{armor}, $_->{upgraded}->{armor}),
340 '<td class="val unit-sight">' . sprintf(
341 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
342 showrangeint($_->{sight}, $_->{upgraded}->{sight})
344 sprintf('<td class="val unit-speed"%2$s>%s',
346 map { $_ && sprintf '%.1f', $_ }
347 $_->{speed}, $_->{upgraded}->{speed}
349 defined $_->{creep} && sprintf(' title="%s on creep"',
350 $_->{creep} == 1 ? 'same' : showrange(
351 map { $_ && sprintf '%.1f', $_ }
352 $_->{speed} * $_->{creep},
353 $_->{upgraded}->{speed} && $_->{upgraded}->{speed} *
354 ($_->{upgraded}->{creep} // $_->{creep}),
359 && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
360 '<td class="unit-magic">' . showmagic($_),
362 '<tr class="sub"><th class="cat"><td><td colspan=10>',
363 showattack($row, $_),
365 )} 1 .. $#{ $_->{attack} }),
370 my @rows = @{$units};
371 my $grouped = 1; # race headers
372 if (exists $get{order}) {
375 if ($get{order} eq 'name') {
376 @rows = sort {$a->{name} cmp $b->{name}} @rows;
378 elsif ($get{order} eq 'cost') {
380 $_->{gas}*1.5 + $_->{min} + $_->{pop}/8 + $_->{build}/256/8
383 elsif ($get{order} eq 'build') {
384 my %unittime = map { ($_->{name} => $_->{warp} // $_->{build}) } @rows;
385 $unittime{Templar} = $unittime{'High Templar'};
387 ($_->{warp} // $_->{build})
388 + ($_->{gas}*1.5 + $_->{min} + $_->{pop}/8)/1024
389 + ($_->{base} ? ($unittime{$_->{base}->[0]} // 100) + 1 : 0)
392 elsif ($get{order} eq 'size') {
394 $_->{pop}*16 + ($_->{size} // $_->{suit}) + $_->{cargo}/8
395 + $_->{hp}/512 + $_->{min}/8192
398 elsif ($get{order} eq 'hp') {
400 $_->{hp}*1.01 + $_->{armor} + $_->{shield} + $_->{size}/1024,
403 elsif ($get{order} eq 'attack') {
404 $_->{order} = $_->{hp} / 16384 + max(
406 ($_->{dps} ? $_->{dps}->[-1] :
407 ($_->{damage} + $_->{upgrade} * 3)
408 * ($_->{count} // 1) / ($_->{cooldown} // 1)
410 * ($_->{splash} ? 1.01 : 1)
411 * ($_->{type} eq 'implosive' ? .96 : 1)
412 * ($_->{type} eq 'explosive' ? .98 : 1)
416 elsif ($get{order} eq 'speed') {
418 ($_->{upgraded}->{speed} // $_->{speed}*1.01)
419 + $_->{sight}/1024 + $_->{detect}/2048
422 @rows = sort {$a->{order} <=> $b->{order}} @rows if exists $rows[0]->{order};
425 my ($race, $cat) = ('', '');
428 say sprintf '<tbody id="%s"><tr class="race"><th colspan="20"><h2>%s</h2>',
429 $race = $_->{race}, ucfirst $race
430 unless $race eq $_->{race};
433 $_->{cat} = $_->{race};
438 '<th class="cat">', $cat ne $_->{cat} && ($cat = $_->{cat}),
443 for my $subrow (@{ $_->{special} }) {
444 $subrow->{alt} or next;
446 '<tr class="alt"><th class="cat"><td>', $subrow->{alt},
447 showunitcols($subrow),
459 <dd><span class="unit-min">minerals</span> and
460 <span class="unit-gas">gas</span> required to create one unit
461 <dd>includes total expenses if based on existing units
463 <dd>relative time needed to create at least one unit
464 <dd>excludes construction of dependencies such as buildings
465 and <span class="unit-composed">+</span>parent units
467 <dd><span class="unit unit-supply">T</span>ransports can fit upto
468 8 non-<span class="unit unit-air">F</span>lying cargo units
469 <dd>number of command points taken while alive
471 if ($scver{major} > 1) {
472 :>received damage depends on
473 <span class="unit unit-o">o</span>rganic,
474 <span class="unit unit-u">m</span>echanic,
475 <span class="unit unit-p">ψ</span>(ps)ionic,
476 <span class="unit unit-s">L</span>ight, and
477 <span class="unit unit-l">A</span>rmored
479 <dd>massive <span class="unit-massive">⚓</span> units
480 cannot be lifted or slowed and can break force fields<:
482 :>abilities may hit only <span class="unit unit-o">o</span>rganic
483 or <span class="unit unit-u">m</span>echanic targets
484 <dd>affected by <span class="unit unit-s">S</span>mall,
485 <span class="unit unit-m">M</span>edium, or
486 <span class="unit unit-l">L</span>arge damage<:
489 <dd>total number of hitpoints (including shields)
490 <dd>everything zerg (except for eggs) regenerates one point every
491 <:= $scver{major} == 1 ? '4½' : '3.7' :> seconds
493 <dd>percentage of HP in shields
495 if ($scver{major} > 1) {
496 :>shields always take full damage, irrelevant of unit size
499 :>does not take armor bonuses,
500 but upgrades can decrease damage to any shield hit by upto 3
502 if ($scver{major} > 1) {
503 :>after 10 seconds out of combat, 2 points are recharged per game second<:
505 :>recharges one point every 2½ seconds<:
509 <dd>can be increased by upto 3 at various facilities
510 <dd>each point decreases damage per hit by one, upto a minimum of ½
511 <dd>reduction applies to initial damage, before size penalties
512 <small>(so a plasma hit of 12 to 4 armor large deals 2 damage, not ½)</small>
514 <dd>damage per single hit
515 <dd>some weapons fire multiple × times, multiplying armor penalties
516 <dd>splash damage hits all objects nearby <span class="unit-splash">⁜</span>
517 or in a straight line <span class="unit-splash">+</span>.
519 if ($scver{major} > 1) {
520 :>does not include <span>≥</span>bonus damage
521 dealt to susceptible unit types
522 <dd><span class="unit-pdd">•</span>projectile shots are negated by
523 Point Defense Drones<:
525 :><span class="unit-l">*</span>explosive damage does only
526 50% damage to <span class="unit unit-s">S</span>mall units,
527 75% to <span class="unit unit-m">M</span>edium,
528 100% to <span class="unit unit-l">L</span>arge
529 <dd><span class="unit-s">~</span>concussive/plasma damage does
530 25% to <span class="unit unit-l">L</span>arge,
531 50% <span class="unit unit-m">M</span>edium,
532 100% to <span class="unit unit-s">S</span>mall units<:
534 <dd><span class="hurtrel">dps</span> indicates relative total amount of damage
535 done in 1 second of <:= $scver{major} > 1 ? '<em>Normal</em> in-game time' :
536 'time on <em>Fast</em> game speed' :>
537 <dd>targets <span class="hurt-g">▽</span> ground
538 and/or <span class="hurt-a">△</span> air
540 <dd>maximum hex distance a weapon can fire (note Sieged Tank also has a minimum)
542 <dd>range in which the unit detects other units
543 <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
545 <dd>top movement speed in hex per second
546 <dd>acceleration and deceleration ignored
548 <dd>parentheses () indicate that it needs to be researched first
549 <dd><span class="magic-perma">passive</span> abilities are always enabled
550 <dd>hover for description
551 <dd>range is maximum distance allowed to activate
552 <dd>cost describes energy loss percentage on spawn and when fully charged
556 When two values are given (1-2), the second value indicates the attribute
557 after all possible upgrades.