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
game.state.kscmdr = iq
game.state.galaxy[game.state.kscmdr.i][game.state.kscmdr.j].klingons += 1
if game.state.kscmdr==game.quadrant:
- # SC has scooted, Remove him from current quadrant
+ # SC has scooted, remove him from current quadrant
game.iscate=False
game.isatb=0
game.ientesc = False
if action=="NONE":
proutn(_("Do you wish to change shield energy? "))
if ja() == True:
- proutn(_("Energy to transfer to shields- "))
action = "NRG"
elif damaged(DSHIELD):
prout(_("Shields damaged and down."))
while scanner.next() != "IHREAL":
scanner.chew()
proutn(_("Energy to transfer to shields- "))
+ nrg = scanner.real
scanner.chew()
- if scanner.real == 0:
+ if nrg == 0:
return
- if scanner.real > game.energy:
+ if nrg > game.energy:
prout(_("Insufficient ship energy."))
return
game.ididit = True
- if game.shield+scanner.real >= game.inshld:
+ if game.shield+nrg >= game.inshld:
prout(_("Shield energy maximized."))
- if game.shield+scanner.real > game.inshld:
+ if game.shield+nrg > game.inshld:
prout(_("Excess energy requested returned to ship energy"))
game.energy -= game.inshld-game.shield
game.shield = game.inshld
return
- if scanner.real < 0.0 and game.energy-scanner.real > game.inenrg:
+ if nrg < 0.0 and game.energy-nrg > game.inenrg:
# Prevent shield drain loophole
skip(1)
prout(_("Engineering to bridge--"))
prout(_(" I can't drain the shields."))
game.ididit = False
return
- if game.shield+scanner.real < 0:
+ if game.shield+nrg < 0:
prout(_("All shield energy transferred to ship."))
game.energy += game.shield
game.shield = 0.0
return
proutn(_("Scotty- \""))
- if scanner.real > 0:
+ if nrg > 0:
prout(_("Transferring energy to shields.\""))
else:
prout(_("Draining energy from shields.\""))
- game.shield += scanner.real
- game.energy -= scanner.real
+ game.shield += nrg
+ game.energy -= nrg
return
def randdevice():
15, # DCOMPTR: computer 1.5%
20, # NAVCOMP: navigation system 2.0%
75, # DTRANSP: transporter 7.5%
- 20, # DSHCTRL: high-speed shield controller 2.0%
+ 20, # DSHCTRL: high-speed shield controller 2.0%
10, # DDRAY: death ray 1.0%
30, # DDSP: deep-space probes 3.0%
)
- idx = randrange(1000) # weights must sum to 1000
+ assert(sum(weights) == 1000)
+ idx = randrange(1000)
sum = 0
for (i, w) in enumerate(weights):
sum += w
# 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:
else:
prout(_("Uhura- Starfleet reports increased Klingon activity"))
if q.planet != None:
- proutn(_("near %s") % q.planet)
+ proutn(_("near %s ") % q.planet)
prout(_("in Quadrant %s.") % w)
def wait():
klship = 1
else:
klship = 2
- if not game.gamewon:
- game.state.nromrem = 0 # None captured if no win
iscore = 10*(game.inkling - game.state.remkl) \
+ 50*(game.incom - len(game.state.kcmdr)) \
+ ithperd + iwon \
if game.inrom - game.state.nromrem:
prout(_("%6d Romulans destroyed %5d") %
(game.inrom - game.state.nromrem, 20*(game.inrom - game.state.nromrem)))
- if game.state.nromrem:
+ if game.state.nromrem and game.gamewon:
prout(_("%6d Romulans captured %5d") %
(game.state.nromrem, game.state.nromrem))
if game.inkling - game.state.remkl:
(game.state.nplankl, -10*game.state.nplankl))
if (game.options & OPTION_WORLDS) and game.state.nworldkl:
prout(_("%6d inhabited planets destroyed by your action %5d") %
- (game.state.nplankl, -300*game.state.nworldkl))
+ (game.state.nworldkl, -300*game.state.nworldkl))
if game.state.basekl:
prout(_("%6d bases destroyed by your action %5d") %
(game.state.basekl, -100*game.state.basekl))
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)
skip(1)
prouts(_("Scotty- \"Keep your fingers crossed, Sir!\""))
skip(1)
- if with(game.cryprob):
+ if withprob(game.cryprob):
prouts(_(" \"Activating now! - - No good! It's***"))
skip(2)
prouts(_("***RED ALERT! RED A*L********************************"))
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()
# Choose game options -- added by ESR for SST2K
if scanner.next() != "IHALPHA":
scanner.chew()
- proutn(_("Choose your game style (or just press enter): "))
+ proutn(_("Choose your game style (plain, almy, fancy or just press enter): "))
scanner.next()
if scanner.sees("plain"):
# Approximates the UT FORTRAN version.
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()
sys.stderr.write("usage: sst [-t] [-x] [startcommand...].\n")
raise SystemExit, 1
# where to save the input in case of bugs
+ if "TMPDIR" in os.environ:
+ tmpdir = os.environ['TMPDIR']
+ else:
+ tmpdir = "/tmp"
try:
- logfp = open("/usr/tmp/sst-input.log", "w")
+ logfp = open(os.path.join(tmpdir, "sst-input.log"), "w")
except IOError:
sys.stderr.write("sst: warning, can't open logfile\n")
+ sys.exit(1)
if logfp:
logfp.write("# seed %s\n" % seed)
logfp.write("# options %s\n" % " ".join(arguments))