Utility for Galaxy players From: colin@Cayman.COM (Colin "Atilla" Steele) Date: Thu, 20 Aug 1992 18:34:59 +0000 Enclosed is dist.pl, a utility for providing some simple information from a galaxy turn. It is written in PERL, which, for those of you who know not, is a language that's quite easy to learn, and fairly useful. If you don't have it, get it from uunet.uu.net, in gnu/perl-<something>.tar.Z, or from jpl-devvax.jpl.nasa.gov in pub. Anyhow, dist.pl will slurp in the turn file (specified in the -f arg, or piped in from stdin) spit out: 1. The distance between any two planets (use "dist.pl -o originplanet -d destplanet) 2. Any planet within a certain distance of an origin planet (use "dist.pl -o originplanet -m distance") 3. The distance between all planets and an origin planet (use "dist.pl -o originplanet") Let me know if y'all find this useful, and if you'd like more such tools. Also, let me know if you'd prefer tools written in C (although unless I get an overwhelming response indicating this, I'll just keep on writing them in perl). BTW, just to convince you to get perl, it only took me about 30 minutes to write, debug and enhance this 'lil widget. -------------------------------- cut here ------------------------------------- #!/bin/perl # # ############################################################################### # DIST.PL ############################################################################### require "getopts.pl"; # # Check command line options - if no file is specified, use stdin. # &Getopts('f:o:d:m:'); $inPlanets = 0; $FILE = $opt_f; $DEST = $opt_d; $ORIGIN = $opt_o; $MAX = $opt_m; (!$FILE) && ($FILE = STDIN); if ($FILE ne "STDIN") { open(INFILE, "<$FILE") || die "Can't open input file $FILE: $!\n"; } while (<INFILE>) { if (/^N\s*X\s*Y?S?.*$/) { $inPlanets = 1; } if ($inPlanets) { if (/^([0-9A-Za-z_'`]+)\s*([\d.]+)\s*([\d.]+).*/) { $planetX{$1} = $2; $planetY{$1} = $3; # print $_; } if (/^\s*$/) { $inPlanets = 0; } } } if ($DEST) { printf "%16s\t%s\t%s\n", "Name", "X", "Y"; printf "%16s\t%.2f\t%.2f\n", $DEST, $planetX{$DEST}, $planetY{$DEST}; printf "%16s\t%.2f\t%.2f\n", $ORIGIN, $planetX{$ORIGIN}, $planetY{$ORIGIN}; $y = $planetY{$ORIGIN} - $planetY{$DEST}; $x = $planetX{$ORIGIN} - $planetX{$DEST}; $hypotenuse = ($x**2 + $y**2)**(1/2); printf "Distance Between %s and %s is %.2f\n", $DEST, $ORIGIN, $hypotenuse; } else { for (sort keys %planetX) { $y = $planetY{$ORIGIN} - $planetY{$_}; $x = $planetX{$ORIGIN} - $planetX{$_}; $hypotenuse = ($x**2 + $y**2)**(1/2); if (($MAX && ($hypotenuse < $MAX)) || !$MAX) { printf "%16s is %.2f from $ORIGIN\n", $_, $hypotenuse; } } } -- ------------------------------------------------------------------------------ Colin Steele | Cayman Systems, 26 Landsdowne St., Cambridge, MA 02139 colin@cayman.com | (617) 494-1916 x209 | applelink D0523 | Fax (617) 494-9270 Up