2 use List::Util qw(max sum);
12 if ($ENV{PATH_INFO} and $ENV{PATH_INFO} 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 print "<h1>$scver{game} units</h1>\n\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 print "<p>Unit properties as seen or measured in $scver{name}\n$patch.\n";
51 print "Also see the $_ table.\n" for join(', ',
52 ('<a href="/sc/2">StarCraft 2: HotS</a>') x ($scver{major} < 2),
53 ('<a href="/sc">original SC: Brood War</a>') x ($scver{major} > 1),
58 my ($ref, $increase) = @_;
59 if (ref $increase eq 'HASH') {
60 addupgrade(\${$ref}->{$_}, $increase->{$_}) for keys %{$increase};
62 elsif (ref $increase eq 'ARRAY') {
63 addupgrade(\${$ref}->[$_], $increase->[$_]) for 0 .. $#{$increase};
65 ${$ref} += $increase if $increase =~ /^-?[0-9.]+/;
68 for my $unit (@{$units}) {
69 for my $upgrade (@{ $unit->{upgrade} }) {
70 while (my ($col, $increase) = each %{$upgrade}) {
71 defined $unit->{$col} or next;
72 addupgrade(\( $unit->{upgraded}->{$col} //= $unit->{$col} ), $increase);
78 my ($name, $id, $nolink) = @_;
80 (defined $get{order} ? $get{order} eq $id : !$id) ? '%2$s ▼'
81 : $nolink ? '%2$s' : '<a href="?%s">%s</a>',
82 $id && "order=$id", $name
85 :><table class="units">
88 <th><:= coltoggle('name', '') :></th>
89 <th class="val min"><img src="/minerals.png" alt="min"></th>
90 <th class="val gas"><img src="/gas.png" alt="gas"></th>
91 <th class="val time"><:= coltoggle(qw'build cost') :></th>
92 <th class="unit" colspan="4"><:= coltoggle(qw'size size') :></th>
93 <th class="val unit-hp">HP</th>
94 <th class="val unit-shield">shield</th>
95 <th class="val unit-armor" title="armor">⛨</th>
96 <th class="val hurt" colspan=3>attack</th>
97 <th class="hurt hurtrel"><:= coltoggle(qw'dps attack 1') :></th>
98 <th class="val unit-range">range</th>
99 <th class="val unit-sight">sight</th>
100 <th class="val unit-speed">speed</th>
101 <th class="unit-magic">specials</th>
105 my ($min, $max) = @_;
106 return '' if not defined $min;
107 $_ &&= int($_ + .5) for $min, $max; # round halves up
108 return $min if not defined $max or $min == $max;
113 my ($row, $area) = @_;
114 my $attack = $row->{attack}->[$area]
115 or return '<td colspan=4 class="hurt">';
118 $out .= '<td class="unit hurt-g">' . '▽' x !!($attack->{anti} & 1);
119 $out .= '<td class="unit hurt-a">' . '△' x !!($attack->{anti} & 2);
120 $out .= '<td class="val hurt">';
122 my $upattack = $row->{upgraded}->{attack}->[$area];
123 my $damage = $attack->{damage};
124 my $maxdamage = $upattack->{damage} // $damage;
125 $damage = $damage->[0] if ref $damage;
126 $maxdamage = $maxdamage->[-1] if ref $maxdamage;
128 $out .= "<small>$attack->{count}× </small>" if $attack->{count} > 1;
129 $out .= '<span class="unit-l" title="explosive">*</span>'
130 if $attack->{type} eq 'explosive';
131 $out .= '<span class="unit-s" title="implosive">~</span>'
132 if $attack->{type} eq 'implosive';
133 $out .= sprintf('<span class="%s" title="%s">≥</span>',
135 $_ =~ /^light/ ? 'unit-s' :
136 $_ eq 'armored' ? 'unit-l' :
137 $_ eq 'organic' ? 'unit-o' :
138 $_ =~ /^massive/ ? 'unit-h' :
139 $_ eq 'shields' ? 'unit-shield' :
141 } join '_', keys %{ $attack->{bonus} }),
145 ref $_ ? showrange($_->[0], $_->[-1]) : $_
146 } $attack->{bonus}->{$_}),
149 )} keys %{ $attack->{bonus} }),
150 ) if $attack->{bonus};
151 $out .= showrange($damage, $maxdamage);
152 $out .= sprintf('<span class="unit-splash" title="%s">%s</span>',
153 $attack->{splash} eq 'line' ? ('linear', '×') : ('splash', '+')
154 ) if $attack->{splash};
156 $out .= '<td class="val hurt hurtrel">';
157 if ($attack->{cooldown}) {
158 if (my $type = $attack->{type}) {
159 if ($type eq 'explosive') {
162 elsif ($type eq 'implosive') {
166 $damage *= ($attack->{count} // 1) / $attack->{cooldown};
167 if (my $bonus = $upattack->{bonus} // $attack->{bonus}) {
168 $maxdamage += $_ for max(
169 map { ref $_ ? $_->[-1] : $_ } values %{$bonus}
172 $maxdamage *= ($upattack->{count} // $attack->{count} // 1)
173 / ($upattack->{cooldown} // $attack->{cooldown});
174 $out .= showrange($damage, $maxdamage);
182 my $specials = $row->{special} or return '';
183 return join ' ', map {
184 sprintf '<span%s title="%s">%s</span>',
185 $_->{duration} < 0 && ' class="magic-perma"',
188 $_->{desc} ? ": $_->{desc}" : '',
189 $_->{range} || $_->{cost} ? sprintf(' (%s)', join ', ',
190 $_->{range} ? "range $_->{range}" : (),
191 $_->{cost} ? sprintf('cost %.0f%%%s',
192 100 * $_->{cost} / $row->{energy},
193 defined $_->{maint} && sprintf('+%.1f%%/s',
194 100 * $_->{maint} / $row->{energy},
199 sprintf($_->{build} ? '(%s)' : '%s', $_->{abbr}),
200 } grep { defined $_->{abbr} } @{$specials};
206 $_->{hp} += $_->{shield} if $_->{shield};
208 if ($_->{attr}->{structure}) {
212 $suitchar = [qw/? s m l/]->[$_->{suit}];
214 elsif ($_->{cargo} > 0) {
215 $suitchar = [qw/? s m l l h h h h/]->[abs $_->{cargo}];
218 $suitchar = [qw/s m l h h h/]->[$_->{size}];
220 elsif ($_->{attr} and $_->{attr}->{light}) {
223 elsif ($_->{attr} and $_->{attr}->{armored}) {
228 '<td class="val min">' . ($_->{min} // ''),
229 '<td class="val gas">' . ($_->{gas} || ''),
230 !defined $_->{build} ? '<td>' : sprintf('<td class="val time">%s%.0f',
231 !!$_->{base} && '<span class="unit-composed">+</span>',
234 !$suitchar ? '<td>' : sprintf('<td class="unit unit-%s">%s%s',
235 $suitchar, ucfirst $suitchar,
236 $_->{attr}->{massive}
237 && '<span class="unit-massive" title="massive">⚓</span>',
239 '<td class="val unit">' . (
240 defined $_->{unit} && $_->{unit} == .5 ? '½' : $_->{unit}
242 '<td class="unit unit-type">' . join('', grep { $_ }
243 (defined $_->{organic} ? !$_->{organic} : $_->{attr}->{mech})
244 && '<span class="unit-u" title="mechanic">m</span>',
245 ($_->{organic} || $_->{attr}->{organic})
246 && '<span class="unit-o" title="organic">o</span>',
247 $_->{attr}->{psionic}
248 && '<span class="unit-p" title="psionic">ψ</span>',
250 '<td class="unit unit-attr">' . join('', grep { $_ }
251 $_->{attr}->{armored}
252 && '<span class="unit unit-l" title="armored">A</span>',
254 && '<span class="unit unit-s" title="light">L</span>',
256 '<td class="val unit-hp">' . $_->{hp} // '',
257 $_->{shield} ? sprintf('<td class="val unit-shield">%.0f%%<td',
258 100 * $_->{shield} / $_->{hp}
260 ' class="val unit-armor">' .
261 showrange($_->{armor}, $_->{upgraded}->{armor}),
263 '<td class="val unit-range">' .
264 showrange(map { $_->{attack}->[0]->{range} } $_, $_->{upgraded}),
265 '<td class="val unit-sight">' . sprintf(
266 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
267 showrange($_->{sight}, $_->{upgraded}->{sight})
269 '<td class="val unit-speed">' .
270 showrange($_->{speed}, $_->{upgraded}->{speed}),
272 && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
274 && qq'<span class="unit unit-jump" title="flying">↑</span>',
275 '<td class="unit-magic">' . showmagic($_),
276 !$_->{attack}->[1] ? () : (
277 '<tr><td colspan=12>', showattack($_, 1), '<td colspan=4>'
283 my $grouped = 1; # race headers
284 if (exists $get{order}) {
287 if ($get{order} eq 'size') {
289 $_->{unit}*16 + ($_->{size} // $_->{suit}) + $_->{cargo}/8
290 + $_->{hp}/512 + $_->{min}/8192
293 elsif ($get{order} eq 'cost') {
295 $_->{gas}*1.5 + $_->{min} + $_->{unit}/8 + $_->{build}/256/8
298 elsif ($get{order} eq 'attack') {
299 $_->{order} = $_->{hp} / 1024 + $_->{shield} / 1008 + max(
301 ((map { ref $_ ? $_->[-1] : $_ } $_->{damage})[0])
302 * ($_->{count} // 1) / ($_->{cooldown} // 1)
303 * ($_->{splash} ? 1.01 : 1)
304 * ($_->{type} eq 'implosive' ? .96 : 1)
305 * ($_->{type} eq 'explosive' ? .98 : 1)
310 $units->[$_]->{order} = $_ for 0 .. $#$units;
313 my @rows = @{$units};
314 @rows = sort {$a->{order} <=> $b->{order}} @rows unless $grouped;
316 my ($race, $cat) = ('', '');
319 printf '<tbody id="%s"><tr class="race"><th colspan="20"><h2>%s</h2>'."\n",
320 $race = $_->{race}, ucfirst $race
321 unless $race eq $_->{race};
324 $_->{cat} = $_->{race};
329 '<th class="cat">', $cat ne $_->{cat} && ($cat = $_->{cat}),
334 for my $subrow (@{ $_->{special} }) {
335 $subrow->{alt} or next;
337 '<tr class="alt"><th class="cat"><td>', $subrow->{alt},
338 showunitcols($subrow),
350 <dd>minerals+gas required to create one unit
351 <dd>includes total expenses if based on existing units
353 <dd>relative time needed to create at least one unit
354 <dd>excludes construction of dependencies such as buildings
355 and <span class="unit-composed">+</span>parent units
358 if ($scver{major} > 1) {
359 :>transports can fit 8 <span class="unit unit-s">S</span>mall,
360 4 <span class="unit unit-m">M</span>edium,
361 2 <span class="unit unit-l">L</span>arge,
362 or a single <span class="unit unit-h">H</span>uge unit
363 <dd>massive <span class="unit-massive">⚓</span> units
364 cannot be lifted or slowed and can break force fields<:
366 :>affected by <span class="unit unit-s">S</span>mall,
367 <span class="unit unit-m">M</span>edium, or
368 <span class="unit unit-l">L</span>arge unit damage<:
370 <dd>number of command points taken per unit
372 if ($scver{major} > 1) {
373 :>received damage depends on
374 <span class="unit unit-o">o</span>rganic,
375 <span class="unit unit-u">m</span>echanic,
376 <span class="unit unit-p">ψ</span>(ps)ionic,
377 <span class="unit unit-s">L</span>ight, and
378 <span class="unit unit-l">A</span>rmored
381 :><span class="unit unit-o">o</span>rganic/<span class="unit unit-u">m</span>echanic unit<:
384 total number of hitpoints (including shields)
386 <dd>percentage of HP in shields
387 <dd>shields always take full damage, irrelevant of unit size
388 <dd>does not take armor bonuses, but upgrades can decrease damage to any shield hit by upto 3
391 <dd>can be increased by upto 3 at various facilities
392 <dd>each point decreases damage per hit by one, upto a minimum of ½
393 <dd>reduction applies to initial damage, before size penalties
394 <small>(so a plasma hit of 12 to 4 armor large deals 2 damage, not ½)</small>
396 <dd>targets <span class="hurt-g">▽</span> ground
397 and/or <span class="hurt-a">△</span> air
398 <dd>damage given per single hit
399 <dd><span class="hurtrel">dps</span> indicates relative amount of damage
400 done in 1 second of in-game time
401 <dd>splash damage hits all objects nearby <span class="unit-splash">+</span>
402 or in a straight line <span class="unit-splash">×</span>.
404 if ($scver{major} > 1) {
405 :>does not include <span>≥</span>bonus damage
406 dealt to susceptible unit types<:
408 :><span class="unit-l">*</span>explosive damage does only
409 50% damage to small units, 75% to medium, 100% to large
410 <dd><span class="unit-s">~</span>concussive/plasma damage does
411 25% to large, 50% medium, 100% to small units<:
414 <dd>range in which the unit detects other units
415 <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
417 <dd>maximum range of weapon (note siege tank also has a minimum range)
419 <dd>relative speed of movement (when in full motion, startup speed ignored)
421 <dd>special abilities are usually casted manually, but some are <span class="magic-perma">always active</span>
422 <dd>parentheses () indicate that it needs to be researched first
423 <dd>hover for description
424 <dd>range is maximum range required to activate
425 <dd>cost is percentage of total energy lost
429 When two values are given (1-2), second value indicates attribute after all