use strict; srand; $|++; print "Arr! Welcome to the Traveller Pirate Simulation!\n"; ################################################# # # Setup: determine player info. # ################################################# my ($shipname, $volume, $hold, $cr) = split( ' ', ); unless ($shipname) { print "Please enter your ship's name:\n"; $shipname = ; chomp $shipname; print "How many tons does The $shipname displace?\n"; $volume = ; chomp $volume; print "And how many tons of that is cargo space?\n"; $hold = ; chomp $hold; print "And how many kilocredits are in your operating funds currently?\n"; $cr = ; 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<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 = ; 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< 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" if $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$repairCost per point.\n"; if ( $repairCost < $cr ) { print "The $shipname has KCr$cr. How many points would you like them to repair?\n"; my $pts = ; 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 repairs.\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