+
+my $units = do $datafile;
+die "Cannot open unit data: $_\n" for $@ || $! || ();
+my $patch = shift @{$units}
+ or die "Cannot open unit data: metadata not found\n";
+
+print "<p>Unit properties as seen or measured in $scver{name}\n$patch.\n";
+print "Also see the $_ table.\n" for join(', ',
+ ('<a href="/sc/2">StarCraft 2: HotS</a>') x ($scver{major} < 2),
+ ('<a href="/sc">original SC: Brood War</a>') x ($scver{major} > 1),
+);
+print "</p>\n\n";
+
+sub addupgrade {
+ my ($ref, $increase, $org) = @_;
+ if (ref $increase eq 'HASH') {
+ addupgrade(\${$ref}->{$_}, $increase->{$_}, $org->{$_}) for keys %{$increase};
+ }
+ elsif (ref $increase eq 'ARRAY') {
+ addupgrade(\${$ref}->[$_], $increase->[$_], $org->[$_]) for 0 .. $#{$increase};
+ }
+ ${$ref} //= $org;
+ ${$ref} += $increase if $increase =~ /^-?[0-9.]+/;
+}
+
+for my $unit (@{$units}) {
+ for my $upgrade (@{ $unit->{upgrade} }) {
+ while (my ($col, $increase) = each %{$upgrade}) {
+ defined $unit->{$col} or next;
+ addupgrade(\$unit->{upgraded}->{$col}, $increase, $unit->{$col});
+ }
+ }
+ for my $special (@{ $unit->{special} }) {
+ for my $upgrade (@{ $special->{upgrade} }) {
+ while (my ($col, $increase) = each %{$upgrade}) {
+ defined $special->{$col} or next;
+ addupgrade(\$special->{upgraded}->{$col}, $increase, $special->{$col});
+ }
+ }
+ }
+}