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',
26 $Request = 'lotv' if $Request eq '2';
27 my %scver = %{ $scvers{$Request} // {} }
28 or Html(), Abort("Requested version <q>$Request</q> not available", '404 request not found');
30 my $datafile = "sc-units-$Request.inc.pl";
33 title => "$scver{title} unit cheat sheet",
36 "Reference of $scver{game} unit properties,"
37 . " comparing various statistics of all the units in $scver{name}"
38 . ' including costs, damage, defense, speed, ranges, and abilities.',
42 starcraft game unit statistics stats comparison table sheet cheat
43 reference software attributes properties patch attribute multiplayer
45 $scver{major} < 2 ? qw' bw broodwar brood war ' :
46 qw' starcraft2 lotv hots wol ',
48 stylesheet => [qw( light dark )],
49 raw => '<link rel="stylesheet" type="text/css" media="all" href="/sc.css?1.2">',
53 say "<h1>$scver{game} units</h1>\n";
55 my $units = do $datafile;
56 Abort("Cannot open unit data", 501, $_) for $@ || $! || ();
57 my $patch = shift @{$units}
58 or Abort("Cannot open unit data: metadata not found", 501);
60 say "<p>Unit properties as seen or measured in $scver{name}\n$patch.";
61 say "Also see the $_ tables." for join(' and ',
62 (showlink('StarCraft 2: LotV', '/sc/lotv')) x ($Request ne 'lotv'),
63 (showlink( 'HotS', '/sc/hots')) x ($Request ne 'hots'),
64 (showlink('original SC: Brood War', '/sc/bw')) x ($Request ne 'bw'),
69 my ($ref, $increase, $org) = @_;
70 if (ref $increase eq 'HASH') {
71 addupgrade(\${$ref}->{$_}, $increase->{$_}, $org->{$_}) for keys %{$increase};
73 elsif (ref $increase eq 'ARRAY') {
74 addupgrade(\${$ref}->[$_], $increase->[$_], $org->[$_]) for 0 .. $#{$increase};
77 ${$ref} += $increase if $increase =~ /^-?[0-9.]+/;
80 for my $unit (@{$units}) {
81 for my $upgrade (@{ $unit->{upgrade} }) {
82 while (my ($col, $increase) = each %{$upgrade}) {
83 defined $unit->{$col} or next;
84 addupgrade(\$unit->{upgraded}->{$col}, $increase, $unit->{$col});
87 for my $special (@{ $unit->{special} }) {
88 for my $upgrade (@{ $special->{upgrade} }) {
89 while (my ($col, $increase) = each %{$upgrade}) {
90 defined $special->{$col} or next;
91 addupgrade(\$special->{upgraded}->{$col}, $increase, $special->{$col});
98 my ($name, $id, $nolink) = @_;
99 return "$name ▼" if defined $get{order} ? $get{order} eq $id : !$id;
100 return $name if $nolink;
101 return showlink($name, '?'.($id && "order=$id"));
103 :><table class="units">
105 <th><:= coltoggle(exists $get{order} ? 'race' : 'source' => '') :></th>
106 <th class="unit-name"><:= coltoggle(name => 'name') :></th>
107 <th class="val unit-min" title=minerals><:= coltoggle(cost => 'cost') :></th>
108 <th class="val unit-gas">gas</th>
109 <th class="val time"><:= coltoggle(build => 'build') :></th>
110 <th class="unit" colspan="2"><:= coltoggle(qw'size size') :></th>
111 <th class="unit unit-attr" colspan="2">attr</th>
112 <th class="val unit-hp"><:= coltoggle(HP => 'hp') :></th>
113 <th class="val unit-shield">shield</th>
114 <th class="val unit-armor" title="armor">⛨</th>
115 <th class="val hurt"><:= coltoggle(attack => 'attack') :></th>
116 <th class="hurt hurtrel">dps</th>
117 <th class="val unit-range" colspan=3>range</th>
118 <th class="val unit-sight">sight</th>
119 <th class="val unit-speed"><:= coltoggle(speed => 'speed') :></th>
120 <th class="unit-magic">specials</th>
124 my ($min, $max) = @_;
125 return '' if not defined $min;
126 return $min || '-' if !$max or $min == $max;
131 $_ &&= int($_ + .5) for @_; # round halves up
132 return showrange(@_);
136 my ($row, $unit) = @_;
138 sprintf('cost %s%%', join '-',
139 map { $_ && sprintf '%.0f', 100 * $row->{cost} / $_ } grep { defined $_ }
141 $unit->{upgraded}->{energy},
143 $unit->{upgraded}->{capacity},
145 !defined $row->{maint} ? () : sprintf('+%s%%/s', join '-',
146 map { sprintf '%.1f', 100 * $row->{maint} / $_ } grep $_,
148 $unit->{upgraded}->{capacity},
154 my ($row, $area) = @_;
155 my $attack = $row->{attack}->[$area]
156 or return '<td colspan=5 class="hurt">';
158 my $upattack = $row->{upgraded}->{attack}->[$area];
159 my $damage = $attack->{damage};
160 my $maxdamage = $upattack->{damage} // $damage;
161 $maxdamage += ($upattack->{upgrade} // $attack->{upgrade}) * 3;
163 my $out = '<td class="val hurt">';
164 $out .= sprintf '<span title="%s">¤</span> ', showcost($attack, $row)
166 $out .= sprintf('<small>%s× </small>',
167 showrangeint($attack->{count}, $upattack->{count}),
168 ) if $attack->{count} > 1;
169 $out .= '<span class="unit-l" title="explosive">*</span>'
170 if $attack->{type} eq 'explosive';
171 $out .= '<span class="unit-s" title="implosive">~</span>'
172 if $attack->{type} eq 'implosive';
173 if (my @bonus = sort grep { !/^-/ } keys %{ $attack->{bonus} }) {
174 $out .= sprintf('<span class="%s" title="%s">≥</span>',
176 $_ eq 'light' ? 'unit-s' :
177 $_ eq 'armored' ? 'unit-l' :
178 $_ eq 'organic' ? 'unit-o' :
179 $_ eq 'massive' ? 'unit-h' :
180 $_ eq 'shields' ? 'unit-shield' :
186 $attack->{bonus}->{$_},
187 ($upattack->{bonus} // $attack->{bonus})->{$_}
188 + ($upattack->{bonus} // $attack->{bonus})->{"-$_"} * 3,
195 $out .= '<span class="unit-pdd" title="projectile">•</span>'
196 if $attack->{type} eq 'projectile';
198 $out .= sprintf '<span title="%s">', $attack->{name} if $attack->{name};
199 $out .= showrangeint($damage, $maxdamage);
200 $out .= '</span>' if $attack->{name};
201 $out .= sprintf('<span class="unit-splash" title="%s">%s</span>',
202 $attack->{splash} eq 'line' ? ('linear', '+') : ('splash', '⁜')
203 ) if $attack->{splash};
205 $out .= '<td class="val hurt hurtrel">';
206 if ($attack->{dps}) {
207 # precalculated dps, do not touch
208 $out .= showrangeint($attack->{dps}->[0],
209 $upattack->{dps}->[-1] // $attack->{dps}->[-1]
212 elsif ($attack->{cooldown}) {
213 if (my $type = $attack->{type}) {
214 if ($type eq 'explosive') {
217 elsif ($type eq 'implosive') {
221 $damage *= ($attack->{count} // 1) / $attack->{cooldown};
222 if (my $bonus = $upattack->{bonus} // $attack->{bonus}) {
223 $maxdamage += $_ for max(
224 map { $bonus->{$_} + $bonus->{"-$_"} * 3 }
225 grep { !/^-/ } keys %{$bonus}
228 $maxdamage *= ($upattack->{count} // $attack->{count} // 1)
229 / ($upattack->{cooldown} // $attack->{cooldown});
230 $out .= showrangeint($damage, $maxdamage);
233 $out .= '<td class="unit hurt-g">' . '▽' x !!($attack->{anti} & 1);
234 $out .= '<td class="unit hurt-a">' . '△' x !!($attack->{anti} & 2);
236 $out .= '<td class="val unit-range">' .
237 showrangeint($attack->{range}, $upattack->{range});
244 my $specials = $row->{special} or return '';
245 return join ' ', map {
246 sprintf '<span%s title="%s">%s</span>',
247 $_->{duration} < 0 && ' class="magic-perma"',
250 $_->{desc} ? ": $_->{desc}" : '',
251 (map { $_ && " ($_)" } join ', ',
252 #TODO: apply upgrades
253 $_->{range} ? "range $_->{range}" : (),
254 $_->{cost} ? showcost($_, $row) :
255 $_->{cooldown} ? "cooldown $_->{cooldown}s" : (),
258 sprintf($_->{build} ? '(%s)' : '%s', $_->{abbr}),
259 } grep { defined $_->{abbr} } @{$specials};
265 $_->{hp} += $_->{shield} if $_->{shield};
268 '<td class="val unit-min">' . ($_->{min} // ''),
269 '<td class="val unit-gas">' . ($_->{gas} || ''),
270 defined $_->{transform} ? sprintf('<td class="val time">%.0f',
273 !defined $_->{build} ? '<td>' : sprintf('<td class="val time"%s>%s%.0f',
274 defined $_->{warp} && qq(title="$_->{build} without warpgate"),
275 !!$_->{base} && sprintf(
276 '<span class="unit-composed" title="%s">+</span>',
277 'from '.join('+', @{ $_->{base} }),
279 $_->{warp} // $_->{build} || '0',
281 sprintf('<td class="unit unit-%s" title="%4$s%3$s">%s',
282 $_-> {cargo} < 0 ? ('supply', T => 'transport') :
283 $_->{upgraded}->{cargo} < 0 ? ('supply magic-opt', T => 'optional transport') :
284 $_-> {attr}->{flying} ? ('air', F => 'flying') :
285 $_->{upgraded}->{attr}->{flying} ? ('air magic-opt', F => 'potentially flying') :
286 $_->{attr}->{structure} ? ('x', B => 'building') :
288 [qw( x s m l l h h h h )]->[ $_->{cargo} ],
290 $_->{cargo} ? 'transportable' : 'untransportable',
292 defined $_->{size} && sprintf('⌀%.1f ', $_->{size}),
294 sprintf('<td class="val unit unit-pop%s">%s',
295 defined $_->{pop} && $_->{pop} < 0 && ' unit-supply',
296 defined $_->{pop} && $_->{pop} == .5 ? '½' : $_->{pop},
298 '<td class="unit unit-type">' . join('', grep { $_ }
299 (defined $_->{organic} ? !$_->{organic} : $_->{attr}->{mech})
300 && '<span class="unit-u" title="mechanic">m</span>',
301 ($_->{organic} || $_->{attr}->{organic})
302 && '<span class="unit-o" title="organic">o</span>',
303 $_->{attr}->{psionic}
304 && '<span class="unit-p" title="psionic">ψ</span>',
306 '<td class="unit unit-attr">' . join('', grep { $_ }
307 $_->{attr}->{armored}
308 && '<span class="unit unit-l" title="armored">A</span>',
310 && '<span class="unit unit-s" title="light">L</span>',
311 $_->{suit} && sprintf(
312 '<span class="unit unit-%s" title="%3$s">%s</span>',
320 $_->{attr}->{massive}
321 && '<span class="unit-massive" title="massive">⚓</span>',
323 $_->{hp} < 0 ? '<td class="val unit-hp" title="invulnerable">∞' :
324 '<td class="val unit-hp">' . showrangeint($_->{hp}, $_->{upgraded}->{hp}),
325 $_->{shield} ? sprintf('<td class="val unit-shield">%.0f%%<td',
326 100 * $_->{shield} / $_->{hp}
328 ' class="val unit-armor">' .
329 showrangeint($_->{armor}, $_->{upgraded}->{armor}),
331 '<td class="val unit-sight">' . sprintf(
332 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
333 showrangeint($_->{sight}, $_->{upgraded}->{sight})
335 sprintf('<td class="val unit-speed"%2$s>%s',
337 map { $_ && sprintf '%.1f', $_ }
338 $_->{speed}, $_->{upgraded}->{speed}
340 defined $_->{creep} && sprintf(' title="%s on creep"',
341 $_->{creep} == 1 ? 'same' : showrange(
342 map { $_ && sprintf '%.1f', $_ }
343 $_->{speed} * $_->{creep},
344 $_->{upgraded}->{speed} && $_->{upgraded}->{speed} *
345 ($_->{upgraded}->{creep} // $_->{creep}),
350 && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
351 '<td class="unit-magic">' . showmagic($_),
352 !$_->{attack}->[1] ? () : (
353 '<tr><th class="cat" colspan="2"><td colspan=10>', showattack($_, 1), '<td colspan=3>'
355 !$_->{attack}->[2] ? () : (
356 '<tr><th class="cat" colspan="2"><td colspan=10>', showattack($_, 2), '<td colspan=3>'
362 my @rows = @{$units};
363 my $grouped = 1; # race headers
364 if (exists $get{order}) {
367 if ($get{order} eq 'name') {
368 @rows = sort {$a->{name} cmp $b->{name}} @rows;
370 elsif ($get{order} eq 'cost') {
372 $_->{gas}*1.5 + $_->{min} + $_->{pop}/8 + $_->{build}/256/8
375 elsif ($get{order} eq 'build') {
376 my %unittime = map { ($_->{name} => $_->{warp} // $_->{build}) } @rows;
377 $unittime{Templar} = $unittime{'High Templar'};
379 ($_->{warp} // $_->{build})
380 + ($_->{gas}*1.5 + $_->{min} + $_->{pop}/8)/1024
381 + ($_->{base} ? ($unittime{$_->{base}->[0]} // 100) + 1 : 0)
384 elsif ($get{order} eq 'size') {
386 $_->{pop}*16 + ($_->{size} // $_->{suit}) + $_->{cargo}/8
387 + $_->{hp}/512 + $_->{min}/8192
390 elsif ($get{order} eq 'hp') {
392 $_->{hp}*1.01 + $_->{armor} + $_->{shield} + $_->{size}/1024,
395 elsif ($get{order} eq 'attack') {
396 $_->{order} = $_->{hp} / 1024 + $_->{shield} / 1008 + max(
398 ($_->{dps} ? $_->{dps}->[-1] :
399 ($_->{damage} + $_->{upgrade} * 3)
400 * ($_->{count} // 1) / ($_->{cooldown} // 1)
402 * ($_->{splash} ? 1.01 : 1)
403 * ($_->{type} eq 'implosive' ? .96 : 1)
404 * ($_->{type} eq 'explosive' ? .98 : 1)
408 elsif ($get{order} eq 'speed') {
410 ($_->{upgraded}->{speed} // $_->{speed}*1.01)
411 + $_->{sight}/1024 + $_->{detect}/2048
414 @rows = sort {$a->{order} <=> $b->{order}} @rows if exists $rows[0]->{order};
417 my ($race, $cat) = ('', '');
420 say sprintf '<tbody id="%s"><tr class="race"><th colspan="20"><h2>%s</h2>',
421 $race = $_->{race}, ucfirst $race
422 unless $race eq $_->{race};
425 $_->{cat} = $_->{race};
430 '<th class="cat">', $cat ne $_->{cat} && ($cat = $_->{cat}),
435 for my $subrow (@{ $_->{special} }) {
436 $subrow->{alt} or next;
438 '<tr class="alt"><th class="cat"><td>', $subrow->{alt},
439 showunitcols($subrow),
451 <dd><span class="unit-min">minerals</span> and
452 <span class="unit-gas">gas</span> required to create one unit
453 <dd>includes total expenses if based on existing units
455 <dd>relative time needed to create at least one unit
456 <dd>excludes construction of dependencies such as buildings
457 and <span class="unit-composed">+</span>parent units
459 <dd><span class="unit unit-supply">T</span>ransports can fit upto
460 8 non-<span class="unit unit-air">F</span>lying cargo units
461 <dd>number of command points taken while alive
463 if ($scver{major} > 1) {
464 :>received damage depends on
465 <span class="unit unit-o">o</span>rganic,
466 <span class="unit unit-u">m</span>echanic,
467 <span class="unit unit-p">ψ</span>(ps)ionic,
468 <span class="unit unit-s">L</span>ight, and
469 <span class="unit unit-l">A</span>rmored
471 <dd>massive <span class="unit-massive">⚓</span> units
472 cannot be lifted or slowed and can break force fields<:
474 :>abilities may hit only <span class="unit unit-o">o</span>rganic
475 or <span class="unit unit-u">m</span>echanic targets
476 <dd>affected by <span class="unit unit-s">S</span>mall,
477 <span class="unit unit-m">M</span>edium, or
478 <span class="unit unit-l">L</span>arge damage<:
481 <dd>total number of hitpoints (including shields)
482 <dd>everything zerg (except for eggs) regenerates one point every
483 <:= $scver{major} == 1 ? '4½' : '3.7' :> seconds
485 <dd>percentage of HP in shields
487 if ($scver{major} > 1) {
488 :>shields always take full damage, irrelevant of unit size
491 :>does not take armor bonuses,
492 but upgrades can decrease damage to any shield hit by upto 3
494 if ($scver{major} > 1) {
495 :>after 10 seconds out of combat, 2 points are recharged per game second<:
497 :>recharges one point every 2½ seconds<:
501 <dd>can be increased by upto 3 at various facilities
502 <dd>each point decreases damage per hit by one, upto a minimum of ½
503 <dd>reduction applies to initial damage, before size penalties
504 <small>(so a plasma hit of 12 to 4 armor large deals 2 damage, not ½)</small>
506 <dd>damage per single hit
507 <dd>some weapons fire multiple × times, multiplying armor penalties
508 <dd>splash damage hits all objects nearby <span class="unit-splash">⁜</span>
509 or in a straight line <span class="unit-splash">+</span>.
511 if ($scver{major} > 1) {
512 :>does not include <span>≥</span>bonus damage
513 dealt to susceptible unit types
514 <dd><span class="unit-pdd">•</span>projectile shots are negated by
515 Point Defense Drones<:
517 :><span class="unit-l">*</span>explosive damage does only
518 50% damage to <span class="unit unit-s">S</span>mall units,
519 75% to <span class="unit unit-m">M</span>edium,
520 100% to <span class="unit unit-l">L</span>arge
521 <dd><span class="unit-s">~</span>concussive/plasma damage does
522 25% to <span class="unit unit-l">L</span>arge,
523 50% <span class="unit unit-m">M</span>edium,
524 100% to <span class="unit unit-s">S</span>mall units<:
526 <dd><span class="hurtrel">dps</span> indicates relative total amount of damage
527 done in 1 second of <:= $scver{major} > 1 ? '<em>Normal</em> in-game time' :
528 'time on <em>Fast</em> game speed' :>
529 <dd>targets <span class="hurt-g">▽</span> ground
530 and/or <span class="hurt-a">△</span> air
532 <dd>maximum hex distance a weapon can fire (note Sieged Tank also has a minimum)
534 <dd>range in which the unit detects other units
535 <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
537 <dd>top movement speed in hex per second
538 <dd>acceleration and deceleration ignored
540 <dd>parentheses () indicate that it needs to be researched first
541 <dd><span class="magic-perma">passive</span> abilities are always enabled
542 <dd>hover for description
543 <dd>range is maximum distance allowed to activate
544 <dd>cost describes energy loss percentage on spawn and when fully charged
548 When two values are given (1-2), the second value indicates the attribute
549 after all possible upgrades.