From: colin@Cayman.COM (Colin "Atilla" Steele)
Newsgroups: rec.games.pbm
Subject: ships.pl, ver 1.2.1
Date: 10 Sep 92 17:40:28 GMT
Distribution: rec
Organization: Cayman Systems Inc., Cambridge, MA


Well, here's the fix for the fix.  Note the addition of a new stat
(the "50% AS" stat), which will tell you what attack strength is
needed to have a 50% chance of hitting the ship.  

cut here ----------------------------------------------------------------------
#!/bin/perl
#
#
###############################################################################
# SHIPS.PL Ver 1.2.1
# Author:  Colin A. Steele (colin@Cayman.com)
# Redistribute freely.  Go nuts ;-)
# Report bugs to colin@Cayman.com.  I may not fix it, but I'll be sympathetic.
#     
#     
# Usage:  ships.pl [-f turnfile] [-a] [-o ownername] [-d] [-b]
# use -f to specify the turnfile to process, else use stdin.
# use -a to see stats on all ships.
# use -o to specify the name of the player whose ships you want stats on.
# use -b to see basic stats.
# use -d to see derived (interesting) stats.
#   
# Stats are calculated as follows.  None of the derived
# stats take tech into account - just multiply by tech to get
# the real stat...
#   
# From "galaxy-rules":  The mass of a ship is equal to Drive +
#                       Attacks*Weapons + Shield + Cargo.
#   
#                       A ship moves a number of light years
#                       per turn equal to 20 times its
#                       drive power divided by its total mass.
#
#                       "Total mass" means the mass of the ship
#                       itself plus the mass of any cargo it's carrying...
#                       
#                       The power of the attack is
#                       equal to the Weapons number multiplied by the
#                       Weapons tech level.
#                 
#                       The power of the defense is equal to the Shield
#                       number multiplied by the Shield tech level
#                       and divided by the diameter of the target ship.
#
#                       A ship's diameter is equal to
#                       the cube root of its mass.
###############################################################################

require "getopts.pl";

#
# Check command line options - if no file is specified, use stdin.
#
&Getopts('af:o:bd');

$inGroups = 0;
undef $owner;

$FILE = $opt_f;
$OWNER = $opt_o;
$ALL = $opt_a;
$BASIC = $opt_b;
$DERIVED = $opt_d;

(!$FILE) && ($FILE = STDIN);

if ($FILE ne "STDIN") {
    open(INFILE, "<$FILE") || die "Can't open input file $FILE: $!\n";
}

#
# Here's the main part - snarf in the file, and when we hit a section
# that starts with "N      D A  W  S  C", then start processing
# the ships.  Use the ship's name and owner as the key into our
# associative arrays.  When you hit a blank line, stop processing
# ships.
#
while (<INFILE>) {

    if (/\s*(\w*) Ship Types\s*/) {
        $owner = $1;
    }
    
    if (/N\s*D\s*A\s*W\s*S\s*C\s*$/) {
        if (($OWNER && ($owner eq $OWNER)) || !$OWNER || $ALL) {
            $inGroups = 1;
        }
    }
    
    if ($inGroups) {

        if (/^(\w*)\s*([\d.]+)\s*([\d.]+)\s*([\d.]+)\s*([\d.]+)\s*([\d.]+)\s*/) {
            $key = $1 . $owner;
            $shipName{$key} = $1;
            $shipOwner{$key} = $owner;
            $shipDrives{$key} = $2;
            $shipAttacks{$key} = $3;
            $shipWeapons{$key} = $4;
            $shipShields{$key} = $5;
            $shipCargo{$key} = $6;
            $shipMass{$key} = $2 + ($3 * $4) + $5 + $6;
            $shipMassRoot{$key} = $shipMass{$key} ** (1/3);
        }

        if (/^\s*$/) {
            $inGroups = 0;
        }
    }
}

#
# Print out the basic stats
#
if ($BASIC) {
    printf "%14s      %s    %s    %s    %s    %s   %s   %s     %s     %s\n",
       "Name",
       "Dri",
       "Att",
       "Wea",
       "Shd",
       "Car";
    for (sort keys %shipName) {
        if (($OWNER && ($shipOwner{$_} eq $OWNER)) ||
            (!$OWNER && ($shipOwner{$_} eq "Your")) ||
            $ALL) {
          printf "%14s   %6.2f %6.2f %6.2f %6.2f %6.2f\n",
                 $shipName{$_},
                 $shipDrives{$_},
                 $shipAttacks{$_},
                 $shipWeapons{$_},
                 $shipShields{$_},
                 $shipCargo{$_};
        }
    }
}

print "\n" . "\n";

#
# Print out the dervied stats
#
if ($DERIVED) {
    printf "%14s     %s   %s     %s\t  %s     %s   %s\n",
       "Name",
       "Mass",
       "Diam",
       "SS (50% AS)",
       "AS",
       "Move",
       "Owner";
    for (sort keys %shipDrives) {
        if (($OWNER && ($shipOwner{$_} eq $OWNER)) ||
            (!$OWNER && ($shipOwner{$_} eq "Your")) ||
            $ALL) {
          printf "%14s   %6.2f %6.2f %6.2f (%.2f)\t%6.2f %6.2f   %s\n",
            $shipName{$_},
            $shipMass{$_},
            $shipMassRoot{$_},
            $shipShields{$_} / $shipMassRoot{$_},
            $shipShields{$_} / $shipMassRoot{$_} * (30 ** (1/3)),
            $shipAttacks{$_} * $shipWeapons{$_},
            20 * $shipDrives{$_} / $shipMass{$_},
            $shipOwner{$_};
      }
    }
}
--


------------------------------------------------------------------------------
 Colin Steele     | Cayman Systems, 26 Landsdowne St., Cambridge, MA 02139
 colin@cayman.com | (617) 494-1916 x209 | applelink D0523 | Fax (617) 494-9270