Citizens of the Imperium

Citizens of the Imperium (http://www.travellerrpg.com/CotI/Discuss/index.php)
-   Software Solutions (http://www.travellerrpg.com/CotI/Discuss/forumdisplay.php?f=63)
-   -   Making big PDF maps (http://www.travellerrpg.com/CotI/Discuss/showthread.php?t=11576)

robject April 14th, 2004 03:13 PM

Quote:

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 &quot;Alexandria.tas&quot;;</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 &quot;min MUST be spinward AND coreward of max!\n&quot;
unless $min &lt; $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 &quot;ERROR: file $filename not found\n&quot;;
my @dat = &lt;IN&gt;; # 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 &gt;= $min
&amp;&amp; $hex &lt;= $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 &gt; outfile.sec

Flynn April 14th, 2004 03:17 PM

Not knowing Perl, I'd have to leverage generic programming knowledge to get an idea of the syntax. It's something I'm willing to attempt if you aren't able to swiftly do so, but it's better to let the experts do so for something that would appear to be relatively quick and painless for someone with knowledge of Perl. It would just take me longer, and might be more frustrating. [img]smile.gif[/img]

I appreciate it,
Flynn

robject April 14th, 2004 03:46 PM

Using the script I walked through, you could carve up a sector map into quadrants by calling it four times:

perl carve.pl spinward.sec 0101 1620 &gt; sm_q1.sec
perl carve.pl spinward.sec 1701 3220 &gt; sm_q2.sec
perl carve.pl spinward.sec 0121 1640 &gt; sm_q3.sec
perl carve.pl spinward.sec 1721 3240 &gt; sm_q4.sec

(I think that's right)

You could get subsectors by calling it 16 times (but I'd instead put 16 calls into a batch file).

And, nicest of all, you can get any other chunk of a sector out.

perl carve.pl spinward.sec 1010 1919 &gt; teens.sec

Even more strange, you can get two disjoint sections of a sector, effectively masking out the rest of the sector data:

perl carve.pl spinward.sec 0101 0810 &gt; ss1.sec
perl carve.pl spinward.sec 2020 3240 &gt; lowerright.sec

type ss1.sec lowerright.sec &gt; masked.sec

robject April 14th, 2004 03:55 PM

I used to have sector data with the XBoat routes already coded in. (Sigh) But most of that hard work got corrupted. I had routes through the Marches, Deneb, Gushemege, Core, Dagudashaag, Zarushagar, Daibei. It was so nice...

Flynn April 14th, 2004 04:23 PM

Very cool. My last post was made before I read your script-fix. [img]smile.gif[/img]

Am trying this out now,
Flynn

Elliot April 14th, 2004 04:28 PM

Can this sector thing be built without the need for Computer 1 skill level? Can a nice GUI be put on the front so that I can have fun with it? Please?

Flynn April 14th, 2004 04:39 PM

robject,

Minor problem. Created the carve.pl, used the parameters you suggested, and I got a distorted map that included two quadrants, not one.

It deleted the unused columns, but not the rows, sadly enough. So I get the upper-right quadrant and the lower-right quadrant when I ask for the upper-right quadrant. Same when I ask for the lower-right quadrant.

Thoughts?

-Flynn

EDIT: From looking at the data files, carve.pl is going through the array and outputting any UWP with a location between the minimum and the maximum, but doesn't hack out the UWPs for locations below the minimum row or column, or for those above the maximum row or column.

Flynn April 14th, 2004 04:57 PM

Elliot,

I couldn't do it, as I have no server to host it, nor do I know Perl. But the info's here for anyone that might have the knowledge and the means. If there are any takers, please feel free to undertake this challenge for the other Traveller fans out there.

Best of luck in finding volunteers, Elliot,
Flynn

robject April 14th, 2004 05:15 PM

Quote:

Originally posted by Flynn:
robject,

Minor problem. Created the carve.pl, used the parameters you suggested, and I got a distorted map that included two quadrants, not one.

[...]

EDIT: From looking at the data files, carve.pl is going through the array and outputting any UWP with a location between the minimum and the maximum, but doesn't hack out the UWPs for locations below the minimum row or column, or for those above the maximum row or column.

You're right. That's my fault for not thinking about the problem. If I'm taking 1720-3240, I don't want 1801, for instance. Rats, we're going to have to crack open the Hex number and fool with it a little.

robject April 14th, 2004 05:19 PM

So, I've added a subroutine which accepts three hex numbers, and returns true if the first lies within the bounds of the other two.

</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">use strict;
require &quot;Alexandria.tas&quot;;

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 &quot;min MUST be spinward AND coreward of max!\n&quot;
unless $min &lt; $max;

open IN, $filename || die &quot;ERROR: file $filename not found\n&quot;;
my @dat = &lt;IN&gt;; # read in the whole thing
close IN;

my %sector = getBunchesOfWorlds( @dat );

delete $sector{minrow};
delete $sector{mincol};
delete $sector{maxrow};
delete $sector{maxcol};

foreach my $hex (sort keys %sector)
{
my %world = %{$sector{$hex}};
print putWorld(%world)
if inside( $hex, $min, $max );
}

sub inside
{
my $hex = shift;
my $min = shift;
my $max = shift;

my ($r, $c) = $hex =~ /(\d\d)(\d\d)/;
my ($r1, $c1) = $min =~ /(\d\d)(\d\d)/;
my ($r2, $c2) = $max =~ /(\d\d)(\d\d)/;

return $r &gt;= $r1
&amp;&amp; $r &lt;= $r2
&amp;&amp; $c &gt;= $c1
&amp;&amp; $c &lt;= $c2;
}</pre>[/QUOTE]


All times are GMT -4. The time now is 10:19 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (c) 2010-2013, Far Future Enterprises. All Rights Reserved.