#!/opt/bin/perl use Storable; my $LIBDIR = $ENV{CROSSFIRE_LIBDIR} or die "\$CROSSFIRE_LIBDIR must be set\n"; my $T = 32; my $arch; umask 022; our $VERSION = '1.01'; sub escape_html($) { local $_ = shift; s/([<>&])/sprintf "&#%d;", ord $1/ge; $_ } for my $path (@ARGV) { # print STDERR "$path\n"; if (!-e "$path.png" || !-e "$path.pst" || -M "$path.pst" > -M $path || -M "$path.png" > -M $path) { # regenerate png and metainfo system "cfmap2png", $path; }; $arch ||= Storable::retrieve "$LIBDIR/archetypes.pst"; my $meta = Storable::retrieve "$path.pst"; open my $fh, ">:utf8", "$path.html" or die "$path.html: $!"; select $fh; my $W = $meta->{width} * $T; my $H = $meta->{height} * $T; my (@path) = split /\//, $path; print "", "", "", "Crossfire Map \"$path\"", "", "", ""; print "", "", "", "", "", "", "", ""; my $W1 = $W + 600; print "

", escape_html $meta->{info}{msg}, "

"; print ""; my %ignore = map +($_ => 1), qw(name _name x y); for my $y (0.. $meta->{height} - 1) { print ""; for my $x (0.. $meta->{width} - 1) { print ""; } print ""; } print "
"; if (my $as = $meta->{map}[$x][$y]) { print "
($x|$y)"; sub print_archs { print "
    "; for my $a (@{$_[0]}) { my $o = $arch->{$a->{_name}}; my $aname = escape_html $a->{_name}; my $name = escape_html $a->{name} || $o->{name}; print "
  • $aname \"$name\"\n"; for (sort keys %$a) { next if $ignore{$_}; my $v = escape_html $a->{$_}; if (($o->{type} == 66 || $o->{type} == 41) && $_ eq "slaying") { # door, teleporter $a->{msg} =~ /^final_map\s*(\S+)\s*$/m, $v = $1 if $v eq "/!"; # random map print "slaying => $v\n"; } elsif ($_ eq "other_arch") { print "$_ => $v\n"; } elsif ($_ eq "inventory") { print "inventory =>\n"; print_archs ($a->{$_}); } elsif ($_ eq "msg") { print "

    $v

    "; } else { print "$_ => $v\n"; } } } print "
"; } print_archs $as; print "
"; } print "


created by cfmap2html version $VERSION

", "

"; close $fh; system "gzip", "-7f", "$path.html"; }