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 stylesheet => [qw( light dark )],
56 raw => '<link rel="stylesheet" type="text/css" media="all" href="/sc.css?1.2">',
57 data => ["$datafile.inc.pl"],
60 say "<h1>$scver{game} units</h1>\n";
62 my $units = Data($datafile);
63 my $patch = shift @{$units}
64 or Abort("Cannot open unit data: metadata not found", 501);
66 say "<p>Unit properties as seen or measured in $scver{name}\n$patch.";
67 say "Also see the $_ tables." for join(' and ',
68 (showlink('StarCraft 2: LotV', '/sc/lotv')) x ($Request ne 'lotv'),
69 (showlink( 'HotS', '/sc/hots')) x ($Request ne 'hots'),
70 (showlink('original SC: Brood War', '/sc/bw')) x ($Request ne 'bw'),
75 my ($ref, $increase, $org) = @_;
76 if (ref $increase eq 'HASH') {
77 addupgrade(\${$ref}->{$_}, $increase->{$_}, $org->{$_}) for keys %{$increase};
79 elsif (ref $increase eq 'ARRAY') {
80 addupgrade(\${$ref}->[$_], $increase->[$_], $org->[$_]) for 0 .. $#{$increase};
83 ${$ref} += $increase if $increase =~ /^-?[0-9.]+/;
86 for my $unit (@{$units}) {
87 for my $upgrade (@{ $unit->{upgrade} }) {
88 while (my ($col, $increase) = each %{$upgrade}) {
89 defined $unit->{$col} or next;
90 addupgrade(\$unit->{upgraded}->{$col}, $increase, $unit->{$col});
93 for my $special (@{ $unit->{special} }) {
94 for my $upgrade (@{ $special->{upgrade} }) {
95 while (my ($col, $increase) = each %{$upgrade}) {
96 defined $special->{$col} or next;
97 addupgrade(\$special->{upgraded}->{$col}, $increase, $special->{$col});
104 my ($name, $id, $nolink) = @_;
105 return "$name ▼" if defined $get{order} ? $get{order} eq $id : !$id;
106 return $name if $nolink;
107 return showlink($name, '?'.($id && "order=$id"));
109 :><table class="units">
111 <th><:= coltoggle(exists $get{order} ? 'race' : 'source' => '') :></th>
112 <th class="unit-name"><:= coltoggle(name => 'name') :></th>
113 <th class="val unit-min" title=minerals><:= coltoggle(cost => 'cost') :></th>
114 <th class="val unit-gas">gas</th>
115 <th class="val time"><:= coltoggle(build => 'build') :></th>
116 <th class="unit" colspan="2"><:= coltoggle(qw'size size') :></th>
117 <th class="unit unit-attr" colspan="2">attr</th>
118 <th class="val unit-hp"><:= coltoggle(HP => 'hp') :></th>
119 <th class="val unit-shield">shield</th>
120 <th class="val unit-armor" title="armor">⛨</th>
121 <th class="val hurt"><:= coltoggle(attack => 'attack') :></th>
122 <th class="hurt hurtrel">dps</th>
123 <th class="val unit-range" colspan=3>range</th>
124 <th class="val unit-sight">sight</th>
125 <th class="val unit-speed"><:= coltoggle(speed => 'speed') :></th>
126 <th class="unit-magic">specials</th>
130 my ($min, $max) = @_;
131 return '' if not defined $min;
132 return $min || '-' if !$max or $min == $max;
137 $_ &&= int($_ + .5) for @_; # round halves up
138 return showrange(@_);
142 my ($row, $unit) = @_;
144 sprintf('cost %s%%', join '-',
145 map { $_ && sprintf '%.0f', 100 * $row->{cost} / $_ } grep { defined $_ }
147 $unit->{upgraded}->{energy},
149 $unit->{upgraded}->{capacity},
151 !defined $row->{maint} ? () : sprintf('+%s%%/s', join '-',
152 map { sprintf '%.1f', 100 * $row->{maint} / $_ } grep $_,
154 $unit->{upgraded}->{capacity},
160 my ($row, $area) = @_;
161 my $attack = $row->{attack}->[$area]
162 or return '<td colspan=5 class="hurt">';
164 my $upattack = $row->{upgraded}->{attack}->[$area];
165 my $damage = $attack->{damage};
166 my $maxdamage = $upattack->{damage} // $damage;
167 $maxdamage += ($upattack->{upgrade} // $attack->{upgrade}) * 3;
169 my $out = '<td class="val hurt">';
170 $out .= sprintf '<span title="%s">¤</span> ', showcost($attack, $row)
172 $out .= sprintf('<small>%s× </small>',
173 showrangeint($attack->{count}, $upattack->{count}),
174 ) if $attack->{count} > 1;
175 $out .= '<span class="unit-l" title="explosive">*</span>'
176 if $attack->{type} eq 'explosive';
177 $out .= '<span class="unit-s" title="implosive">~</span>'
178 if $attack->{type} eq 'implosive';
179 if (my @bonus = sort grep { !/^-/ } keys %{ $attack->{bonus} }) {
180 $out .= sprintf('<span class="%s" title="%s">≥</span>',
182 $_ eq 'light' ? 'unit-s' :
183 $_ eq 'armored' ? 'unit-l' :
184 $_ eq 'organic' ? 'unit-o' :
185 $_ eq 'massive' ? 'unit-h' :
186 $_ eq 'shields' ? 'unit-shield' :
187 $_ eq 'structure' ? 'unit-x' :
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>',
255 $_->{duration} < 0 && ' class="magic-perma"',
256 $_->{detect} && ' class="unit-detect"',
259 $_->{name} // $_->{alt},
260 $_->{desc} ? ": $_->{desc}" : '',
261 (map { $_ && " ($_)" } join ', ',
262 #TODO: apply upgrades
263 $_->{range} ? "range $_->{range}" : (),
264 $_->{cost} ? showcost($_, $row) :
265 $_->{cooldown} ? "cooldown $_->{cooldown}s" : (),
268 sprintf($_->{build} ? '(%s)' : '%s', $_->{abbr}),
269 } grep { defined $_->{abbr} } @{$specials};
275 $_->{hp} += $_->{shield} if $_->{shield};
278 '<td class="val unit-min">' . ($_->{min} // ''),
279 '<td class="val unit-gas">' . ($_->{gas} || ''),
280 defined $_->{transform} ? sprintf('<td class="val time">%.0f',
283 !defined $_->{build} ? '<td>' : sprintf('<td class="val time"%s>%s%.0f',
284 defined $_->{warp} && sprintf(' title="%.0f without warpgate"', $_->{build}),
285 !!$_->{base} && sprintf(
286 '<span class="unit-composed" title="%s">+</span>',
287 'from '.join('+', @{ $_->{base} }),
289 $_->{warp} // $_->{build} || '0',
291 sprintf('<td class="unit unit-%s" title="%4$s%3$s">%s',
292 $_-> {cargo} < 0 ? ('supply', T => 'transport') :
293 $_->{upgraded}->{cargo} < 0 ? ('supply magic-opt', T => 'optional transport') :
294 $_-> {attr}->{flying} ? ('air', F => 'flying') :
295 $_->{upgraded}->{attr}->{flying} ? ('air magic-opt', F => 'potentially flying') :
296 $_->{attr}->{structure} ? ('x', B => 'building') :
298 [qw( x s m l l h h h h )]->[ $_->{cargo} ],
300 $_->{cargo} ? 'transportable' : 'untransportable',
302 defined $_->{size} && sprintf('⌀%.1f ', $_->{size}),
304 sprintf('<td class="val unit unit-pop%s">%s',
305 defined $_->{pop} && $_->{pop} < 0 && ' unit-supply',
306 defined $_->{pop} && $_->{pop} == .5 ? '½' : $_->{pop},
308 '<td class="unit unit-type">' . join('', grep { $_ }
309 (defined $_->{organic} ? !$_->{organic} : $_->{attr}->{mech})
310 && '<span class="unit-u" title="mechanic">m</span>',
311 ($_->{organic} || $_->{attr}->{organic})
312 && '<span class="unit-o" title="organic">o</span>',
313 $_->{attr}->{psionic}
314 && '<span class="unit-p" title="psionic">ψ</span>',
316 '<td class="unit unit-attr">' . join('', grep { $_ }
317 $_->{attr}->{armored}
318 && '<span class="unit unit-l" title="armored">A</span>',
320 && '<span class="unit unit-s" title="light">L</span>',
321 $_->{suit} && sprintf(
322 '<span class="unit unit-%s" title="%3$s">%s</span>',
330 $_->{attr}->{massive}
331 && '<span class="unit-massive" title="massive">⚓</span>',
333 $_->{hp} < 0 ? '<td class="val unit-hp" title="invulnerable">∞' :
334 '<td class="val unit-hp">' . showrangeint($_->{hp}, $_->{upgraded}->{hp}),
335 $_->{shield} ? sprintf('<td class="val unit-shield">%.0f%%<td',
336 100 * $_->{shield} / $_->{hp}
338 ' class="val unit-armor">' .
339 showrangeint($_->{armor}, $_->{upgraded}->{armor}),
341 '<td class="val unit-sight">' . sprintf(
342 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
343 showrangeint($_->{sight}, $_->{upgraded}->{sight})
345 sprintf('<td class="val unit-speed"%2$s>%s',
347 map { $_ && sprintf '%.1f', $_ }
348 $_->{speed}, $_->{upgraded}->{speed}
350 defined $_->{creep} && sprintf(' title="%s on creep"',
351 $_->{creep} == 1 ? 'same' : showrange(
352 map { $_ && sprintf '%.1f', $_ }
353 $_->{speed} * $_->{creep},
354 $_->{upgraded}->{speed} && $_->{upgraded}->{speed} *
355 ($_->{upgraded}->{creep} // $_->{creep}),
360 && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
361 '<td class="unit-magic">' . showmagic($_),
363 '<tr class="sub"><th class="cat"><td><td colspan=10>',
364 showattack($row, $_),
366 )} 1 .. $#{ $_->{attack} }),
371 my @rows = @{$units};
372 my $grouped = 1; # race headers
373 if (exists $get{order}) {
376 if ($get{order} eq 'name') {
377 @rows = sort {$a->{name} cmp $b->{name}} @rows;
379 elsif ($get{order} eq 'cost') {
381 $_->{gas}*1.5 + $_->{min} + $_->{pop}/8 + $_->{build}/256/8
384 elsif ($get{order} eq 'build') {
385 my %unittime = map { ($_->{name} => $_->{warp} // $_->{build}) } @rows;
386 $unittime{Templar} = $unittime{'High Templar'};
388 ($_->{warp} // $_->{build})
389 + ($_->{gas}*1.5 + $_->{min} + $_->{pop}/8)/1024
390 + ($_->{base} ? ($unittime{$_->{base}->[0]} // 100) + 1 : 0)
393 elsif ($get{order} eq 'size') {
395 $_->{pop}*16 + ($_->{size} // $_->{suit}) + $_->{cargo}/8
396 + $_->{hp}/512 + $_->{min}/8192
399 elsif ($get{order} eq 'hp') {
401 $_->{hp}*1.01 + $_->{armor} + $_->{shield} + $_->{size}/1024,
404 elsif ($get{order} eq 'attack') {
405 $_->{order} = $_->{hp} / 16384 + max(
407 ($_->{dps} ? $_->{dps}->[-1] :
408 ($_->{damage} + $_->{upgrade} * 3)
409 * ($_->{count} // 1) / ($_->{cooldown} // 1)
411 * ($_->{splash} ? 1.01 : 1)
412 * ($_->{type} eq 'implosive' ? .96 : 1)
413 * ($_->{type} eq 'explosive' ? .98 : 1)
417 elsif ($get{order} eq 'speed') {
419 ($_->{upgraded}->{speed} // $_->{speed}*1.01)
420 + $_->{sight}/1024 + $_->{detect}/2048
423 @rows = sort {$a->{order} <=> $b->{order}} @rows if exists $rows[0]->{order};
426 my ($race, $cat) = ('', '');
429 say sprintf '<tbody id="%s"><tr class="race"><th colspan="20"><h2>%s</h2>',
430 $race = $_->{race}, ucfirst $race
431 unless $race eq $_->{race};
434 $_->{cat} = $_->{race};
439 '<th class="cat">', $cat ne $_->{cat} && ($cat = $_->{cat}),
444 for my $subrow (@{ $_->{special} }) {
445 $subrow->{alt} or next;
447 '<tr class="alt"><th class="cat"><td>', $subrow->{alt},
448 showunitcols($subrow),
460 <dd><span class="unit-min">minerals</span> and
461 <span class="unit-gas">gas</span> required to create one unit
462 <dd>includes total expenses if based on existing units
464 <dd>relative time needed to create at least one unit
465 <dd>excludes construction of dependencies such as buildings
466 and <span class="unit-composed">+</span>parent units
468 <dd><span class="unit unit-supply">T</span>ransports can fit upto
469 8 non-<span class="unit unit-air">F</span>lying cargo units
470 <dd>number of command points taken while alive
472 if ($scver{major} > 1) {
473 :>received damage depends on
474 <span class="unit unit-o">o</span>rganic,
475 <span class="unit unit-u">m</span>echanic,
476 <span class="unit unit-p">ψ</span>(ps)ionic,
477 <span class="unit unit-s">L</span>ight, and
478 <span class="unit unit-l">A</span>rmored
480 <dd>massive <span class="unit-massive">⚓</span> units
481 cannot be lifted or slowed and can break force fields<:
483 :>abilities may hit only <span class="unit unit-o">o</span>rganic
484 or <span class="unit unit-u">m</span>echanic targets
485 <dd>affected by <span class="unit unit-s">S</span>mall,
486 <span class="unit unit-m">M</span>edium, or
487 <span class="unit unit-l">L</span>arge damage<:
490 <dd>total number of hitpoints (including shields)
491 <dd>everything zerg (except for eggs) regenerates one point every
492 <:= $scver{major} == 1 ? '4½' : '3.7' :> seconds
494 <dd>percentage of HP in shields
496 if ($scver{major} > 1) {
497 :>shields always take full damage, irrelevant of unit size
500 :>does not take armor bonuses,
501 but upgrades can decrease damage to any shield hit by upto 3
503 if ($scver{major} > 1) {
504 :>after 10 seconds out of combat, 2 points are recharged per game second<:
506 :>recharges one point every 2½ seconds<:
510 <dd>can be increased by upto 3 at various facilities
511 <dd>each point decreases damage per hit by one, upto a minimum of ½
512 <dd>reduction applies to initial damage, before size penalties
513 <small>(so a plasma hit of 12 to 4 armor large deals 2 damage, not ½)</small>
515 <dd>damage per single hit
516 <dd>some weapons fire multiple × times, multiplying armor penalties
517 <dd>splash damage hits all objects nearby <span class="unit-splash">⁜</span>
518 or in a straight line <span class="unit-splash">+</span>.
520 if ($scver{major} > 1) {
521 :>does not include <span>≥</span>bonus damage
522 dealt to susceptible unit types
523 <dd><span class="unit-pdd">•</span>projectile shots are negated by
524 Point Defense Drones<:
526 :><span class="unit-l">*</span>explosive damage does only
527 50% damage to <span class="unit unit-s">S</span>mall units,
528 75% to <span class="unit unit-m">M</span>edium,
529 100% to <span class="unit unit-l">L</span>arge
530 <dd><span class="unit-s">~</span>concussive/plasma damage does
531 25% to <span class="unit unit-l">L</span>arge,
532 50% <span class="unit unit-m">M</span>edium,
533 100% to <span class="unit unit-s">S</span>mall units<:
535 <dd><span class="hurtrel">dps</span> indicates relative total amount of damage
536 done in 1 second of <:= $scver{major} > 1 ? '<em>Normal</em> in-game time' :
537 'time on <em>Fast</em> game speed' :>
538 <dd>targets <span class="hurt-g">▽</span> ground
539 and/or <span class="hurt-a">△</span> air
541 <dd>maximum hex distance a weapon can fire (note Sieged Tank also has a minimum)
543 <dd>range in which the unit detects other units
544 <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
546 <dd>top movement speed in hex per second
547 <dd>acceleration and deceleration ignored
549 <dd>parentheses () indicate that it needs to be researched first
550 <dd><span class="magic-perma">passive</span> abilities are always enabled
551 <dd>hover for description
552 <dd>range is maximum distance allowed to activate
553 <dd>cost describes energy loss percentage on spawn and when fully charged
557 When two values are given (1-2), the second value indicates the attribute
558 after all possible upgrades.