#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $SHOWWARN = 0; my $SHOWMAP = "head"; # ascii, num, ppm my $SHOWCOL = 0; use Getopt::Long; GetOptions( "verbose|v!" => \$SHOWWARN, "map|m=s" => \$SHOWMAP, "color|c" => \$SHOWCOL, ); use Data::StarCraft::Map; my $map = Data::StarCraft::Map->new->open(\*STDIN); $map->{DEBUG} = 1 if $SHOWWARN; if ($SHOWMAP ne "ppm") { printf("%s size %dx%d, %d player\n", $map->version, $map->info->{x}, $map->info->{y}, scalar grep {$_->{id} == 214} $map->units, ); print "\n"; } if ($SHOWMAP eq "head") { if ($map->{STR}) { my @str = split /\0/, substr $map->{STR}, 2051; $SHOWCOL ? ( s/([\001-\007])/sprintf '[0;%dm', 30+ord($1)/eg and $_ .= "" ) : s/[\001-\017]//g, print "* $_\n" for @str; print "\n"; } printf "%-4s %d\n", $_, defined $map->{$_} ? length $map->{$_} : 0 for sort keys %$map; print "\n"; printf "%s: %s\n", $_, join ",", unpack "C*", $map->{$_} for sort grep { defined $map->{$_} and length $map->{$_} < 32 } keys %$map; print "\n"; } sub world { my $self = shift; # ERA: 0 1 2 3 4 5 6 7 my @worlds = qw(badlands platform install ashworld jungle desert ice twilight); return $worlds[$self->era] || "?"; } # MTXM TILE # ? ? yes # v205 = yes no my %mapsep = ( num => ',', ppm => ' ', ascii => '', ); if (defined $mapsep{$SHOWMAP}) { my $MAPCHARSEP = $mapsep{$SHOWMAP}; my $tiles = $SHOWMAP eq "num" ? [ map sprintf('%5d', $_), @{$map->tiles} ] : $map->tiles;#_parsed; if ($SHOWMAP eq "ppm") { use Data::StarCraft::Tileset; my $era = world($map); if ($era eq '?') { warn 'Tileset '.$map->era.' not recognized; fallback to jungle'; $era = 'jungle'; } my $tileset = Data::StarCraft::Tileset->open("/home/shiar/sc/tileset_$era") or die "No tileset for world $era"; printf "P3\n%d %d\n255\n", $map->info->{x}, $map->info->{y}; for (@$tiles) { my $tile = $tileset->tileavg($_); my $div = 1;#$tile->{walk} > 1 ? 1 : 1.8; my @rgb = map {int($_ / $div)} @{ $tile->{col} }; if (($tile->{walk} & 1) == 0 and $tile->{walk} < 10) { # $rgb[2] += 128; $rgb[0] *= 3; $rgb[1] *= 3; $rgb[2] *= 3; } elsif ($tile->{build}) { $rgb[0] += 48; # $rgb[$_] = int($rgb[$_] / 1.5) for 0..2; } $_ = join ' ', @rgb; } } while (my @line = splice @$tiles, 0, $map->width) { printf "%s\n", join $MAPCHARSEP, @line; } } =head1 scmap From replay: old/screptomap somereplay.rep | ./scmap -m=ppm > map.ppm From map: ./scmtomap starcraft/maps/ladder/'(4)Lost Temple.scm' ./scmap -m=ppm < file000001.xxx > map.ppm =cut