2 use List::Util qw(max sum);
12 if ($Request and $Request eq '2') {
15 name => 'Heart of the Swarm',
16 title => 'starcraft2',
17 game => 'StarCraft II',
21 my $datafile = "sc-units-$scver{id}.inc.pl";
24 title => "$scver{title} unit cheat sheet",
27 "Reference of $scver{game} unit properties,"
28 . " comparing various statistics of all the units in $scver{name}"
29 . ' including costs, damage, defense, speed, ranges, and abilities.',
33 starcraft game unit statistics stats comparison table sheet cheat
34 reference software attributes properties
36 $scver{major} < 2 ? qw' bw broodwar brood war ' : qw' starcraft2 hots ',
38 stylesheet => [qw'light'],
39 raw => '<link rel="stylesheet" type="text/css" media="all" href="/sc.css?1.1" title="light">',
43 say "<h1>$scver{game} units</h1>\n";
45 my $units = do $datafile;
46 die "Cannot open unit data: $_\n" for $@ || $! || ();
47 my $patch = shift @{$units}
48 or die "Cannot open unit data: metadata not found\n";
50 say "<p>Unit properties as seen or measured in $scver{name}\n$patch.";
51 say "Also see the $_ table." for join(', ',
52 (showlink('StarCraft 2: HotS', '/sc/2')) x ($scver{major} < 2),
53 (showlink('original SC: Brood War', '/sc')) x ($scver{major} > 1),
58 my ($ref, $increase, $org) = @_;
59 if (ref $increase eq 'HASH') {
60 addupgrade(\${$ref}->{$_}, $increase->{$_}, $org->{$_}) for keys %{$increase};
62 elsif (ref $increase eq 'ARRAY') {
63 addupgrade(\${$ref}->[$_], $increase->[$_], $org->[$_]) for 0 .. $#{$increase};
66 ${$ref} += $increase if $increase =~ /^-?[0-9.]+/;
69 for my $unit (@{$units}) {
70 for my $upgrade (@{ $unit->{upgrade} }) {
71 while (my ($col, $increase) = each %{$upgrade}) {
72 defined $unit->{$col} or next;
73 addupgrade(\$unit->{upgraded}->{$col}, $increase, $unit->{$col});
76 for my $special (@{ $unit->{special} }) {
77 for my $upgrade (@{ $special->{upgrade} }) {
78 while (my ($col, $increase) = each %{$upgrade}) {
79 defined $special->{$col} or next;
80 addupgrade(\$special->{upgraded}->{$col}, $increase, $special->{$col});
87 my ($name, $id, $nolink) = @_;
88 return "$name ▼" if defined $get{order} ? $get{order} eq $id : !$id;
89 return $name if $nolink;
90 return showlink($name, '?'.($id && "order=$id"));
92 :><table class="units">
95 <th><:= coltoggle('name', '') :></th>
96 <th class="val min" title=minerals>cost</th>
97 <th class="val gas">gas</th>
98 <th class="val time"><:= coltoggle(qw'build cost') :></th>
99 <th class="unit" colspan="2"><:= coltoggle(qw'size size') :></th>
100 <th class="unit" colspan="2">attr</th>
101 <th class="val unit-hp">HP</th>
102 <th class="val unit-shield">shield</th>
103 <th class="val unit-armor" title="armor">⛨</th>
104 <th class="val hurt">attack</th>
105 <th class="hurt hurtrel"><:= coltoggle(qw'dps attack 1') :></th>
106 <th class="val unit-range" colspan=3>range</th>
107 <th class="val unit-sight">sight</th>
108 <th class="val unit-speed">speed</th>
109 <th class="unit-magic">specials</th>
113 my ($min, $max) = @_;
114 return '' if not defined $min;
115 return $min || '-' if !$max or $min == $max;
120 $_ &&= int($_ + .5) for @_; # round halves up
121 return showrange(@_);
125 my ($row, $unit) = @_;
127 sprintf('cost %s%%', join '-',
128 map { $_ && sprintf '%.0f', 100 * $row->{cost} / $_ } grep { defined $_ }
130 $unit->{upgraded}->{energy},
132 $unit->{upgraded}->{capacity},
134 !defined $row->{maint} ? () : sprintf('+%s%%/s', join '-',
135 map { sprintf '%.1f', 100 * $row->{maint} / $_ } grep $_,
137 $unit->{upgraded}->{capacity},
143 my ($row, $area) = @_;
144 my $attack = $row->{attack}->[$area]
145 or return '<td colspan=5 class="hurt">';
147 my $upattack = $row->{upgraded}->{attack}->[$area];
148 my $damage = $attack->{damage};
149 my $maxdamage = $upattack->{damage} // $damage;
150 $maxdamage += ($upattack->{upgrade} // $attack->{upgrade}) * 3;
152 my $out = '<td class="val hurt">';
153 $out .= sprintf '<span title="%s">¤</span> ', showcost($attack, $row)
155 $out .= sprintf('<small>%s× </small>',
156 showrangeint($attack->{count}, $upattack->{count}),
157 ) if $attack->{count} > 1;
158 $out .= '<span class="unit-l" title="explosive">*</span>'
159 if $attack->{type} eq 'explosive';
160 $out .= '<span class="unit-s" title="implosive">~</span>'
161 if $attack->{type} eq 'implosive';
162 if (my @bonus = sort grep { !/^-/ } keys %{ $attack->{bonus} }) {
163 $out .= sprintf('<span class="%s" title="%s">≥</span>',
165 $_ eq 'light' ? 'unit-s' :
166 $_ eq 'armored' ? 'unit-l' :
167 $_ eq 'organic' ? 'unit-o' :
168 $_ eq 'massive' ? 'unit-h' :
169 $_ eq 'shields' ? 'unit-shield' :
175 $attack->{bonus}->{$_},
176 $attack->{bonus}->{$_} + $attack->{bonus}->{"-$_"} * 3,
183 $out .= '<span class="unit-pdd" title="projectile">•</span>'
184 if $attack->{type} eq 'projectile';
186 $out .= sprintf '<span title="%s">', $attack->{name} if $attack->{name};
187 $out .= showrangeint($damage, $maxdamage);
188 $out .= '</span>' if $attack->{name};
189 $out .= sprintf('<span class="unit-splash" title="%s">%s</span>',
190 $attack->{splash} eq 'line' ? ('linear', '+') : ('splash', '⁜')
191 ) if $attack->{splash};
193 $out .= '<td class="val hurt hurtrel">';
194 if ($attack->{dps}) {
195 # precalculated dps, do not touch
196 $out .= showrangeint($attack->{dps}->[0],
197 $upattack->{dps}->[-1] // $attack->{dps}->[-1]
200 elsif ($attack->{cooldown}) {
201 if (my $type = $attack->{type}) {
202 if ($type eq 'explosive') {
205 elsif ($type eq 'implosive') {
209 $damage *= ($attack->{count} // 1) / $attack->{cooldown};
210 if (my $bonus = $upattack->{bonus} // $attack->{bonus}) {
211 $maxdamage += $_ for max(
212 map { $bonus->{$_} + $bonus->{"-$_"} * 3 }
213 grep { !/^-/ } keys %{$bonus}
216 $maxdamage *= ($upattack->{count} // $attack->{count} // 1)
217 / ($upattack->{cooldown} // $attack->{cooldown});
218 $out .= showrangeint($damage, $maxdamage);
221 $out .= '<td class="unit hurt-g">' . '▽' x !!($attack->{anti} & 1);
222 $out .= '<td class="unit hurt-a">' . '△' x !!($attack->{anti} & 2);
224 $out .= '<td class="val unit-range">' .
225 showrangeint($attack->{range}, $upattack->{range});
232 my $specials = $row->{special} or return '';
233 return join ' ', map {
234 sprintf '<span%s title="%s">%s</span>',
235 $_->{duration} < 0 && ' class="magic-perma"',
238 $_->{desc} ? ": $_->{desc}" : '',
239 (map { $_ && " ($_)" } join ', ',
240 #TODO: apply upgrades
241 $_->{range} ? "range $_->{range}" : (),
242 $_->{cost} ? showcost($_, $row) :
243 $_->{cooldown} ? "cooldown $_->{cooldown}s" : (),
246 sprintf($_->{build} ? '(%s)' : '%s', $_->{abbr}),
247 } grep { defined $_->{abbr} } @{$specials};
253 $_->{hp} += $_->{shield} if $_->{shield};
256 '<td class="val min">' . ($_->{min} // ''),
257 '<td class="val gas">' . ($_->{gas} || ''),
258 !defined $_->{build} ? '<td>' : sprintf('<td class="val time">%s%.0f',
259 !!$_->{base} && '<span class="unit-composed">+</span>',
262 sprintf('<td class="unit unit-%s" title="%4$s%3$s">%s',
263 $_-> {cargo} < 0 ? ('supply', T => 'transport') :
264 $_->{upgraded}->{cargo} < 0 ? ('supply magic-opt', T => 'optional transport') :
265 $_->{attr}->{flying} ? ('air', F => 'flying') :
266 $_->{attr}->{structure} ? ('x', B => 'building') :
268 [qw( x s m l l h h h h )]->[ $_->{cargo} ],
270 $_->{cargo} ? 'transportable' : 'untransportable',
272 defined $_->{size} && sprintf('⌀%.1f ', $_->{size}),
274 sprintf('<td class="val unit%s">%s',
275 defined $_->{pop} && $_->{pop} < 0 && ' unit-supply',
276 defined $_->{pop} && $_->{pop} == .5 ? '½' : $_->{pop},
278 '<td class="unit unit-type">' . join('', grep { $_ }
279 (defined $_->{organic} ? !$_->{organic} : $_->{attr}->{mech})
280 && '<span class="unit-u" title="mechanic">m</span>',
281 ($_->{organic} || $_->{attr}->{organic})
282 && '<span class="unit-o" title="organic">o</span>',
283 $_->{attr}->{psionic}
284 && '<span class="unit-p" title="psionic">ψ</span>',
286 '<td class="unit unit-attr">' . join('', grep { $_ }
287 $_->{attr}->{armored}
288 && '<span class="unit unit-l" title="armored">A</span>',
290 && '<span class="unit unit-s" title="light">L</span>',
291 $_->{suit} && sprintf(
292 '<span class="unit unit-%s" title="%3$s">%s</span>',
300 $_->{attr}->{massive}
301 && '<span class="unit-massive" title="massive">⚓</span>',
303 '<td class="val unit-hp">' . $_->{hp} // '',
304 $_->{shield} ? sprintf('<td class="val unit-shield">%.0f%%<td',
305 100 * $_->{shield} / $_->{hp}
307 ' class="val unit-armor">' .
308 showrangeint($_->{armor}, $_->{upgraded}->{armor}),
310 '<td class="val unit-sight">' . sprintf(
311 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
312 showrangeint($_->{sight}, $_->{upgraded}->{sight})
314 sprintf('<td class="val unit-speed"%2$s>%s',
316 map { $_ && sprintf '%.1f', $_ }
317 $_->{speed}, $_->{upgraded}->{speed}
319 defined $_->{creep} && sprintf(' title="%s on creep"',
320 $_->{creep} == 1 ? 'same' : showrange(
321 map { $_ && sprintf '%.1f', $_ }
322 $_->{speed} * $_->{creep},
323 $_->{upgraded}->{speed} && $_->{upgraded}->{speed} *
324 ($_->{upgraded}->{creep} // $_->{creep}),
329 && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
330 '<td class="unit-magic">' . showmagic($_),
331 !$_->{attack}->[1] ? () : (
332 '<tr><td colspan=12>', showattack($_, 1), '<td colspan=3>'
334 !$_->{attack}->[2] ? () : (
335 '<tr><td colspan=12>', showattack($_, 2), '<td colspan=3>'
341 my $grouped = 1; # race headers
342 if (exists $get{order}) {
345 if ($get{order} eq 'size') {
347 $_->{pop}*16 + ($_->{size} // $_->{suit}) + $_->{cargo}/8
348 + $_->{hp}/512 + $_->{min}/8192
351 elsif ($get{order} eq 'cost') {
353 $_->{gas}*1.5 + $_->{min} + $_->{pop}/8 + $_->{build}/256/8
356 elsif ($get{order} eq 'attack') {
357 $_->{order} = $_->{hp} / 1024 + $_->{shield} / 1008 + max(
359 ($_->{damage} + $_->{upgrade} * 3)
360 * ($_->{count} // 1) / ($_->{cooldown} // 1)
361 * ($_->{splash} ? 1.01 : 1)
362 * ($_->{type} eq 'implosive' ? .96 : 1)
363 * ($_->{type} eq 'explosive' ? .98 : 1)
368 $units->[$_]->{order} = $_ for 0 .. $#$units;
371 my @rows = @{$units};
372 @rows = sort {$a->{order} <=> $b->{order}} @rows unless $grouped;
374 my ($race, $cat) = ('', '');
377 say sprintf '<tbody id="%s"><tr class="race"><th colspan="20"><h2>%s</h2>',
378 $race = $_->{race}, ucfirst $race
379 unless $race eq $_->{race};
382 $_->{cat} = $_->{race};
387 '<th class="cat">', $cat ne $_->{cat} && ($cat = $_->{cat}),
392 for my $subrow (@{ $_->{special} }) {
393 $subrow->{alt} or next;
395 '<tr class="alt"><th class="cat"><td>', $subrow->{alt},
396 showunitcols($subrow),
408 <dd>minerals and gas required to create one unit
409 <dd>includes total expenses if based on existing units
411 <dd>relative time needed to create at least one unit
412 <dd>excludes construction of dependencies such as buildings
413 and <span class="unit-composed">+</span>parent units
415 <dd><span class="unit unit-supply">T</span>ransports can fit upto
416 8 non-<span class="unit unit-air">F</span>lying cargo units
417 <dd>number of command points taken while alive
419 if ($scver{major} > 1) {
420 :>received damage depends on
421 <span class="unit unit-o">o</span>rganic,
422 <span class="unit unit-u">m</span>echanic,
423 <span class="unit unit-p">ψ</span>(ps)ionic,
424 <span class="unit unit-s">L</span>ight, and
425 <span class="unit unit-l">A</span>rmored
427 <dd>massive <span class="unit-massive">⚓</span> units
428 cannot be lifted or slowed and can break force fields<:
430 :>abilities may hit only <span class="unit unit-o">o</span>rganic
431 or <span class="unit unit-u">m</span>echanic targets
432 <dd>affected by <span class="unit unit-s">S</span>mall,
433 <span class="unit unit-m">M</span>edium, or
434 <span class="unit unit-l">L</span>arge damage<:
437 <dd>total number of hitpoints (including shields)
438 <dd>everything zerg (except for eggs) regenerates one point every
439 <:= $scver{major} == 1 ? '4½' : '3.7' :> seconds
441 <dd>percentage of HP in shields
443 if ($scver{major} > 1) {
444 :>shields always take full damage, irrelevant of unit size
447 :>does not take armor bonuses,
448 but upgrades can decrease damage to any shield hit by upto 3
450 if ($scver{major} > 1) {
451 :>after 10 seconds out of combat, 2 points are recharged per game second<:
453 :>recharges one point every 2½ seconds<:
457 <dd>can be increased by upto 3 at various facilities
458 <dd>each point decreases damage per hit by one, upto a minimum of ½
459 <dd>reduction applies to initial damage, before size penalties
460 <small>(so a plasma hit of 12 to 4 armor large deals 2 damage, not ½)</small>
462 <dd>damage per single hit
463 <dd>some weapons fire multiple × times, multiplying armor penalties
464 <dd>splash damage hits all objects nearby <span class="unit-splash">⁜</span>
465 or in a straight line <span class="unit-splash">+</span>.
467 if ($scver{major} > 1) {
468 :>does not include <span>≥</span>bonus damage
469 dealt to susceptible unit types
470 <dd><span class="unit-pdd">•</span>projectile shots are negated by
471 Point Defense Drones<:
473 :><span class="unit-l">*</span>explosive damage does only
474 50% damage to <span class="unit unit-s">S</span>mall units,
475 75% to <span class="unit unit-m">M</span>edium,
476 100% to <span class="unit unit-l">L</span>arge
477 <dd><span class="unit-s">~</span>concussive/plasma damage does
478 25% to <span class="unit unit-l">L</span>arge,
479 50% <span class="unit unit-m">M</span>edium,
480 100% to <span class="unit unit-s">S</span>mall units<:
482 <dd><span class="hurtrel">dps</span> indicates relative total amount of damage
483 done in 1 second of <:= $scver{major} > 1 ? '<em>Normal</em> in-game time' :
484 'time on <em>Fast</em> game speed' :>
485 <dd>targets <span class="hurt-g">▽</span> ground
486 and/or <span class="hurt-a">△</span> air
488 <dd>maximum hex distance a weapon can fire (note Sieged Tank also has a minimum)
490 <dd>range in which the unit detects other units
491 <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
493 <dd>top movement speed in hex per second
494 <dd>acceleration and deceleration ignored
496 <dd>parentheses () indicate that it needs to be researched first
497 <dd><span class="magic-perma">passive</span> abilities are always enabled
498 <dd>hover for description
499 <dd>range is maximum distance allowed to activate
500 <dd>cost describes energy loss percentage on spawn and when fully charged
504 When two values are given (1-2), the second value indicates the attribute
505 after all possible upgrades.