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, $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) = @_;
89 (defined $get{order} ? $get{order} eq $id : !$id) ? '%2$s ▼'
90 : $nolink ? '%2$s' : '<a href="?%s">%s</a>',
91 $id && "order=$id", $name
94 :><table class="units">
97 <th><:= coltoggle('name', '') :></th>
98 <th class="val min" title=minerals>cost</th>
99 <th class="val gas">gas</th>
100 <th class="val time"><:= coltoggle(qw'build cost') :></th>
101 <th class="unit" colspan="2"><:= coltoggle(qw'size size') :></th>
102 <th class="unit" colspan="2">attr</th>
103 <th class="val unit-hp">HP</th>
104 <th class="val unit-shield">shield</th>
105 <th class="val unit-armor" title="armor">⛨</th>
106 <th class="val hurt">attack</th>
107 <th class="hurt hurtrel"><:= coltoggle(qw'dps attack 1') :></th>
108 <th class="val unit-range" colspan=3>range</th>
109 <th class="val unit-sight">sight</th>
110 <th class="val unit-speed">speed</th>
111 <th class="unit-magic">specials</th>
115 my ($min, $max) = @_;
116 return '' if not defined $min;
117 $_ &&= int($_ + .5) for $min, $max; # round halves up
118 return $min || '-' if not defined $max or $min == $max;
123 my ($row, $area) = @_;
124 my $attack = $row->{attack}->[$area]
125 or return '<td colspan=5 class="hurt">';
127 my $upattack = $row->{upgraded}->{attack}->[$area];
128 my $damage = $attack->{damage};
129 my $maxdamage = $upattack->{damage} // $damage;
130 $maxdamage += ($upattack->{upgrade} // $attack->{upgrade}) * 3;
132 my $out = '<td class="val hurt">';
133 $out .= sprintf '<span title="%s">¤</span> ', showcost($attack, $row)
135 $out .= sprintf('<small>%s× </small>',
136 showrange($attack->{count}, $upattack->{count}),
137 ) if $attack->{count} > 1;
138 $out .= '<span class="unit-l" title="explosive">*</span>'
139 if $attack->{type} eq 'explosive';
140 $out .= '<span class="unit-s" title="implosive">~</span>'
141 if $attack->{type} eq 'implosive';
142 if (my @bonus = sort grep { !/^-/ } keys %{ $attack->{bonus} }) {
143 $out .= sprintf('<span class="%s" title="%s">≥</span>',
145 $_ eq 'light' ? 'unit-s' :
146 $_ eq 'armored' ? 'unit-l' :
147 $_ eq 'organic' ? 'unit-o' :
148 $_ eq 'massive' ? 'unit-h' :
149 $_ eq 'shields' ? 'unit-shield' :
155 $attack->{bonus}->{$_},
156 $attack->{bonus}->{$_} + $attack->{bonus}->{"-$_"} * 3,
163 $out .= '<span class="unit-pdd" title="projectile">•</span>'
164 if $attack->{type} eq 'projectile';
166 $out .= sprintf '<span title="%s">', $attack->{name} if $attack->{name};
167 $out .= showrange($damage, $maxdamage);
168 $out .= '</span>' if $attack->{name};
169 $out .= sprintf('<span class="unit-splash" title="%s">%s</span>',
170 $attack->{splash} eq 'line' ? ('linear', '+') : ('splash', '⁜')
171 ) if $attack->{splash};
173 $out .= '<td class="val hurt hurtrel">';
174 if ($attack->{dps}) {
175 # precalculated dps, do not touch
176 $out .= showrange($attack->{dps}->[0],
177 $upattack->{dps}->[-1] // $attack->{dps}->[-1]
180 elsif ($attack->{cooldown}) {
181 if (my $type = $attack->{type}) {
182 if ($type eq 'explosive') {
185 elsif ($type eq 'implosive') {
189 $damage *= ($attack->{count} // 1) / $attack->{cooldown};
190 if (my $bonus = $upattack->{bonus} // $attack->{bonus}) {
191 $maxdamage += $_ for max(
192 map { $bonus->{$_} + $bonus->{"-$_"} * 3 }
193 grep { !/^-/ } keys %{$bonus}
196 $maxdamage *= ($upattack->{count} // $attack->{count} // 1)
197 / ($upattack->{cooldown} // $attack->{cooldown});
198 $out .= showrange($damage, $maxdamage);
201 $out .= '<td class="unit hurt-g">' . '▽' x !!($attack->{anti} & 1);
202 $out .= '<td class="unit hurt-a">' . '△' x !!($attack->{anti} & 2);
204 $out .= '<td class="val unit-range">' .
205 showrange($attack->{range}, $upattack->{range});
212 my $specials = $row->{special} or return '';
213 return join ' ', map {
214 sprintf '<span%s title="%s">%s</span>',
215 $_->{duration} < 0 && ' class="magic-perma"',
218 $_->{desc} ? ": $_->{desc}" : '',
219 (map { $_ && " ($_)" } join ', ',
220 #TODO: apply upgrades
221 $_->{range} ? "range $_->{range}" : (),
222 $_->{cost} ? sprintf('cost %.0f%%%s',
223 100 * $_->{cost} / $row->{energy},
224 defined $_->{maint} && sprintf('+%.1f%%/s',
225 100 * $_->{maint} / $row->{energy},
228 $_->{cooldown} ? "cooldown $_->{cooldown}s" : (),
231 sprintf($_->{build} ? '(%s)' : '%s', $_->{abbr}),
232 } grep { defined $_->{abbr} } @{$specials};
238 $_->{hp} += $_->{shield} if $_->{shield};
241 '<td class="val min">' . ($_->{min} // ''),
242 '<td class="val gas">' . ($_->{gas} || ''),
243 !defined $_->{build} ? '<td>' : sprintf('<td class="val time">%s%.0f',
244 !!$_->{base} && '<span class="unit-composed">+</span>',
247 sprintf('<td class="unit unit-%s" title="%4$s%3$s">%s',
248 $_-> {cargo} < 0 ? ('supply', T => 'transport') :
249 $_->{upgraded}->{cargo} < 0 ? ('supply magic-opt', T => 'optional transport') :
250 $_->{attr}->{flying} ? ('air', F => 'flying') :
251 $_->{attr}->{structure} ? ('x', B => 'building') :
253 [qw( x s m l l h h h h )]->[ $_->{cargo} ],
255 $_->{cargo} ? 'transportable' : 'untransportable',
257 defined $_->{size} && sprintf('⌀%.1f ', $_->{size}),
259 sprintf('<td class="val unit%s">%s',
260 defined $_->{pop} && $_->{pop} < 0 && ' unit-supply',
261 defined $_->{pop} && $_->{pop} == .5 ? '½' : $_->{pop},
263 '<td class="unit unit-type">' . join('', grep { $_ }
264 (defined $_->{organic} ? !$_->{organic} : $_->{attr}->{mech})
265 && '<span class="unit-u" title="mechanic">m</span>',
266 ($_->{organic} || $_->{attr}->{organic})
267 && '<span class="unit-o" title="organic">o</span>',
268 $_->{attr}->{psionic}
269 && '<span class="unit-p" title="psionic">ψ</span>',
271 '<td class="unit unit-attr">' . join('', grep { $_ }
272 $_->{attr}->{armored}
273 && '<span class="unit unit-l" title="armored">A</span>',
275 && '<span class="unit unit-s" title="light">L</span>',
276 $_->{suit} && sprintf(
277 '<span class="unit unit-%s" title="%3$s">%s</span>',
285 $_->{attr}->{massive}
286 && '<span class="unit-massive" title="massive">⚓</span>',
288 '<td class="val unit-hp">' . $_->{hp} // '',
289 $_->{shield} ? sprintf('<td class="val unit-shield">%.0f%%<td',
290 100 * $_->{shield} / $_->{hp}
292 ' class="val unit-armor">' .
293 showrange($_->{armor}, $_->{upgraded}->{armor}),
295 '<td class="val unit-sight">' . sprintf(
296 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
297 showrange($_->{sight}, $_->{upgraded}->{sight})
299 '<td class="val unit-speed">' .
300 showrange($_->{speed}, $_->{upgraded}->{speed}),
302 && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
303 '<td class="unit-magic">' . showmagic($_),
304 !$_->{attack}->[1] ? () : (
305 '<tr><td colspan=12>', showattack($_, 1), '<td colspan=3>'
307 !$_->{attack}->[2] ? () : (
308 '<tr><td colspan=12>', showattack($_, 2), '<td colspan=3>'
314 my $grouped = 1; # race headers
315 if (exists $get{order}) {
318 if ($get{order} eq 'size') {
320 $_->{pop}*16 + ($_->{size} // $_->{suit}) + $_->{cargo}/8
321 + $_->{hp}/512 + $_->{min}/8192
324 elsif ($get{order} eq 'cost') {
326 $_->{gas}*1.5 + $_->{min} + $_->{pop}/8 + $_->{build}/256/8
329 elsif ($get{order} eq 'attack') {
330 $_->{order} = $_->{hp} / 1024 + $_->{shield} / 1008 + max(
332 ($_->{damage} + $_->{upgrade} * 3)
333 * ($_->{count} // 1) / ($_->{cooldown} // 1)
334 * ($_->{splash} ? 1.01 : 1)
335 * ($_->{type} eq 'implosive' ? .96 : 1)
336 * ($_->{type} eq 'explosive' ? .98 : 1)
341 $units->[$_]->{order} = $_ for 0 .. $#$units;
344 my @rows = @{$units};
345 @rows = sort {$a->{order} <=> $b->{order}} @rows unless $grouped;
347 my ($race, $cat) = ('', '');
350 printf '<tbody id="%s"><tr class="race"><th colspan="20"><h2>%s</h2>'."\n",
351 $race = $_->{race}, ucfirst $race
352 unless $race eq $_->{race};
355 $_->{cat} = $_->{race};
360 '<th class="cat">', $cat ne $_->{cat} && ($cat = $_->{cat}),
365 for my $subrow (@{ $_->{special} }) {
366 $subrow->{alt} or next;
368 '<tr class="alt"><th class="cat"><td>', $subrow->{alt},
369 showunitcols($subrow),
381 <dd>minerals+gas required to create one unit
382 <dd>includes total expenses if based on existing units
384 <dd>relative time needed to create at least one unit
385 <dd>excludes construction of dependencies such as buildings
386 and <span class="unit-composed">+</span>parent units
388 <dd><span class="unit unit-supply">T</span>ransports can fit upto
389 <span class="unit unit-s">8</span>
390 non-<span class="unit unit-air">F</span>lying units
391 <dd>number of command points taken per unit
393 if ($scver{major} > 1) {
394 :>received damage depends on
395 <span class="unit unit-o">o</span>rganic,
396 <span class="unit unit-u">m</span>echanic,
397 <span class="unit unit-p">ψ</span>(ps)ionic,
398 <span class="unit unit-s">L</span>ight, and
399 <span class="unit unit-l">A</span>rmored
401 <dd>massive <span class="unit-massive">⚓</span> units
402 cannot be lifted or slowed and can break force fields<:
404 :><span class="unit unit-o">o</span>rganic/<span class="unit unit-u">m</span>echanic unit
405 <dd>affected by <span class="unit unit-s">S</span>mall,
406 <span class="unit unit-m">M</span>edium, or
407 <span class="unit unit-l">L</span>arge unit damage<:
410 total number of hitpoints (including shields)
412 <dd>percentage of HP in shields
413 <dd>shields always take full damage, irrelevant of unit size
414 <dd>does not take armor bonuses, but upgrades can decrease damage to any shield hit by upto 3
417 <dd>can be increased by upto 3 at various facilities
418 <dd>each point decreases damage per hit by one, upto a minimum of ½
419 <dd>reduction applies to initial damage, before size penalties
420 <small>(so a plasma hit of 12 to 4 armor large deals 2 damage, not ½)</small>
422 <dd>damage given per single hit
423 <dd><span class="hurtrel">dps</span> indicates relative amount of damage
424 done in 1 second of in-game time
425 <dd>splash damage hits all objects nearby <span class="unit-splash">⁜</span>
426 or in a straight line <span class="unit-splash">+</span>.
428 if ($scver{major} > 1) {
429 :>does not include <span>≥</span>bonus damage
430 dealt to susceptible unit types
431 <dd><span class="unit-pdd">•</span>projectile shots are negated by
432 Point Defense Drones<:
434 :><span class="unit-l">*</span>explosive damage does only
435 50% damage to small units, 75% to medium, 100% to large
436 <dd><span class="unit-s">~</span>concussive/plasma damage does
437 25% to large, 50% medium, 100% to small units<:
439 <dd>targets <span class="hurt-g">▽</span> ground
440 and/or <span class="hurt-a">△</span> air
442 <dd>maximum range of weapon (note siege tank also has a minimum range)
444 <dd>range in which the unit detects other units
445 <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
447 <dd>relative speed of movement (when in full motion, startup speed ignored)
449 <dd>parentheses () indicate that it needs to be researched first
450 <dd><span class="magic-perma">passive</span> abilities are always enabled
451 <dd>hover for description
452 <dd>range is maximum range required to activate
453 <dd>cost is percentage of total energy lost
457 When two values are given (1-2), second value indicates attribute after all