sc: separate css to external file
[sheet.git] / sc.plp
1 <(common.inc.plp)><:
2
3 my $datafile = 'sc-units.inc.pl';
4 if ($ENV{PATH_INFO} and $ENV{PATH_INFO} eq '/2') {
5         $datafile = 'sc2-units.inc.pl';
6 }
7
8 Html({
9         title => 'starcraft unit cheat sheet',
10         version => 'v1.0',
11         description => [
12                 'Reference of StarCraft unit properties,'
13                 . ' comparing various statistics of all the units in Brood War'
14                 . ' including costs, damage, defense, speed, ranges, and abilities.',
15         ],
16         keywords => [qw'
17                 starcraft game unit statistics stats comparison table sheet cheat
18                 reference software attributes properties
19         '],
20         stylesheet => [qw'light'],
21         raw => '<link rel="stylesheet" type="text/css" media="all" href="/sc.css?1.1" title="light">',
22         data => [$datafile],
23 });
24
25 :>
26 <h1>StarCraft units</h1>
27
28 <p>
29 Unit properties as seen or measured in Brood War
30 <span title="no known changes as of v1.16.1">version≥1.08</span>.
31 </p>
32
33 <:
34 sub coltoggle {
35         my ($name, $id) = @_;
36         return sprintf(
37                 (defined $get{order} ? $get{order} eq $id : !$id) ? '%2$s ▼'
38                         : '<a href="?%s">%s</a>',
39                 $id && "order=$id", $name
40         );
41 }
42 :><table class="units">
43 <thead><tr>
44         <th></th>
45         <th><:= coltoggle('name', '') :></th>
46         <th class="val min"><img src="/minerals.png" alt="min"></th>
47         <th class="val gas"><img src="/gas.png" alt="gas"></th>
48         <th class="val time"><:= coltoggle(qw'build cost') :></th>
49         <th class="unit" colspan="2"><:= coltoggle(qw'size size') :></th>
50         <th class="val unit-hp">HP</th>
51         <th class="val unit-shield">shield</th>
52         <th class="val unit-armor">armor</th>
53         <th class="val hurt" colspan="2">ground</th>
54         <th class="val hurt" colspan="2">air</th>
55         <th class="val unit-range">range</th>
56         <th class="val unit-sight">sight</th>
57         <th class="val unit-speed">speed</th>
58         <th class="unit-magic">specials</th>
59 </tr></thead>
60 <:
61 sub showrange {
62         my ($min, $max) = @_;
63         $_ = int($_ + .5) for $min, $max;  # round halves up
64         return $min == $max ? $min : "$min-$max";
65 }
66
67 sub showval {
68         my ($row, @elements) = @_;
69         my ($min, $max);
70
71         my $value = $row;
72         $value = ref $value eq 'HASH' && $value->{$_} or last for @elements;
73         if (ref $value eq 'ARRAY') {
74                 $min = $value->[0];
75                 $max = $value->[-1];
76         }
77         else {
78                 $min = $max = $value;
79         }
80         defined $min or return '';
81
82         if ($row->{upgrade}) {
83                 for (@{ $row->{upgrade} }) {
84                         my $increase = $_ or next;
85                         $increase = ref $increase eq 'HASH' && $increase->{$_} or last for @elements;
86                         $increase = $increase->[-1] if ref $increase eq 'ARRAY';
87                         $max += $increase if $increase;
88                 }
89         }
90
91         if ($elements[0] eq 'attack' and $elements[1] ne 'range' and $elements[2] eq 'dps') {{
92                 my $attack = $row->{ $elements[0] }->{ $elements[1] };
93                 ref $attack or $attack = $row->{ $elements[0] }->{$attack}; # follow
94                 my $type = $attack->{type} or next;
95                 if ($type eq 'explosive') {
96                         $min /= 2;
97                 }
98                 elsif ($type eq 'implosive') {
99                         $min /= 4;
100                 }
101         }}
102         return showrange($min, $max);
103 }
104
105         sub showattack {
106                 my ($row, $area) = @_;
107                 my $attack = $row->{attack}->{$area};
108                 if (not ref $attack) {
109                         # reference to another area
110                         $area = $attack;
111                         $attack = $row->{attack}->{$area};
112                 }
113
114                 return '<td colspan="2" class="hurt">' unless $attack;
115
116                 my $tagbase = '<td class="val hurt';
117                 if (ref $attack and $attack->{type}) {
118                         if ($attack->{type} eq 'explosive') {
119                                 $tagbase .= ' unit-l';
120                         }
121                         elsif ($attack->{type} eq 'implosive') {
122                                 $tagbase .= ' unit-s';
123                         }
124                 }
125                 $tagbase .= '">';
126
127                 my $out = showval($row, 'attack', $area, 'damage');
128                 $out .= '<span class="unit-splash">+</span>' if $attack->{splash};
129                 $attack->{dps} = $attack->{cooldown} && [
130                         map { 24 * $_ / $attack->{cooldown} * ($attack->{count} // 1) }
131                         map { ref $_ ? @{$_} : $_ }
132                         $attack->{damage}
133                         #TODO: upgrade (zergling)
134                 ];
135                 $out .= '<td class="val hurt hurtrel">' . showval($row, 'attack', $area, 'dps');
136                 return $tagbase . $out;
137         }
138
139         sub showmagic {
140                 my ($row) = @_;
141                 my $specials = $row->{special} or return '';
142                 return join ' ', map {
143                         sprintf '<span%s title="%s">%s</span>',
144                                 $_->{duration} < 0 && ' class="magic-perma"',
145                                 join('',
146                                         $_->{name},
147                                         $_->{desc} ? ": $_->{desc}" : '',
148                                         $_->{range} || $_->{cost} ? sprintf(' (%s)', join ', ',
149                                                 $_->{range} ? "range $_->{range}" : (),
150                                                 $_->{cost} ? sprintf('cost %.0f%%',
151                                                         100 * $_->{cost} / $row->{energy}
152                                                 ) : (),
153                                         ) : '',
154                                 ),
155                                 sprintf($_->{build} ? '(%s)' : '%s', $_->{abbr}),
156                 } grep { defined $_->{abbr} } @{$specials};
157         }
158
159         sub showunitcols {
160                 my ($row) = @_;
161                 local $_ = $row;
162                 $_->{hp} += $_->{shield} if $_->{shield};
163                 my $suitchar = '';
164                 if ($_->{suit}) {
165                         $suitchar = [qw/? s m l/]->[$_->{suit}];
166                 }
167
168                 return (
169                         '<td class="val min">' . ($_->{min} // ''),
170                         '<td class="val gas">' . ($_->{gas} || ''),
171                         !defined $_->{build} ? '<td>' : sprintf('<td class="val time">%s%.0f',
172                                 !!$_->{base} && '<span class="unit-composed">+</span>',
173                                 $_->{build} || '0',
174                         ),
175                         !$suitchar ? '<td>' : sprintf('<td class="unit unit-%s">%s', $suitchar, ucfirst $suitchar),
176                         '<td class="val unit">' . join('',
177                                 defined $_->{unit} && $_->{unit} == .5 ? '½' : $_->{unit},
178                                 defined $_->{organic} && sprintf(
179                                         '<span class="unit-%s" title="%s">%s</span>',
180                                         $_->{organic} ? 'o' : 'u',
181                                         $_->{organic} ? 'organic' : 'mechanic',
182                                         $_->{organic} ? 'o' : 'm',
183                                 ),
184                         ),
185                         '<td class="val unit-hp">' . $_->{hp} // '',
186                         '<td class="val unit-shield">' . (
187                                 $_->{shield} ? sprintf('%.0f%%', 100 * $_->{shield} / $_->{hp}) : '&nbsp;'
188                         ),
189                         '<td class="val unit-armor">' . showval($_, 'armor'),
190                         showattack($_, 'ground'),
191                         showattack($_, 'air'),
192                         '<td class="val unit-range">' . showval($_, 'attack', 'range'),
193                         '<td class="val unit-sight">' . sprintf(
194                                 $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
195                                 showval($_, 'sight')
196                         ),
197                         '<td class="val unit-speed">' . showval($_, 'speed'),
198                         '<td class="unit-magic">' . showmagic($_),
199                         "\n"
200                 );
201         }
202
203         my $units = do $datafile;
204         die "Cannot open unit data: $_\n" for $@ || $! || ();
205         my $grouped = 1;  # race headers
206         if (exists $get{order}) {
207                 $grouped = 0;
208                 $get{order} ||= '';
209                 if ($get{order} eq 'size') {
210                         $_->{order} = $_->{unit}*8 + $_->{suit} + $_->{hp}/512 + $_->{min}/8192 for @$units;
211                 }
212                 elsif ($get{order} eq 'cost') {
213                         $_->{order} = $_->{gas}*1.5 + $_->{min} + $_->{unit}/8 + $_->{build}/256/8 for @$units;
214                 }
215                 else {
216                         $units->[$_]->{order} = $_ for 0 .. $#$units;
217                 }
218         }
219         my @rows = @{$units};
220         @rows = sort {$a->{order} <=> $b->{order}} @rows unless $grouped;
221
222         my ($race, $cat) = ('', '');
223         for (@rows) {
224                 if ($grouped) {
225                         printf '<tbody id="%s"><tr class="race"><th colspan="18"><h2>%s</h2>'."\n",
226                                 $race = $_->{race}, ucfirst $race
227                                         unless $race eq $_->{race};
228                 }
229                 else {
230                         $_->{cat} = $_->{race};
231                 }
232
233                 print(
234                         '<tr>',
235                         sprintf('<t%s class="cat">%s',
236                                 $cat ne $_->{cat} ? ('h', $cat = $_->{cat}) : ('d', '&nbsp;')
237                         ),
238                         '<td>' . $_->{name},
239                         showunitcols($_),
240                 );
241
242                 for my $subrow (@{ $_->{special} }) {
243                         $subrow->{alt} or next;
244                         print(
245                                 '<tr class="alt"><td class="cat"><td>' . $subrow->{alt},
246                                 showunitcols($subrow),
247                         );
248                 }
249         }
250 :>
251 </table>
252
253 <div class="legend">
254 <h2>Legend</h2>
255
256 <dl>
257 <dt>cost
258         <dd>minerals+gas required to create one unit
259         <dd>includes total expenses if based on existing units
260 <dt>build
261         <dd>relative time needed to create at least one unit
262         <dd>excludes construction of dependencies such as buildings
263                 and <span class="unit-composed">+</span>parent units
264 <dt>size
265         <dd>affected by <span class="unit unit-s">S</span>mall,
266                 <span class="unit unit-m">M</span>edium,
267                 or <span class="unit unit-l">L</span>arge unit damage
268         <dd>number of command points taken per unit
269         <dd><span class="unit unit-o">o</span>rganic/<span class="unit unit-u">m</span>echanic unit
270 <dt>HP<dd>
271         total number of hitpoints (including shields)
272 <dt>shield
273         <dd>percentage of HP in shields
274         <dd>shields always take full damage, irrelevant of unit size
275         <dd>does not take armor bonuses, but upgrades can decrease damage to any shield hit by upto 3
276 <dt>armor
277         <dd>base unit armor
278         <dd>can be increased by upto 3 at various facilities
279         <dd>each point decreases damage per hit by one, upto a minimum of ½
280         <dd>reduction applies to initial damage, before size penalties <small>(so a plasma hit of 12 to 4 armor large deals 2 damage, not ½)</small>
281 <dt>ground/air
282         <dd>damage done per single attack against ground/air units
283         <dd>2nd column indicates relative amount of damage done in
284                 1 second of fastest game time
285         <dd>splash damage<span class="unit-splash">+</span> hits nearby objects as well
286         <dd><span class="hurt unit-l">explosive</span> damage does only
287                 50% damage to small units, 75% to medium, 100% to large
288         <dd><span class="hurt unit-s">concussive/plasma</span> damage does
289                 25% to large, 50% medium, 100% to small units
290 <dt>sight
291         <dd>range in which the unit detects other units
292         <dd><strong class="unit-detect">emphasis</strong> indicates ability to detect cloaked units
293 <dt>range
294         <dd>maximum range of weapon (note siege tank also has a minimum range)
295 <dt>speed
296         <dd>relative speed of movement (when in full motion, startup speed ignored)
297 <dt>specials
298         <dd>special abilities are usually casted manually, but some are <span class="magic-perma">always active</span>
299         <dd>parentheses () indicate that it needs to be researched first
300         <dd>hover for description
301         <dd>range is maximum range required to activate
302         <dd>cost is percentage of total energy lost
303 </dl>
304
305 <p>
306 When two values are given (1-2), second value indicates attribute after all
307 possible upgrades.
308 </p>
309
310 </div>
311