Originally posted by Flynn:
Wow, it works great!
Do you have the script that breaks a sector down into subsectors?
And how hard would it be to modify that script to take a sector file and break it down into the four quadrants?
This is very cool,
Flynn
Both would be pretty straightforward. I remember actually writing those scripts before. Hang on and I'll see what I can do.
As a matter of fact,
you might be able to write those types of scripts, too.
What we
really want is a script that lets us extract
any region of a sector map.
Perl scripts are usually written inside any old text editor. Give it a .pl ending to identify it as perl.
Let's start out with these lines:
</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">use strict;
require "Alexandria.tas";</pre>[/QUOTE]The first line helps people debug problems. The second lets us leverage a very useful Traveller subroutine.
Now, for our Traveller data, we want to operate on a sector file. We also want to know what extents to extract. So we'd pass in something like this:
myprogram.pl spinward.sec 0101 0810
so our code would read a filename and two extents:
</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">my $filename = shift;
my $min = shift;
my $max = shift;
#
# Let's make sure min and max are in the
# proper relationship to each other.
#
die "min MUST be spinward AND coreward of max!\n"
unless $min < $max;</pre>[/QUOTE]next, let's open up the sector file and read it in.
</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">open IN, $filename || die "ERROR: file $filename not found\n";
my @dat = <IN>; # read in the whole thing
close IN;</pre>[/QUOTE]Now we want all this gunk parsed out for us.
</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">my %sector = getBunchesOfWorlds( @dat );
delete $sector{minrow};
delete $sector{mincol};
delete $sector{maxrow};
delete $sector{maxcol};</pre>[/QUOTE]%sector is a table of UWP data, indexed by hex number. So now we just run through this table, and print out the entries whose hex numbers are within our required extents.
%sector also contains four pieces of meta-data: the min and max row and column detected. Those four 'delete' lines get rid of that data.
</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">foreach my $hex (sort keys %sector)
{
my %world = %{$sector{$hex}};
print putWorld(%world)
if $hex >= $min
&& $hex <= $max;
}</pre>[/QUOTE](I already see things I don't like about this old code. I really should rewrite it someday.)
That's it. Call the script something like
carve.pl and run it like this:
perl carve.pl spinward.sec 0101 0810 > outfile.sec