See the doc/HACKING file in the distribution for designers notes and advice
ion how to modify (and how not to modify!) this code.
"""
-import os, sys, math, curses, time, readline, cPickle, random, copy, gettext
+import os, sys, math, curses, time, readline, cPickle, random, copy, gettext, getpass
SSTDOC = "/usr/share/doc/sst/sst.doc"
DOC_NAME = "sst.doc"
def _(str): return gettext.gettext(str)
-PHASEFAC = 2.0
-GALSIZE = 8
-NINHAB = (GALSIZE * GALSIZE / 2)
-MAXUNINHAB = 10
-PLNETMAX = (NINHAB + MAXUNINHAB)
-QUADSIZE = 10
-BASEMIN = 2
-BASEMAX = (GALSIZE * GALSIZE / 12)
-MAXKLGAME = 127
-MAXKLQUAD = 9
-FULLCREW = 428 # BSD Trek was 387, that's wrong
-FOREVER = 1e30
-MAXBURST = 3
-MINCMDR = 10
+GALSIZE = 8 # Galaxy size in quadrants
+NINHAB = (GALSIZE * GALSIZE / 2) # Number of inhabited worlds
+MAXUNINHAB = 10 # Maximum uninhabited worlds
+QUADSIZE = 10 # Quadrant size in sectors
+BASEMIN = 2 # Minimum starbases
+BASEMAX = (GALSIZE * GALSIZE / 12) # Maximum starbases
+MAXKLGAME = 127 # Maximum Klingons per game
+MAXKLQUAD = 9 # Maximum Klingons per quadrant
+FULLCREW = 428 # Crew size. BSD Trek was 387, that's wrong
+FOREVER = 1e30 # Time for the indefinite future
+MAXBURST = 3 # Max # of torps you can launch in one turn
+MINCMDR = 10 # Minimum number of Klingon commanders
+DOCKFAC = 0.25 # Repair faster when docked
+PHASEFAC = 2.0 # Unclear what this is, it was in the C version
class TrekError:
pass
self.energy = 0.0 # energy level
self.shield = 0.0 # shield level
self.warpfac = 0.0 # warp speed
- self.wfacsq = 0.0 # squared warp factor
self.lsupres = 0.0 # life support reserves
self.optime = 0.0 # time taken by current operation
- self.docfac = 0.0 # repair factor when docking (constant?)
self.damfac = 0.0 # damage factor
self.lastchart = 0.0 # time star chart was last updated
self.cryprob = 0.0 # probability that crystal will work
FCREW = 21
def withprob(p):
- v = random.random()
- #logfp.write("# withprob(%s) -> %f (%s) at %s\n" % (p, v, v<p, traceback.extract_stack()[-2][1:]))
- return v < p
+ return random.random() < p
def randrange(*args):
- v = random.randrange(*args)
- #logfp.write("# randrange%s -> %s at %s\n" % (args, v, traceback.extract_stack()[-2][1:]))
- return v
+ return random.randrange(*args)
def randreal(*args):
v = random.random()
if len(args) == 1:
- v *= args[0] # returns from [0, args[0])
+ v *= args[0] # from [0, args[0])
elif len(args) == 2:
- v = args[0] + v*(args[1]-args[0]) # returns from [args[0], args[1])
- #logfp.write("# randreal%s -> %s at %s\n" % (args, v, traceback.extract_stack()[-2][1:]))
+ v = args[0] + v*(args[1]-args[0]) # from [args[0], args[1])
return v
# Code from ai.c begins here
def randdevice():
"Choose a device to damage, at random."
- # Quoth Eric Allman in the code of BSD-Trek:
- # "Under certain conditions you can get a critical hit. This
- # sort of hit damages devices. The probability that a given
- # device is damaged depends on the device. Well protected
- # devices (such as the computer, which is in the core of the
- # ship and has considerable redundancy) almost never get
- # damaged, whereas devices which are exposed (such as the
- # warp engines) or which are particularly delicate (such as
- # the transporter) have a much higher probability of being
- # damaged."
- #
- # This is one place where OPTION_PLAIN does not restore the
- # original behavior, which was equiprobable damage across
- # all devices. If we wanted that, we'd return randrange(NDEVICES)
- # and have done with it. Also, in the original game, DNAVYS
- # and DCOMPTR were the same device.
- #
- # Instead, we use a table of weights similar to the one from BSD Trek.
- # BSD doesn't have the shuttle, shield controller, death ray, or probes.
- # We don't have a cloaking device. The shuttle got the allocation
- # for the cloaking device, then we shaved a half-percent off
- # everything to have some weight to give DSHCTRL/DDRAY/DDSP.
weights = (
105, # DSRSENS: short range scanners 10.5%
105, # DLRSENS: long range scanners 10.5%
120, # DPHASER: phasers 12.0%
120, # DPHOTON: photon torpedoes 12.0%
- 25, # DLIFSUP: life support 2.5%
+ 25, # DLIFSUP: life support 2.5%
65, # DWARPEN: warp drive 6.5%
70, # DIMPULS: impulse engines 6.5%
145, # DSHIELD: deflector shields 14.5%
# Fix devices
repair = xtime
if game.condition == "docked":
- repair /= game.docfac
+ repair /= DOCKFAC
# Don't fix Deathray here
for l in range(NDEVICES):
if game.damage[l] > 0.0 and l != DDRAY:
# Likewise, if in the original time the Galileo was abandoned, but
# was on ship earlier, it would have vanished -- let's restore it.
if game.iscraft == "offship" and not gotit and game.damage[DSHUTTL] >= 0.0:
- prout(_("Checkov- \"Security reports the Galileo has reappeared in the dock!\""))
+ prout(_("Chekov- \"Security reports the Galileo has reappeared in the dock!\""))
game.iscraft = "onship"
# There used to be code to do the actual reconstrction here,
# but the starchart is now part of the snapshotted galaxy state.
prout(_("Spock has reconstructed a correct star chart from memory"))
else:
# Go forward in time
- game.optime = -0.5*game.intime*math.log(randreal())
+ game.optime = expran(0.5*game.intime)
prout(_("You are traveling forward in time %d stardates.") % int(game.optime))
# cheat to make sure no tractor beams occur during time warp
postpone(FTBEAM, game.optime)
jdam = True
prout(" %-26s\t%8.2f\t\t%8.2f" % (device[i],
game.damage[i]+0.05,
- game.docfac*game.damage[i]+0.005))
+ DOCKFAC*game.damage[i]+0.005))
if not jdam:
prout(_("All devices functional."))
game.iscraft = "onship"
game.landed = False
game.alive = True
- game.docfac = 0.25
# Starchart is functional but we've never seen it
game.lastchart = FOREVER
# Put stars in the galaxy
def choose():
"Choose your game type."
- global thing
while True:
- game.tourn = 0
+ game.tourn = game.length = 0
game.thawed = False
game.skill = SKILL_NONE
- game.length = 0
if not scanner.inqueue: # Can start with command line options
proutn(_("Would you like a regular, tournament, or saved game? "))
scanner.next()
drawmaps(1)
while True: # get a command
hitme = False
- game.justin = False
- game.optime = 0.0
+ game.optime = game.justin = False
scanner.chew()
setwnd(prompt_window)
clrscr()
logfp.write("# seed %s\n" % seed)
logfp.write("# options %s\n" % " ".join(arguments))
logfp.write("# recorded by %s@%s on %s\n" % \
- (os.getenv("LOGNAME"),socket.gethostname(),time.ctime()))
+ (getpass.getuser(),socket.gethostname(),time.ctime()))
random.seed(seed)
scanner = sstscanner()
map(scanner.append, arguments)