2 use List::Util qw(max sum);
12 name => 'Heart of the Swarm',
13 title => 'starcraft2',
14 game => 'StarCraft II',
20 $Request = 'hots' if $Request eq '2';
21 my %scver = %{ $scvers{$Request} }
22 or Abort("Requested version $Request not available", '404 unknown');
24 my $datafile = "sc-units-$Request.inc.pl";
27 title => "$scver{title} unit cheat sheet",
30 "Reference of $scver{game} unit properties,"
31 . " comparing various statistics of all the units in $scver{name}"
32 . ' including costs, damage, defense, speed, ranges, and abilities.',
36 starcraft game unit statistics stats comparison table sheet cheat
37 reference software attributes properties patch attribute multiplayer
39 $scver{major} < 2 ? qw' bw broodwar brood war ' : qw' starcraft2 hots ',
41 stylesheet => [qw'light'],
42 raw => '<link rel="stylesheet" type="text/css" media="all" href="/sc.css?1.1" title="light">',
46 say "<h1>$scver{game} units</h1>\n";
48 my $units = do $datafile;
49 Abort("Cannot open unit data", 501, $_) for $@ || $! || ();
50 my $patch = shift @{$units}
51 or Abort("Cannot open unit data: metadata not found", 501);
53 say "<p>Unit properties as seen or measured in $scver{name}\n$patch.";
54 say "Also see the $_ table." for join(', ',
55 (showlink('StarCraft 2: HotS', '/sc/hots')) x ($Request ne 'hots'),
56 (showlink('original SC: Brood War', '/sc/bw')) x ($Request ne 'bw'),
61 my ($ref, $increase, $org) = @_;
62 if (ref $increase eq 'HASH') {
63 addupgrade(\${$ref}->{$_}, $increase->{$_}, $org->{$_}) for keys %{$increase};
65 elsif (ref $increase eq 'ARRAY') {
66 addupgrade(\${$ref}->[$_], $increase->[$_], $org->[$_]) for 0 .. $#{$increase};
69 ${$ref} += $increase if $increase =~ /^-?[0-9.]+/;
72 for my $unit (@{$units}) {
73 for my $upgrade (@{ $unit->{upgrade} }) {
74 while (my ($col, $increase) = each %{$upgrade}) {
75 defined $unit->{$col} or next;
76 addupgrade(\$unit->{upgraded}->{$col}, $increase, $unit->{$col});
79 for my $special (@{ $unit->{special} }) {
80 for my $upgrade (@{ $special->{upgrade} }) {
81 while (my ($col, $increase) = each %{$upgrade}) {
82 defined $special->{$col} or next;
83 addupgrade(\$special->{upgraded}->{$col}, $increase, $special->{$col});
90 my ($name, $id, $nolink) = @_;
91 return "$name ▼" if defined $get{order} ? $get{order} eq $id : !$id;
92 return $name if $nolink;
93 return showlink($name, '?'.($id && "order=$id"));
95 :><table class="units">
97 <th><:= coltoggle(exists $get{order} ? 'race' : 'source' => '') :></th>
98 <th><:= coltoggle(name => 'name') :></th>
99 <th class="val min" title=minerals><:= coltoggle(cost => 'cost') :></th>
100 <th class="val gas">gas</th>
101 <th class="val time"><:= coltoggle(build => 'build') :></th>
102 <th class="unit" colspan="2"><:= coltoggle(qw'size size') :></th>
103 <th class="unit" colspan="2">attr</th>
104 <th class="val unit-hp"><:= coltoggle(HP => 'hp') :></th>
105 <th class="val unit-shield">shield</th>
106 <th class="val unit-armor" title="armor">⛨</th>
107 <th class="val hurt"><:= coltoggle(attack => 'attack') :></th>
108 <th class="hurt hurtrel">dps</th>
109 <th class="val unit-range" colspan=3>range</th>
110 <th class="val unit-sight">sight</th>
111 <th class="val unit-speed"><:= coltoggle(speed => 'speed') :></th>
112 <th class="unit-magic">specials</th>
116 my ($min, $max) = @_;
117 return '' if not defined $min;
118 return $min || '-' if !$max or $min == $max;
123 $_ &&= int($_ + .5) for @_; # round halves up
124 return showrange(@_);
128 my ($row, $unit) = @_;
130 sprintf('cost %s%%', join '-',
131 map { $_ && sprintf '%.0f', 100 * $row->{cost} / $_ } grep { defined $_ }
133 $unit->{upgraded}->{energy},
135 $unit->{upgraded}->{capacity},
137 !defined $row->{maint} ? () : sprintf('+%s%%/s', join '-',
138 map { sprintf '%.1f', 100 * $row->{maint} / $_ } grep $_,
140 $unit->{upgraded}->{capacity},
146 my ($row, $area) = @_;
147 my $attack = $row->{attack}->[$area]
148 or return '<td colspan=5 class="hurt">';
150 my $upattack = $row->{upgraded}->{attack}->[$area];
151 my $damage = $attack->{damage};
152 my $maxdamage = $upattack->{damage} // $damage;
153 $maxdamage += ($upattack->{upgrade} // $attack->{upgrade}) * 3;
155 my $out = '<td class="val hurt">';
156 $out .= sprintf '<span title="%s">¤</span> ', showcost($attack, $row)
158 $out .= sprintf('<small>%s× </small>',
159 showrangeint($attack->{count}, $upattack->{count}),
160 ) if $attack->{count} > 1;
161 $out .= '<span class="unit-l" title="explosive">*</span>'
162 if $attack->{type} eq 'explosive';
163 $out .= '<span class="unit-s" title="implosive">~</span>'
164 if $attack->{type} eq 'implosive';
165 if (my @bonus = sort grep { !/^-/ } keys %{ $attack->{bonus} }) {
166 $out .= sprintf('<span class="%s" title="%s">≥</span>',
168 $_ eq 'light' ? 'unit-s' :
169 $_ eq 'armored' ? 'unit-l' :
170 $_ eq 'organic' ? 'unit-o' :
171 $_ eq 'massive' ? 'unit-h' :
172 $_ eq 'shields' ? 'unit-shield' :
178 $attack->{bonus}->{$_},
179 $attack->{bonus}->{$_} + $attack->{bonus}->{"-$_"} * 3,
186 $out .= '<span class="unit-pdd" title="projectile">•</span>'
187 if $attack->{type} eq 'projectile';
189 $out .= sprintf '<span title="%s">', $attack->{name} if $attack->{name};
190 $out .= showrangeint($damage, $maxdamage);
191 $out .= '</span>' if $attack->{name};
192 $out .= sprintf('<span class="unit-splash" title="%s">%s</span>',
193 $attack->{splash} eq 'line' ? ('linear', '+') : ('splash', '⁜')
194 ) if $attack->{splash};
196 $out .= '<td class="val hurt hurtrel">';
197 if ($attack->{dps}) {
198 # precalculated dps, do not touch
199 $out .= showrangeint($attack->{dps}->[0],
200 $upattack->{dps}->[-1] // $attack->{dps}->[-1]
203 elsif ($attack->{cooldown}) {
204 if (my $type = $attack->{type}) {
205 if ($type eq 'explosive') {
208 elsif ($type eq 'implosive') {
212 $damage *= ($attack->{count} // 1) / $attack->{cooldown};
213 if (my $bonus = $upattack->{bonus} // $attack->{bonus}) {
214 $maxdamage += $_ for max(
215 map { $bonus->{$_} + $bonus->{"-$_"} * 3 }
216 grep { !/^-/ } keys %{$bonus}
219 $maxdamage *= ($upattack->{count} // $attack->{count} // 1)
220 / ($upattack->{cooldown} // $attack->{cooldown});
221 $out .= showrangeint($damage, $maxdamage);
224 $out .= '<td class="unit hurt-g">' . '▽' x !!($attack->{anti} & 1);
225 $out .= '<td class="unit hurt-a">' . '△' x !!($attack->{anti} & 2);
227 $out .= '<td class="val unit-range">' .
228 showrangeint($attack->{range}, $upattack->{range});
235 my $specials = $row->{special} or return '';
236 return join ' ', map {
237 sprintf '<span%s title="%s">%s</span>',
238 $_->{duration} < 0 && ' class="magic-perma"',
241 $_->{desc} ? ": $_->{desc}" : '',
242 (map { $_ && " ($_)" } join ', ',
243 #TODO: apply upgrades
244 $_->{range} ? "range $_->{range}" : (),
245 $_->{cost} ? showcost($_, $row) :
246 $_->{cooldown} ? "cooldown $_->{cooldown}s" : (),
249 sprintf($_->{build} ? '(%s)' : '%s', $_->{abbr}),
250 } grep { defined $_->{abbr} } @{$specials};
256 $_->{hp} += $_->{shield} if $_->{shield};
259 '<td class="val min">' . ($_->{min} // ''),
260 '<td class="val gas">' . ($_->{gas} || ''),
261 !defined $_->{build} ? '<td>' : sprintf('<td class="val time"%s>%s%.0f',
262 defined $_->{warp} && qq(title="$_->{build} without warpgate"),
263 !!$_->{base} && sprintf(
264 '<span class="unit-composed" title="%s">+</span>',
265 'from '.join('+', @{ $_->{base} }),
267 $_->{warp} // $_->{build} || '0',
269 sprintf('<td class="unit unit-%s" title="%4$s%3$s">%s',
270 $_-> {cargo} < 0 ? ('supply', T => 'transport') :
271 $_->{upgraded}->{cargo} < 0 ? ('supply magic-opt', T => 'optional transport') :
272 $_->{attr}->{flying} ? ('air', F => 'flying') :
273 $_->{attr}->{structure} ? ('x', B => 'building') :
275 [qw( x s m l l h h h h )]->[ $_->{cargo} ],
277 $_->{cargo} ? 'transportable' : 'untransportable',
279 defined $_->{size} && sprintf('⌀%.1f ', $_->{size}),
281 sprintf('<td class="val unit%s">%s',
282 defined $_->{pop} && $_->{pop} < 0 && ' unit-supply',
283 defined $_->{pop} && $_->{pop} == .5 ? '½' : $_->{pop},
285 '<td class="unit unit-type">' . join('', grep { $_ }
286 (defined $_->{organic} ? !$_->{organic} : $_->{attr}->{mech})
287 && '<span class="unit-u" title="mechanic">m</span>',
288 ($_->{organic} || $_->{attr}->{organic})
289 && '<span class="unit-o" title="organic">o</span>',
290 $_->{attr}->{psionic}
291 && '<span class="unit-p" title="psionic">ψ</span>',
293 '<td class="unit unit-attr">' . join('', grep { $_ }
294 $_->{attr}->{armored}
295 && '<span class="unit unit-l" title="armored">A</span>',
297 && '<span class="unit unit-s" title="light">L</span>',
298 $_->{suit} && sprintf(
299 '<span class="unit unit-%s" title="%3$s">%s</span>',
307 $_->{attr}->{massive}
308 && '<span class="unit-massive" title="massive">⚓</span>',
310 '<td class="val unit-hp">' . $_->{hp} // '',
311 $_->{shield} ? sprintf('<td class="val unit-shield">%.0f%%<td',
312 100 * $_->{shield} / $_->{hp}
314 ' class="val unit-armor">' .
315 showrangeint($_->{armor}, $_->{upgraded}->{armor}),
317 '<td class="val unit-sight">' . sprintf(
318 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
319 showrangeint($_->{sight}, $_->{upgraded}->{sight})
321 sprintf('<td class="val unit-speed"%2$s>%s',
323 map { $_ && sprintf '%.1f', $_ }
324 $_->{speed}, $_->{upgraded}->{speed}
326 defined $_->{creep} && sprintf(' title="%s on creep"',
327 $_->{creep} == 1 ? 'same' : showrange(
328 map { $_ && sprintf '%.1f', $_ }
329 $_->{speed} * $_->{creep},
330 $_->{upgraded}->{speed} && $_->{upgraded}->{speed} *
331 ($_->{upgraded}->{creep} // $_->{creep}),
336 && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
337 '<td class="unit-magic">' . showmagic($_),
338 !$_->{attack}->[1] ? () : (
339 '<tr><td colspan=12>', showattack($_, 1), '<td colspan=3>'
341 !$_->{attack}->[2] ? () : (
342 '<tr><td colspan=12>', showattack($_, 2), '<td colspan=3>'
348 my @rows = @{$units};
349 my $grouped = 1; # race headers
350 if (exists $get{order}) {
353 if ($get{order} eq 'name') {
354 @rows = sort {$a->{name} cmp $b->{name}} @rows;
356 elsif ($get{order} eq 'hp') {
358 $_->{hp}*1.01 + $_->{armor} + $_->{shield} + $_->{size}/1024,
361 elsif ($get{order} eq 'cost') {
363 $_->{gas}*1.5 + $_->{min} + $_->{pop}/8 + $_->{build}/256/8
366 elsif ($get{order} eq 'build') {
367 my %unittime = map { ($_->{name} => $_->{warp} // $_->{build}) } @rows;
368 $unittime{Templar} = $unittime{'High Templar'};
370 ($_->{warp} // $_->{build})
371 + ($_->{gas}*1.5 + $_->{min} + $_->{pop}/8)/1024
372 + ($_->{base} ? ($unittime{$_->{base}->[0]} // 100) + 1 : 0)
375 elsif ($get{order} eq 'size') {
377 $_->{pop}*16 + ($_->{size} // $_->{suit}) + $_->{cargo}/8
378 + $_->{hp}/512 + $_->{min}/8192
381 elsif ($get{order} eq 'attack') {
382 $_->{order} = $_->{hp} / 1024 + $_->{shield} / 1008 + max(
384 ($_->{dps} ? $_->{dps}->[-1] :
385 ($_->{damage} + $_->{upgrade} * 3)
386 * ($_->{count} // 1) / ($_->{cooldown} // 1)
388 * ($_->{splash} ? 1.01 : 1)
389 * ($_->{type} eq 'implosive' ? .96 : 1)
390 * ($_->{type} eq 'explosive' ? .98 : 1)
394 elsif ($get{order} eq 'speed') {
396 ($_->{upgraded}->{speed} // $_->{speed}*1.01)
397 + $_->{sight}/1024 + $_->{detect}/2048
400 @rows = sort {$a->{order} <=> $b->{order}} @rows if exists $rows[0]->{order};
403 my ($race, $cat) = ('', '');
406 say sprintf '<tbody id="%s"><tr class="race"><th colspan="20"><h2>%s</h2>',
407 $race = $_->{race}, ucfirst $race
408 unless $race eq $_->{race};
411 $_->{cat} = $_->{race};
416 '<th class="cat">', $cat ne $_->{cat} && ($cat = $_->{cat}),
421 for my $subrow (@{ $_->{special} }) {
422 $subrow->{alt} or next;
424 '<tr class="alt"><th class="cat"><td>', $subrow->{alt},
425 showunitcols($subrow),
437 <dd>minerals and gas required to create one unit
438 <dd>includes total expenses if based on existing units
440 <dd>relative time needed to create at least one unit
441 <dd>excludes construction of dependencies such as buildings
442 and <span class="unit-composed">+</span>parent units
444 <dd><span class="unit unit-supply">T</span>ransports can fit upto
445 8 non-<span class="unit unit-air">F</span>lying cargo units
446 <dd>number of command points taken while alive
448 if ($scver{major} > 1) {
449 :>received damage depends on
450 <span class="unit unit-o">o</span>rganic,
451 <span class="unit unit-u">m</span>echanic,
452 <span class="unit unit-p">ψ</span>(ps)ionic,
453 <span class="unit unit-s">L</span>ight, and
454 <span class="unit unit-l">A</span>rmored
456 <dd>massive <span class="unit-massive">⚓</span> units
457 cannot be lifted or slowed and can break force fields<:
459 :>abilities may hit only <span class="unit unit-o">o</span>rganic
460 or <span class="unit unit-u">m</span>echanic targets
461 <dd>affected by <span class="unit unit-s">S</span>mall,
462 <span class="unit unit-m">M</span>edium, or
463 <span class="unit unit-l">L</span>arge damage<:
466 <dd>total number of hitpoints (including shields)
467 <dd>everything zerg (except for eggs) regenerates one point every
468 <:= $scver{major} == 1 ? '4½' : '3.7' :> seconds
470 <dd>percentage of HP in shields
472 if ($scver{major} > 1) {
473 :>shields always take full damage, irrelevant of unit size
476 :>does not take armor bonuses,
477 but upgrades can decrease damage to any shield hit by upto 3
479 if ($scver{major} > 1) {
480 :>after 10 seconds out of combat, 2 points are recharged per game second<:
482 :>recharges one point every 2½ seconds<:
486 <dd>can be increased by upto 3 at various facilities
487 <dd>each point decreases damage per hit by one, upto a minimum of ½
488 <dd>reduction applies to initial damage, before size penalties
489 <small>(so a plasma hit of 12 to 4 armor large deals 2 damage, not ½)</small>
491 <dd>damage per single hit
492 <dd>some weapons fire multiple × times, multiplying armor penalties
493 <dd>splash damage hits all objects nearby <span class="unit-splash">⁜</span>
494 or in a straight line <span class="unit-splash">+</span>.
496 if ($scver{major} > 1) {
497 :>does not include <span>≥</span>bonus damage
498 dealt to susceptible unit types
499 <dd><span class="unit-pdd">•</span>projectile shots are negated by
500 Point Defense Drones<:
502 :><span class="unit-l">*</span>explosive damage does only
503 50% damage to <span class="unit unit-s">S</span>mall units,
504 75% to <span class="unit unit-m">M</span>edium,
505 100% to <span class="unit unit-l">L</span>arge
506 <dd><span class="unit-s">~</span>concussive/plasma damage does
507 25% to <span class="unit unit-l">L</span>arge,
508 50% <span class="unit unit-m">M</span>edium,
509 100% to <span class="unit unit-s">S</span>mall units<:
511 <dd><span class="hurtrel">dps</span> indicates relative total amount of damage
512 done in 1 second of <:= $scver{major} > 1 ? '<em>Normal</em> in-game time' :
513 'time on <em>Fast</em> game speed' :>
514 <dd>targets <span class="hurt-g">▽</span> ground
515 and/or <span class="hurt-a">△</span> air
517 <dd>maximum hex distance a weapon can fire (note Sieged Tank also has a minimum)
519 <dd>range in which the unit detects other units
520 <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
522 <dd>top movement speed in hex per second
523 <dd>acceleration and deceleration ignored
525 <dd>parentheses () indicate that it needs to be researched first
526 <dd><span class="magic-perma">passive</span> abilities are always enabled
527 <dd>hover for description
528 <dd>range is maximum distance allowed to activate
529 <dd>cost describes energy loss percentage on spawn and when fully charged
533 When two values are given (1-2), the second value indicates the attribute
534 after all possible upgrades.