#!perl
#
# mapmaker v1.1
# reads a file with lines of format:
# nnnn A000000-0 NSG
# or
# Jd aaaa bbbb cccc xxxx
# or
# RZ nnnn
# AZ nnnn
# where nnnn is a hex map coordinate (0101 through 0810), A000000-0 is a UPP,
# NSG indicates Naval Scout or Gas Giant (omit or replace with . if none)
# and d is a single digit followed by a list of hex coordinates.
#
# It then draws a TAS form 6 with systems plotted and decorated with
# X-boat paths drawn.
#
# Revision 1.0 07-09-2007 bjm Initial release
# Revision 1.1 08-09-2007 bjm Adds listings, better option handling, help
# Revision 1.2 08-09-2007 bjm System, sector, subsector names
use strict;
use warnings;
use Getopt::Long;
Getopt::Long::Configure ("bundling");
# set this to get colour zones and listings
our $COLOUR = 0;
our $LISTINGS = 0;
our $HELP = 0;
our $side = 40;
my $rv = GetOptions ("colour|color|c" => \$COLOUR,
"listing|l" => \$LISTINGS,
"help|h" => \$HELP,
"side|s=i" => \$side,
);
if ($HELP) {
print STDERR "Usage: mapmaker [-l] [-c] [-s n] [-h]\n";
print STDERR " -l --listing List system stats\n";
print STDERR " -c --colour Use colour for zones and listing bars\n";
print STDERR " -s integer Set hex side length to integer\n";
print STDERR " -h --help Print this message\n";
exit;
}
#set these to control size
our $factor = 1.732;
#calc size of map
our $total_width = $side * 12.5;
our $total_height = $side * $factor * 10.5;
#calc hex info
our $sheight = $side * $factor / 2;
our $swidth = $side/2;
our $width = $side;
#jump dashes
our @jumpdash = (
"none",
"none",
"1%,1%",
"3%,1%",
"3%,1%,1%,3%" );
# names
our $sector;
our $subsector;
printmap();
sub printmap {
print header();
print frame();
for (0..9) {
print tophalf($_);
print bottomhalf($_);
}
print tophalf(10);
print number();
my @drawstuff;
my @worldlist;
while (<>) {
chomp;
s/^\s+//;
next if /^\s+$/;
next if /^#/;
/^\d/ && do { push @drawstuff, world($_); push @worldlist, $_; };
/^J/ && unshift @drawstuff, jump($_);
/^(R|A)Z/ && unshift @drawstuff, zone($_);
/^Sector/i && do { (undef,$sector) = split ' '; };
/^Subsector/i && do { (undef,$subsector) = split ' ';};
}
print "\n";
for (@drawstuff) { print; }
print "\n";
if ($LISTINGS) {
print "\n";
print listworlds(@worldlist);
print "\n";
}
print footer();
}
sub listworlds {
my @w = @_;
my $margin = $total_width + $side;
my $topmargin = $side;
my $line=0;
my $fsz = $side/4;
my $lsz = $side/3;
my $list;
my $subsecfontcolor;
my $secfontcolor;
if ($sector) {
$secfontcolor = 'black';
} else {
$secfontcolor = '#dddddd';
$sector = "Uknown";
}
if ($subsector) {
$subsecfontcolor = 'black';
} else {
$subsecfontcolor = '#dddddd';
$subsector = "Unknown";
}
$list .= '' . $sector . ' sector' . "\n";
$topmargin+= $fsz*2;
$list .= '' . $subsector . ' subsector' . "\n";
$topmargin+= $fsz*3;
$list .= '' . "\n";
for (@w) {
if ($line % 2) {
$list .= '';
$list .= "$loc";
$list .= '' . "\n";
$list .= '';
$list .= "$upp";
$list .= '' . "\n";
my $nsgsp=0;
for (@nsg) {
unless ($_ eq '.') {
$list .= '';
$list .= "$_";
$list .= '' . "\n";
}
$nsgsp++;
}
if ($rest) {
$list .= '';
$list .= $rest;
$list .= '' . "\n";
} else {
$list .= '';
$list .= "system name";
$list .= '' . "\n";
}
$line++;
}
$list .= '' . "\n";
return $list;
}
sub center_of {
my $coord = shift;
my $c = substr($coord,0,2) + 0;
my $r = substr($coord,2,2) + 0;
my $x = $side + (($c-1) * $side * 1.5);
my $y = ($c % 2) ? ($r-1) * $side * $factor + ($side * $factor /2):
($r-1) * $side * $factor + ($side * $factor);
return ($x,$y);
}
sub zone {
my $data = shift;
my ($z, $loc) = split ' ', $data;
my $zone = substr($z,0,1);
my %c = ('R' => 'red', 'A' => '#bbbb00');
my %zd = ('R' => "none", 'A' => "3%,1%");
my ($x, $y) = center_of($loc);
my $f;
if ($COLOUR) { $f = $c{$zone}; } else { $f = 'white'; }
return '' . "\n";
}
sub jump {
my $data = shift;
my ($j, @jumps) = split ' ', $data;
my $jt = substr($j,1,1) + 0;
my $s = $side/20;
my $out = '' . "\n";
} else {
$output .= '';
for (0..6) {
$output .= '' . "\n";
}
$output .= '' . "\n";
}
# sp
$output .= '' . $sp . '' . "\n";
# decorations
if ($dec =~ /N/i) {
my $nx = $x - ($side/3);
my $ny = $y - ($side/3);
$output .= star($nx,$ny);
};
if ($dec =~ /S/i) {
my $nx = $x + ($side/3);
my $ny = $y - ($side/3);
$output .= triangle($nx, $ny);
};
if ($dec =~ /G/i) {
my $nx = $x - ($side/3);
my $ny = $y + ($side/3);
$output .= '
' . "\n";
};
return $output;
}
sub triangle {
my ($x,$y) = @_;
my $triangle = '' . $n . '' . "\n";
}
}
return $t;
}
sub frame {
my $h = $total_height;
my $w = $total_width;
return '' . "\n";
}
sub half {
my ($row, $top) = @_;
my $ly = ($row * 2 * $sheight ) + $sheight;
my $line = '';
return $line;
}
sub tophalf {
return half(shift,1);
}
sub bottomhalf {
return half(shift,0);
}
sub header {
my $h = $total_height+5;
my $w;
if ($LISTINGS) {
$w = $total_width*2;
} else {
$w = $total_width+5;
}
return '
' . "\n";
}