I use this to conduct pirate opertions in a Traveller RPG setting. Enjoy, matey!

use strict; srand; $|++; print "Arr! Welcome to the Traveller Pirate Simulation!\n"; ################################################# # # Setup: determine player info. # ################################################# my ($shipname, $volume, $hold, $cr) = split( ' ', <DATA> ); unless ($shipname) { print "Please enter your ship's name:\n"; $shipname = <STDIN>; chomp $shipname; print "How many tons does The $shipname displace?\n"; $volume = <STDIN>; chomp $volume; print "And how many tons of that is cargo space?\n"; $hold = <STDIN>; chomp $hold; print "And how many kilocredits are in your operating funds currentl +y?\n"; $cr = <STDIN>; chomp $cr; print "Thank you.\n"; } print "Let me take a look at your ship, here...\n\n"; die "Arr! That ain't no pirating ship!\n" if ($hold < 10) || ($volume + < 100) || ($volume/$hold > 10); my $dr = int($volume/$hold); my $hp = int($volume/10); my $crew = int($volume/20); my $rating = (('tenderized','tenderized','tenderized', 'balanced','balanced','balanced', 'militarized','militarized','militarized')[$dr]); my $notoriety = 0; print<<PREGAME; The $shipname is a $volume-ton ship, with a $hold-ton hold. The ship's operating funds stand at KCr$cr. The $shipname will take $hp points of damage before she is captured. You have $crew crew, each of which receives one share of all profits. As captain, you receive 2 shares of all profits. Your defensive rating is $dr, which rates your ship as '$rating'. PREGAME $hp--; ################################################# # # Lookup tables for system and ship encounters # ################################################# my %sdm = ('A'=>3,'B'=>2,'C'=>1,'D'=>0,'E'=>-1,'X'=>-2); my %sc = ('S'=>1,'A'=>10,'R'=>20,'T'=>10,'M'=>10); my %hc = ('F'=>10); my %pdm = ('S'=>-2,'A'=>0,'R'=>0,'F'=>-4,'T'=>-7,'M'=>-7); my %type = ( 'A', 'Trader', 'S', 'Scout', 'F', 'Freighter', 'R', 'Merchant', 'T', 'Patrol Ship', 'M', 'Mercenary Cruiser' ); my $dmg = 0; ################################################# # # Main Loop # ################################################# my $week = 0; for(;;) { &run(++$week); print "Does the captain of the $shipname wish to retire? [yn]\n"; my $choice = <STDIN>; if ($choice =~ /y/i) { print "Very good.\n"; &retire; } else { print "Arr! Another week of pillage and plunder!\n\n"; } } sub calculateScore { my $shares = $crew + 2; my $profits = int(2 * $cr/$shares); $notoriety = int(log ($profits/(5*$hp*$dr))); return $profits; } ################################################# # # Calculate retirement cash & skill level # (i.e. mustering-out benefits!) # ################################################# sub retire { my $shipFence = int(rand(2)*$volume/20); $cr += $shipFence * 1000; my $profits = &calculateScore(); print<<RETIRED; Your career as a pirate has ended. You fence your ship for MCr$shipFence. Your total profits are KCr$cr. Your take comes to KCr$profits. Your pirating skill level is $notorie +ty. Thank you for playing! RETIRED exit; } # # Quick 'n Dirty dice roller. # sub roll { return $_[0] + int(rand(6)) + int(rand(6)) + 2; } ################################################# # # run(): the workhorse of the program # ################################################# sub run { my $wk = shift; my $port = (('','', 'A','A','A','B','B','C','D','E','X','X','X')[&r +oll()]); my $dm = $sdm{$port} + $notoriety; my $ship = (('S','S','S','S','A','A','A','R','F','F','T','T','T','T +')[&roll($dm)]); $ship = 'M' unless $ship; my $scargo = 0; my $hcargo = 0; my $tcargo = 0; my $actualCargoTonnage = 0; my $newDamage = 0; my $repairs = 0; my $repairCostTotal = 0; my $profit = 0; print "Captain's log, week $wk. Our notoriety is at level $notorie +ty.\n"; print "We have entered a system with a class $port port.\n"; if ( $ship eq 'T' ) # Smokey's here { print "We have been chased off by a Patrol ship.\n"; $newDamage = int(rand(4)); print "The $shipname sustained $newDamage points of damage.\n" i +f $newDamage > 0; } elsif ( $ship eq 'M' ) # Bounty hunter gonna take a crack at you { print "Uh oh! A Mercenary cruiser has found us!\n"; $newDamage += int(rand(20/$dr)); $newDamage = 0 if $newDamage < 0; print "The $shipname sustained $newDamage points of damage.\n" i +f $newDamage > 0; } else # captured a cargo ship { print "We have captured a $type{$ship}.\n"; $scargo += &roll($notoriety) * $sc{$ship}; $hcargo += &roll($notoriety) * $hc{$ship} * 10; $tcargo = $scargo + $hcargo; # fence cargo and repair ship $cr += $scargo; $cr += $hcargo * 10; $profit = $scargo + $hcargo * 10; print "$tcargo tons of cargo has been fenced for KCr$profit.\n"; if( $dmg > 0 && $port =~ /A|B/ ) { my $repairCost = &roll() * 100 + int($week/5)*10; print "The drydock is willing to repair our ship for KCr$repa +irCost per point.\n"; if ( $repairCost < $cr ) { print "The $shipname has KCr$cr. How many points would yo +u like them to repair?\n"; my $pts = <STDIN>; redo if ($repairCost * $pts > $cr) || ($pts > $dmg); $cr -= $repairCost * $pts; $dmg -= $pts; $repairs = $pts; $repairCostTotal += $repairCost * $pts; } else { print "Unfortunately, our operating fund is too low for re +pairs.\n"; } } } $dmg += $newDamage; $cr -= 4 * $crew; my $hold = $scargo + $hcargo; # damage report, captain print "The $shipname has $dmg total points of damage.\n" if $dmg > +0; # uh oh, we're done for print "The $shipname has been captured,\nand its crew marooned on a + miserable prison planet!\n*** Game (and Career) Over ***\n" if $dmg +> $hp; exit if $dmg > $hp; # any money left? print " The balance book now stands at KCr${cr}.\n"; if ( $cr < 0 ) { print "You have gone bankrupt, and so are forced into retirement +.\n"; &retire(); } # what would the captain's percentage be then? print " Your shares' value stands at KCr", &calculateScore(), ".\n +\n"; } #__DATA__ #Solpugida 400 100 100

Replies are listed 'Best First'.
Re: Pirate Operations for Traveller
by tekniko (Deacon) on Mar 30, 2004 at 14:34 UTC
    This was written strictly to waste time when I'm on the phone with a misguided user and would rather be doing something else.
      Howdy!

      ...after all, it is a Well Known Fact that piracy is not feasible in the Traveller Universe...

      *grin* *duck* *run*

      yours,
      Michael
        Heh, heh, heh...This program really does not address feasibility. Again, it's a time waster.

        I do agree with you.