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 Abort("Requested version $Request not available", '404 unknown');
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 $attack->{bonus}->{$_} + $attack->{bonus}->{"-$_"} * 3,
194 $out .= '<span class="unit-pdd" title="projectile">•</span>'
195 if $attack->{type} eq 'projectile';
197 $out .= sprintf '<span title="%s">', $attack->{name} if $attack->{name};
198 $out .= showrangeint($damage, $maxdamage);
199 $out .= '</span>' if $attack->{name};
200 $out .= sprintf('<span class="unit-splash" title="%s">%s</span>',
201 $attack->{splash} eq 'line' ? ('linear', '+') : ('splash', '⁜')
202 ) if $attack->{splash};
204 $out .= '<td class="val hurt hurtrel">';
205 if ($attack->{dps}) {
206 # precalculated dps, do not touch
207 $out .= showrangeint($attack->{dps}->[0],
208 $upattack->{dps}->[-1] // $attack->{dps}->[-1]
211 elsif ($attack->{cooldown}) {
212 if (my $type = $attack->{type}) {
213 if ($type eq 'explosive') {
216 elsif ($type eq 'implosive') {
220 $damage *= ($attack->{count} // 1) / $attack->{cooldown};
221 if (my $bonus = $upattack->{bonus} // $attack->{bonus}) {
222 $maxdamage += $_ for max(
223 map { $bonus->{$_} + $bonus->{"-$_"} * 3 }
224 grep { !/^-/ } keys %{$bonus}
227 $maxdamage *= ($upattack->{count} // $attack->{count} // 1)
228 / ($upattack->{cooldown} // $attack->{cooldown});
229 $out .= showrangeint($damage, $maxdamage);
232 $out .= '<td class="unit hurt-g">' . '▽' x !!($attack->{anti} & 1);
233 $out .= '<td class="unit hurt-a">' . '△' x !!($attack->{anti} & 2);
235 $out .= '<td class="val unit-range">' .
236 showrangeint($attack->{range}, $upattack->{range});
243 my $specials = $row->{special} or return '';
244 return join ' ', map {
245 sprintf '<span%s title="%s">%s</span>',
246 $_->{duration} < 0 && ' class="magic-perma"',
249 $_->{desc} ? ": $_->{desc}" : '',
250 (map { $_ && " ($_)" } join ', ',
251 #TODO: apply upgrades
252 $_->{range} ? "range $_->{range}" : (),
253 $_->{cost} ? showcost($_, $row) :
254 $_->{cooldown} ? "cooldown $_->{cooldown}s" : (),
257 sprintf($_->{build} ? '(%s)' : '%s', $_->{abbr}),
258 } grep { defined $_->{abbr} } @{$specials};
264 $_->{hp} += $_->{shield} if $_->{shield};
267 '<td class="val unit-min">' . ($_->{min} // ''),
268 '<td class="val unit-gas">' . ($_->{gas} || ''),
269 defined $_->{transform} ? sprintf('<td class="val time">%.0f',
272 !defined $_->{build} ? '<td>' : sprintf('<td class="val time"%s>%s%.0f',
273 defined $_->{warp} && qq(title="$_->{build} without warpgate"),
274 !!$_->{base} && sprintf(
275 '<span class="unit-composed" title="%s">+</span>',
276 'from '.join('+', @{ $_->{base} }),
278 $_->{warp} // $_->{build} || '0',
280 sprintf('<td class="unit unit-%s" title="%4$s%3$s">%s',
281 $_-> {cargo} < 0 ? ('supply', T => 'transport') :
282 $_->{upgraded}->{cargo} < 0 ? ('supply magic-opt', T => 'optional transport') :
283 $_-> {attr}->{flying} ? ('air', F => 'flying') :
284 $_->{upgraded}->{attr}->{flying} ? ('air magic-opt', F => 'potentially flying') :
285 $_->{attr}->{structure} ? ('x', B => 'building') :
287 [qw( x s m l l h h h h )]->[ $_->{cargo} ],
289 $_->{cargo} ? 'transportable' : 'untransportable',
291 defined $_->{size} && sprintf('⌀%.1f ', $_->{size}),
293 sprintf('<td class="val unit unit-pop%s">%s',
294 defined $_->{pop} && $_->{pop} < 0 && ' unit-supply',
295 defined $_->{pop} && $_->{pop} == .5 ? '½' : $_->{pop},
297 '<td class="unit unit-type">' . join('', grep { $_ }
298 (defined $_->{organic} ? !$_->{organic} : $_->{attr}->{mech})
299 && '<span class="unit-u" title="mechanic">m</span>',
300 ($_->{organic} || $_->{attr}->{organic})
301 && '<span class="unit-o" title="organic">o</span>',
302 $_->{attr}->{psionic}
303 && '<span class="unit-p" title="psionic">ψ</span>',
305 '<td class="unit unit-attr">' . join('', grep { $_ }
306 $_->{attr}->{armored}
307 && '<span class="unit unit-l" title="armored">A</span>',
309 && '<span class="unit unit-s" title="light">L</span>',
310 $_->{suit} && sprintf(
311 '<span class="unit unit-%s" title="%3$s">%s</span>',
319 $_->{attr}->{massive}
320 && '<span class="unit-massive" title="massive">⚓</span>',
322 $_->{hp} < 0 ? '<td class="val unit-hp" title="invulnerable">∞' :
323 '<td class="val unit-hp">' . showrangeint($_->{hp}, $_->{upgraded}->{hp}),
324 $_->{shield} ? sprintf('<td class="val unit-shield">%.0f%%<td',
325 100 * $_->{shield} / $_->{hp}
327 ' class="val unit-armor">' .
328 showrangeint($_->{armor}, $_->{upgraded}->{armor}),
330 '<td class="val unit-sight">' . sprintf(
331 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
332 showrangeint($_->{sight}, $_->{upgraded}->{sight})
334 sprintf('<td class="val unit-speed"%2$s>%s',
336 map { $_ && sprintf '%.1f', $_ }
337 $_->{speed}, $_->{upgraded}->{speed}
339 defined $_->{creep} && sprintf(' title="%s on creep"',
340 $_->{creep} == 1 ? 'same' : showrange(
341 map { $_ && sprintf '%.1f', $_ }
342 $_->{speed} * $_->{creep},
343 $_->{upgraded}->{speed} && $_->{upgraded}->{speed} *
344 ($_->{upgraded}->{creep} // $_->{creep}),
349 && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
350 '<td class="unit-magic">' . showmagic($_),
351 !$_->{attack}->[1] ? () : (
352 '<tr><th class="cat" colspan="2"><td colspan=10>', showattack($_, 1), '<td colspan=3>'
354 !$_->{attack}->[2] ? () : (
355 '<tr><th class="cat" colspan="2"><td colspan=10>', showattack($_, 2), '<td colspan=3>'
361 my @rows = @{$units};
362 my $grouped = 1; # race headers
363 if (exists $get{order}) {
366 if ($get{order} eq 'name') {
367 @rows = sort {$a->{name} cmp $b->{name}} @rows;
369 elsif ($get{order} eq 'hp') {
371 $_->{hp}*1.01 + $_->{armor} + $_->{shield} + $_->{size}/1024,
374 elsif ($get{order} eq 'cost') {
376 $_->{gas}*1.5 + $_->{min} + $_->{pop}/8 + $_->{build}/256/8
379 elsif ($get{order} eq 'build') {
380 my %unittime = map { ($_->{name} => $_->{warp} // $_->{build}) } @rows;
381 $unittime{Templar} = $unittime{'High Templar'};
383 ($_->{warp} // $_->{build})
384 + ($_->{gas}*1.5 + $_->{min} + $_->{pop}/8)/1024
385 + ($_->{base} ? ($unittime{$_->{base}->[0]} // 100) + 1 : 0)
388 elsif ($get{order} eq 'size') {
390 $_->{pop}*16 + ($_->{size} // $_->{suit}) + $_->{cargo}/8
391 + $_->{hp}/512 + $_->{min}/8192
394 elsif ($get{order} eq 'attack') {
395 $_->{order} = $_->{hp} / 1024 + $_->{shield} / 1008 + max(
397 ($_->{dps} ? $_->{dps}->[-1] :
398 ($_->{damage} + $_->{upgrade} * 3)
399 * ($_->{count} // 1) / ($_->{cooldown} // 1)
401 * ($_->{splash} ? 1.01 : 1)
402 * ($_->{type} eq 'implosive' ? .96 : 1)
403 * ($_->{type} eq 'explosive' ? .98 : 1)
407 elsif ($get{order} eq 'speed') {
409 ($_->{upgraded}->{speed} // $_->{speed}*1.01)
410 + $_->{sight}/1024 + $_->{detect}/2048
413 @rows = sort {$a->{order} <=> $b->{order}} @rows if exists $rows[0]->{order};
416 my ($race, $cat) = ('', '');
419 say sprintf '<tbody id="%s"><tr class="race"><th colspan="20"><h2>%s</h2>',
420 $race = $_->{race}, ucfirst $race
421 unless $race eq $_->{race};
424 $_->{cat} = $_->{race};
429 '<th class="cat">', $cat ne $_->{cat} && ($cat = $_->{cat}),
434 for my $subrow (@{ $_->{special} }) {
435 $subrow->{alt} or next;
437 '<tr class="alt"><th class="cat"><td>', $subrow->{alt},
438 showunitcols($subrow),
450 <dd><span class="unit-min">minerals</span> and
451 <span class="unit-gas">gas</span> required to create one unit
452 <dd>includes total expenses if based on existing units
454 <dd>relative time needed to create at least one unit
455 <dd>excludes construction of dependencies such as buildings
456 and <span class="unit-composed">+</span>parent units
458 <dd><span class="unit unit-supply">T</span>ransports can fit upto
459 8 non-<span class="unit unit-air">F</span>lying cargo units
460 <dd>number of command points taken while alive
462 if ($scver{major} > 1) {
463 :>received damage depends on
464 <span class="unit unit-o">o</span>rganic,
465 <span class="unit unit-u">m</span>echanic,
466 <span class="unit unit-p">ψ</span>(ps)ionic,
467 <span class="unit unit-s">L</span>ight, and
468 <span class="unit unit-l">A</span>rmored
470 <dd>massive <span class="unit-massive">⚓</span> units
471 cannot be lifted or slowed and can break force fields<:
473 :>abilities may hit only <span class="unit unit-o">o</span>rganic
474 or <span class="unit unit-u">m</span>echanic targets
475 <dd>affected by <span class="unit unit-s">S</span>mall,
476 <span class="unit unit-m">M</span>edium, or
477 <span class="unit unit-l">L</span>arge damage<:
480 <dd>total number of hitpoints (including shields)
481 <dd>everything zerg (except for eggs) regenerates one point every
482 <:= $scver{major} == 1 ? '4½' : '3.7' :> seconds
484 <dd>percentage of HP in shields
486 if ($scver{major} > 1) {
487 :>shields always take full damage, irrelevant of unit size
490 :>does not take armor bonuses,
491 but upgrades can decrease damage to any shield hit by upto 3
493 if ($scver{major} > 1) {
494 :>after 10 seconds out of combat, 2 points are recharged per game second<:
496 :>recharges one point every 2½ seconds<:
500 <dd>can be increased by upto 3 at various facilities
501 <dd>each point decreases damage per hit by one, upto a minimum of ½
502 <dd>reduction applies to initial damage, before size penalties
503 <small>(so a plasma hit of 12 to 4 armor large deals 2 damage, not ½)</small>
505 <dd>damage per single hit
506 <dd>some weapons fire multiple × times, multiplying armor penalties
507 <dd>splash damage hits all objects nearby <span class="unit-splash">⁜</span>
508 or in a straight line <span class="unit-splash">+</span>.
510 if ($scver{major} > 1) {
511 :>does not include <span>≥</span>bonus damage
512 dealt to susceptible unit types
513 <dd><span class="unit-pdd">•</span>projectile shots are negated by
514 Point Defense Drones<:
516 :><span class="unit-l">*</span>explosive damage does only
517 50% damage to <span class="unit unit-s">S</span>mall units,
518 75% to <span class="unit unit-m">M</span>edium,
519 100% to <span class="unit unit-l">L</span>arge
520 <dd><span class="unit-s">~</span>concussive/plasma damage does
521 25% to <span class="unit unit-l">L</span>arge,
522 50% <span class="unit unit-m">M</span>edium,
523 100% to <span class="unit unit-s">S</span>mall units<:
525 <dd><span class="hurtrel">dps</span> indicates relative total amount of damage
526 done in 1 second of <:= $scver{major} > 1 ? '<em>Normal</em> in-game time' :
527 'time on <em>Fast</em> game speed' :>
528 <dd>targets <span class="hurt-g">▽</span> ground
529 and/or <span class="hurt-a">△</span> air
531 <dd>maximum hex distance a weapon can fire (note Sieged Tank also has a minimum)
533 <dd>range in which the unit detects other units
534 <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
536 <dd>top movement speed in hex per second
537 <dd>acceleration and deceleration ignored
539 <dd>parentheses () indicate that it needs to be researched first
540 <dd><span class="magic-perma">passive</span> abilities are always enabled
541 <dd>hover for description
542 <dd>range is maximum distance allowed to activate
543 <dd>cost describes energy loss percentage on spawn and when fully charged
547 When two values are given (1-2), the second value indicates the attribute
548 after all possible upgrades.