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'],
49 raw => '<link rel="stylesheet" type="text/css" media="all" href="/sc.css?1.1" title="light">',
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><:= coltoggle(name => 'name') :></th>
107 <th class="val min" title=minerals><:= coltoggle(cost => 'cost') :></th>
108 <th class="val 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" 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 min">' . ($_->{min} // ''),
268 '<td class="val 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 $_->{attr}->{structure} ? ('x', B => 'building') :
286 [qw( x s m l l h h h h )]->[ $_->{cargo} ],
288 $_->{cargo} ? 'transportable' : 'untransportable',
290 defined $_->{size} && sprintf('⌀%.1f ', $_->{size}),
292 sprintf('<td class="val unit%s">%s',
293 defined $_->{pop} && $_->{pop} < 0 && ' unit-supply',
294 defined $_->{pop} && $_->{pop} == .5 ? '½' : $_->{pop},
296 '<td class="unit unit-type">' . join('', grep { $_ }
297 (defined $_->{organic} ? !$_->{organic} : $_->{attr}->{mech})
298 && '<span class="unit-u" title="mechanic">m</span>',
299 ($_->{organic} || $_->{attr}->{organic})
300 && '<span class="unit-o" title="organic">o</span>',
301 $_->{attr}->{psionic}
302 && '<span class="unit-p" title="psionic">ψ</span>',
304 '<td class="unit unit-attr">' . join('', grep { $_ }
305 $_->{attr}->{armored}
306 && '<span class="unit unit-l" title="armored">A</span>',
308 && '<span class="unit unit-s" title="light">L</span>',
309 $_->{suit} && sprintf(
310 '<span class="unit unit-%s" title="%3$s">%s</span>',
318 $_->{attr}->{massive}
319 && '<span class="unit-massive" title="massive">⚓</span>',
321 $_->{hp} < 0 ? '<td class="val unit-hp" title="invulnerable">∞' :
322 '<td class="val unit-hp">' . showrangeint($_->{hp}, $_->{upgraded}->{hp}),
323 $_->{shield} ? sprintf('<td class="val unit-shield">%.0f%%<td',
324 100 * $_->{shield} / $_->{hp}
326 ' class="val unit-armor">' .
327 showrangeint($_->{armor}, $_->{upgraded}->{armor}),
329 '<td class="val unit-sight">' . sprintf(
330 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
331 showrangeint($_->{sight}, $_->{upgraded}->{sight})
333 sprintf('<td class="val unit-speed"%2$s>%s',
335 map { $_ && sprintf '%.1f', $_ }
336 $_->{speed}, $_->{upgraded}->{speed}
338 defined $_->{creep} && sprintf(' title="%s on creep"',
339 $_->{creep} == 1 ? 'same' : showrange(
340 map { $_ && sprintf '%.1f', $_ }
341 $_->{speed} * $_->{creep},
342 $_->{upgraded}->{speed} && $_->{upgraded}->{speed} *
343 ($_->{upgraded}->{creep} // $_->{creep}),
348 && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
349 '<td class="unit-magic">' . showmagic($_),
350 !$_->{attack}->[1] ? () : (
351 '<tr><td colspan=12>', showattack($_, 1), '<td colspan=3>'
353 !$_->{attack}->[2] ? () : (
354 '<tr><td colspan=12>', showattack($_, 2), '<td colspan=3>'
360 my @rows = @{$units};
361 my $grouped = 1; # race headers
362 if (exists $get{order}) {
365 if ($get{order} eq 'name') {
366 @rows = sort {$a->{name} cmp $b->{name}} @rows;
368 elsif ($get{order} eq 'hp') {
370 $_->{hp}*1.01 + $_->{armor} + $_->{shield} + $_->{size}/1024,
373 elsif ($get{order} eq 'cost') {
375 $_->{gas}*1.5 + $_->{min} + $_->{pop}/8 + $_->{build}/256/8
378 elsif ($get{order} eq 'build') {
379 my %unittime = map { ($_->{name} => $_->{warp} // $_->{build}) } @rows;
380 $unittime{Templar} = $unittime{'High Templar'};
382 ($_->{warp} // $_->{build})
383 + ($_->{gas}*1.5 + $_->{min} + $_->{pop}/8)/1024
384 + ($_->{base} ? ($unittime{$_->{base}->[0]} // 100) + 1 : 0)
387 elsif ($get{order} eq 'size') {
389 $_->{pop}*16 + ($_->{size} // $_->{suit}) + $_->{cargo}/8
390 + $_->{hp}/512 + $_->{min}/8192
393 elsif ($get{order} eq 'attack') {
394 $_->{order} = $_->{hp} / 1024 + $_->{shield} / 1008 + max(
396 ($_->{dps} ? $_->{dps}->[-1] :
397 ($_->{damage} + $_->{upgrade} * 3)
398 * ($_->{count} // 1) / ($_->{cooldown} // 1)
400 * ($_->{splash} ? 1.01 : 1)
401 * ($_->{type} eq 'implosive' ? .96 : 1)
402 * ($_->{type} eq 'explosive' ? .98 : 1)
406 elsif ($get{order} eq 'speed') {
408 ($_->{upgraded}->{speed} // $_->{speed}*1.01)
409 + $_->{sight}/1024 + $_->{detect}/2048
412 @rows = sort {$a->{order} <=> $b->{order}} @rows if exists $rows[0]->{order};
415 my ($race, $cat) = ('', '');
418 say sprintf '<tbody id="%s"><tr class="race"><th colspan="20"><h2>%s</h2>',
419 $race = $_->{race}, ucfirst $race
420 unless $race eq $_->{race};
423 $_->{cat} = $_->{race};
428 '<th class="cat">', $cat ne $_->{cat} && ($cat = $_->{cat}),
433 for my $subrow (@{ $_->{special} }) {
434 $subrow->{alt} or next;
436 '<tr class="alt"><th class="cat"><td>', $subrow->{alt},
437 showunitcols($subrow),
449 <dd>minerals and gas required to create one unit
450 <dd>includes total expenses if based on existing units
452 <dd>relative time needed to create at least one unit
453 <dd>excludes construction of dependencies such as buildings
454 and <span class="unit-composed">+</span>parent units
456 <dd><span class="unit unit-supply">T</span>ransports can fit upto
457 8 non-<span class="unit unit-air">F</span>lying cargo units
458 <dd>number of command points taken while alive
460 if ($scver{major} > 1) {
461 :>received damage depends on
462 <span class="unit unit-o">o</span>rganic,
463 <span class="unit unit-u">m</span>echanic,
464 <span class="unit unit-p">ψ</span>(ps)ionic,
465 <span class="unit unit-s">L</span>ight, and
466 <span class="unit unit-l">A</span>rmored
468 <dd>massive <span class="unit-massive">⚓</span> units
469 cannot be lifted or slowed and can break force fields<:
471 :>abilities may hit only <span class="unit unit-o">o</span>rganic
472 or <span class="unit unit-u">m</span>echanic targets
473 <dd>affected by <span class="unit unit-s">S</span>mall,
474 <span class="unit unit-m">M</span>edium, or
475 <span class="unit unit-l">L</span>arge damage<:
478 <dd>total number of hitpoints (including shields)
479 <dd>everything zerg (except for eggs) regenerates one point every
480 <:= $scver{major} == 1 ? '4½' : '3.7' :> seconds
482 <dd>percentage of HP in shields
484 if ($scver{major} > 1) {
485 :>shields always take full damage, irrelevant of unit size
488 :>does not take armor bonuses,
489 but upgrades can decrease damage to any shield hit by upto 3
491 if ($scver{major} > 1) {
492 :>after 10 seconds out of combat, 2 points are recharged per game second<:
494 :>recharges one point every 2½ seconds<:
498 <dd>can be increased by upto 3 at various facilities
499 <dd>each point decreases damage per hit by one, upto a minimum of ½
500 <dd>reduction applies to initial damage, before size penalties
501 <small>(so a plasma hit of 12 to 4 armor large deals 2 damage, not ½)</small>
503 <dd>damage per single hit
504 <dd>some weapons fire multiple × times, multiplying armor penalties
505 <dd>splash damage hits all objects nearby <span class="unit-splash">⁜</span>
506 or in a straight line <span class="unit-splash">+</span>.
508 if ($scver{major} > 1) {
509 :>does not include <span>≥</span>bonus damage
510 dealt to susceptible unit types
511 <dd><span class="unit-pdd">•</span>projectile shots are negated by
512 Point Defense Drones<:
514 :><span class="unit-l">*</span>explosive damage does only
515 50% damage to <span class="unit unit-s">S</span>mall units,
516 75% to <span class="unit unit-m">M</span>edium,
517 100% to <span class="unit unit-l">L</span>arge
518 <dd><span class="unit-s">~</span>concussive/plasma damage does
519 25% to <span class="unit unit-l">L</span>arge,
520 50% <span class="unit unit-m">M</span>edium,
521 100% to <span class="unit unit-s">S</span>mall units<:
523 <dd><span class="hurtrel">dps</span> indicates relative total amount of damage
524 done in 1 second of <:= $scver{major} > 1 ? '<em>Normal</em> in-game time' :
525 'time on <em>Fast</em> game speed' :>
526 <dd>targets <span class="hurt-g">▽</span> ground
527 and/or <span class="hurt-a">△</span> air
529 <dd>maximum hex distance a weapon can fire (note Sieged Tank also has a minimum)
531 <dd>range in which the unit detects other units
532 <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
534 <dd>top movement speed in hex per second
535 <dd>acceleration and deceleration ignored
537 <dd>parentheses () indicate that it needs to be researched first
538 <dd><span class="magic-perma">passive</span> abilities are always enabled
539 <dd>hover for description
540 <dd>range is maximum distance allowed to activate
541 <dd>cost describes energy loss percentage on spawn and when fully charged
545 When two values are given (1-2), the second value indicates the attribute
546 after all possible upgrades.