-'''
+#!/usr/bin/env python
+"""
sst.py =-- Super Star Trek in Python
This code is a Python translation of a C translation of a FORTRAN original.
-The FORTRANness still shows in many ways, notably the use of 1-origin index
-an a lot of parallel arrays where a more modern language would use structures
-or objects.
+The FORTRANness still shows in many ways, notably the use of a lot of
+parallel arrays where a more modern language would use structures
+or objects. (However, 1-origin array indexing was fixed.)
Dave Matuszek says:
Also, the nav subsystem (enabling automatic course
setting) can be damaged separately from the main computer (which
handles weapons targeting, ETA calculation, and self-destruct).
-'''
+"""
import os, sys, math, curses, time, atexit, readline, cPickle, random, getopt
SSTDOC = "/usr/share/doc/sst/sst.doc"
MAXUNINHAB = 10
PLNETMAX = (NINHAB + MAXUNINHAB)
QUADSIZE = 10
+BASEMIN = 2
BASEMAX = (GALSIZE * GALSIZE / 12)
MAXKLGAME = 127
MAXKLQUAD = 9
FOREVER = 1e30
# These functions hide the difference between 0-origin and 1-origin addressing.
-def VALID_QUADRANT(x, y): return ((x)>=1 and (x)<=GALSIZE and (y)>=1 and (y)<=GALSIZE)
-def VALID_SECTOR(x, y): return ((x)>=1 and (x)<=QUADSIZE and (y)>=1 and (y)<=QUADSIZE)
+def VALID_QUADRANT(x, y): return ((x)>=0 and (x)<GALSIZE and (y)>=0 and (y)<GALSIZE)
+def VALID_SECTOR(x, y): return ((x)>=0 and (x)<QUADSIZE and (y)>=0 and (y)<QUADSIZE)
def square(i): return ((i)*(i))
def distance(c1, c2): return math.sqrt(square(c1.x - c2.x) + square(c1.y - c2.y))
IHALPHA = " "
class coord:
- def __init(self, x=None, y=None):
+ def __init__(self, x=None, y=None):
self.x = x
self.y = y
def invalidate(self):
def is_valid(self):
return self.x != None and self.y != None
def __eq__(self, other):
- return self.x == other.y and self.x == other.y
+ return other != None and self.x == other.y and self.x == other.y
def __add__(self, other):
return coord(self.x+self.x, self.y+self.y)
def __sub__(self, other):
def __hash__(self):
return hash((x, y))
def __str__(self):
- return "%d - %d" % (self.x, self.y)
+ return "%s - %s" % (self.x+1, self.y+1)
+ __repr__ = __str__
class planet:
- def __init(self):
+ def __init__(self):
self.name = None # string-valued if inhabited
self.w = coord() # quadrant located
self.pclass = None # could be ""M", "N", "O", or "destroyed"
- self.crystals = None # could be "mined", "present", "absent"
- self.known = None # could be "unknown", "known", "shuttle_down"
- self.inhabited # is it inhabites?
+ self.crystals = "absent"# could be "mined", "present", "absent"
+ self.known = "unknown" # could be "unknown", "known", "shuttle_down"
+ self.inhabited = False # is it inhabites?
def __str__(self):
return self.name
NOPLANET = None
class quadrant:
- def __init(self):
+ def __init__(self):
self.stars = None
self.planet = None
self.starbase = None
self.status = None # Could be "secure", "distressed", "enslaved"
class page:
- def __init(self):
+ def __init__(self):
self.stars = None
self.starbase = None
self.klingons = None
+def fill2d(size, fillfun):
+ "Fill an empty list in 2D."
+ lst = []
+ for i in range(size):
+ lst.append([])
+ for j in range(size):
+ lst[i].append(fillfun(i, j))
+ return lst
+
class snapshot:
- def __init(self):
+ def __init__(self):
self.snap = False # snapshot taken
- self.crew = None # crew complement
- self.remkl = None # remaining klingons
- self.remcom = None # remaining commanders
- self.nscrem = None # remaining super commanders
- self.rembase = None # remaining bases
- self.starkl = None # destroyed stars
- self.basekl = None # destroyed bases
- self.nromrem = None # Romulans remaining
- self.nplankl = None # destroyed uninhabited planets
- self.nworldkl = None # destroyed inhabited planets
+ self.crew = 0 # crew complement
+ self.remkl = 0 # remaining klingons
+ self.remcom = 0 # remaining commanders
+ self.nscrem = 0 # remaining super commanders
+ self.rembase = 0 # remaining bases
+ self.starkl = 0 # destroyed stars
+ self.basekl = 0 # destroyed bases
+ self.nromrem = 0 # Romulans remaining
+ self.nplankl = 0 # destroyed uninhabited planets
+ self.nworldkl = 0 # destroyed inhabited planets
self.planets = [] # Planet information
- self.date = None # stardate
- self.remres = None # remaining resources
- self.remtime = None # remaining time
+ self.date = 0.0 # stardate
+ self.remres = 0 # remaining resources
+ self.remtime = 0 # remaining time
self.baseq = [] # Base quadrant coordinates
- for i in range(BASEMAX+1):
+ for i in range(BASEMAX):
self.baseq.append(coord())
self.kcmdr = [] # Commander quadrant coordinates
- for i in range(QUADSIZE+1):
+ for i in range(QUADSIZE):
self.kcmdr.append(coord())
self.kscmdr = coord() # Supercommander quadrant coordinates
- self.galaxy = [] # The Galaxy (subscript 0 not used)
- for i in range(GALSIZE+1):
- self.chart.append([])
- for j in range(GALSIZE+1):
- self.galaxy[i].append(quadrant())
- self.chart = [] # the starchart (subscript 0 not used)
- for i in range(GALSIZE+1):
- self.chart.append([])
- for j in range(GALSIZE+1):
- self.chart[i].append(page())
+ # the galaxy (subscript 0 not used)
+ self.galaxy = fill2d(GALSIZE, lambda i, j: quadrant())
+ # the starchart (subscript 0 not used)
+ self.chart = fill2d(GALSIZE, lambda i, j: page())
class event:
def __init__(self):
class gamestate:
def __init__(self):
self.options = None # Game options
- self.state = None # A snapshot structure
- self.snapsht = None # Last snapshot taken for time-travel purposes
- self.quad = [[IHDOT * (QUADSIZE+1)] * (QUADSIZE+1)] # contents of our quadrant
- self.kpower = [[0 * (QUADSIZE+1)] * (QUADSIZE+1)] # enemy energy levels
- self.kdist = [[0 * (QUADSIZE+1)] * (QUADSIZE+1)] # enemy distances
- self.kavgd = [[0 * (QUADSIZE+1)] * (QUADSIZE+1)] # average distances
+ self.state = snapshot() # A snapshot structure
+ self.snapsht = snapshot() # Last snapshot taken for time-travel purposes
+ self.quad = fill2d(QUADSIZE, lambda i, j: IHDOT) # contents of our quadrant
+ self.kpower = fill2d(QUADSIZE, lambda i, j: 0.0) # enemy energy levels
+ self.kdist = fill2d(QUADSIZE, lambda i, j: 0.0) # enemy distances
+ self.kavgd = fill2d(QUADSIZE, lambda i, j: 0.0) # average distances
self.damage = [0.0] * NDEVICES # damage encountered
- self.future = [0.0] * NEVENTS # future events
+ self.future = [] # future events
for i in range(NEVENTS):
self.future.append(event())
self.passwd = None; # Self Destruct password
- self.ks = [[0 * (QUADSIZE+1)] * (QUADSIZE+1)] # enemy sector locations
+ self.ks = fill2d(QUADSIZE, lambda i, j: coord()) # enemy sector locations
self.quadrant = None # where we are in the large
self.sector = None # where we are in the small
self.tholian = None # coordinates of Tholian
if not irun:
# avoid intruding on another commander's territory
if ienm == IHC:
- for n in range(1, game.state.remcom+1):
+ for n in range(game.state.remcom):
if game.state.kcmdr[n] == iq:
return False
# refuse to leave if currently attacking starbase
unschedule(FSCDBAS)
game.state.kscmdr=iq
else:
- for n in range(1, game.state.remcom+1):
+ for n in range(game.state.remcom):
if game.state.kcmdr[n] == game.quadrant:
game.state.kcmdr[n]=iq
break
attempts = 0; # Settle mysterious hang problem
while attempts < 20 and not success:
attempts += 1
- if look.x < 1 or look.x > QUADSIZE:
+ if look.x < 0 or look.x >= QUADSIZE:
if motion < 0 and tryexit(look, ienm, loccom, irun):
return
if krawlx == mx or my == 0:
break
look.x = next.x + krawlx
krawlx = -krawlx
- elif look.y < 1 or look.y > QUADSIZE:
+ elif look.y < 0 or look.y >= QUADSIZE:
if motion < 0 and tryexit(look, ienm, loccom, irun):
return
if krawly == my or mx == 0:
# Figure out which Klingon is the commander (or Supercommander)
# and do move
if game.comhere:
- for i in range(1, game.nenhere+1):
+ for i in range(game.nenhere):
w = game.ks[i]
if game.quad[w.x][w.y] == IHC:
movebaddy(w, i, IHC)
break
if game.ishere:
- for i in range(1, game.nenhere+1):
+ for i in range(game.nenhere):
w = game.ks[i]
if game.quad[w.x][w.y] == IHS:
movebaddy(w, i, IHS)
# Move these last so they can base their actions on what the
# commander(s) do.
if game.skill >= SKILL_EXPERT and (game.options & OPTION_MVBADDY):
- for i in range(1, game.nenhere+1):
+ for i in range(game.nenhere):
w = game.ks[i]
if game.quad[w.x][w.y] == IHK or game.quad[w.x][w.y] == IHR:
movebaddy(w, i, game.quad[w.x][w.y])
return 1
if avoid:
# Avoid quadrants with bases if we want to avoid Enterprise
- for i in range(1, game.state.rembase+1):
+ for i in range(game.state.rembase):
if game.state.baseq[i] == iq:
return True
if game.justin and not game.iscate:
game.ishere = False
game.ientesc = False
unschedule(FSCDBAS)
- for i in range(1, game.nenhere+1):
+ for i in range(game.nenhere):
if game.quad[game.ks[i].x][game.ks[i].y] == IHS:
break
game.quad[game.ks[i].x][game.ks[i].y] = IHDOT
unschedule(FSCMOVE)
return
sc = game.state.kscmdr
- for i in range(1, game.state.rembase+1):
+ for i in range(game.state.rembase):
basetbl.append((i, distance(game.state.baseq[i], sc)))
if game.state.rembase > 1:
basetbl.sort(lambda x, y: cmp(x[1]. y[1]))
# look for nearest base without a commander, no Enterprise, and
# without too many Klingons, and not already under attack.
ifindit = iwhichb = 0
- for i2 in range(1, game.state.rembase+1):
+ for i2 in range(game.state.rembase):
i = basetbl[i2][0]; # bug in original had it not finding nearest
ibq = game.state.baseq[i]
if ibq == game.quadrant or ibq == game.battle or \
continue
# if there is a commander, and no other base is appropriate,
# we will take the one with the commander
- for j in range(1, game.state.remcom+1):
+ for j in range(game.state.remcom):
if ibq == game.state.kcmdr[j] and ifindit!= 2:
ifindit = 2
iwhichb = i
if game.state.rembase == 0:
unschedule(FSCMOVE)
else:
- for i in range(1, game.state.rembase+1):
+ for i in range(game.state.rembase):
ibq = game.state.baseq[i]
if ibq == game.state.kscmdr and game.state.kscmdr == game.battle:
# attack the base
if not game.ithere or game.justin:
return
- if game.tholian.x == 1 and game.tholian.y == 1:
- idx = 1; idy = QUADSIZE
- elif game.tholian.x == 1 and game.tholian.y == QUADSIZE:
- idx = QUADSIZE; idy = QUADSIZE
- elif game.tholian.x == QUADSIZE and game.tholian.y == QUADSIZE:
- idx = QUADSIZE; idy = 1
- elif game.tholian.x == QUADSIZE and game.tholian.y == 1:
- idx = 1; idy = 1
+ if game.tholian.x == 0 and game.tholian.y == 0:
+ idx = 0; idy = QUADSIZE-1
+ elif game.tholian.x == 0 and game.tholian.y == QUADSIZE-1:
+ idx = QUADSIZE-1; idy = QUADSIZE-1
+ elif game.tholian.x == QUADSIZE-1 and game.tholian.y == QUADSIZE-1:
+ idx = QUADSIZE-1; idy = 0
+ elif game.tholian.x == QUADSIZE-1 and game.tholian.y == 0:
+ idx = 0; idy = 0
else:
# something is wrong!
game.ithere = False
game.ks[game.nenhere] = game.tholian
# check to see if all holes plugged
- for i in range(1, QUADSIZE+1):
- if game.quad[1][i]!=IHWEB and game.quad[1][i]!=IHT:
+ for i in range(QUADSIZE):
+ if game.quad[0][i]!=IHWEB and game.quad[0][i]!=IHT:
return
if game.quad[QUADSIZE][i]!=IHWEB and game.quad[QUADSIZE][i]!=IHT:
return
- if game.quad[i][1]!=IHWEB and game.quad[i][1]!=IHT:
+ if game.quad[i][0]!=IHWEB and game.quad[i][0]!=IHT:
return
if game.quad[i][QUADSIZE]!=IHWEB and game.quad[i][QUADSIZE]!=IHT:
return
return None
elif iquad in (IHR, IHK): # Hit a regular enemy
# find the enemy
- for ll in range(1, game.nenhere+1):
+ for ll in range(game.nenhere):
if w == game.ks[ll]:
break
kp = math.fabs(game.kpower[ll])
elif iquad == IHB: # Hit a base
skip(1)
prout(_("***STARBASE DESTROYED.."))
- for ll in range(1, game.state.rembase+1):
+ for ll in range(game.state.rembase):
if game.state.baseq[ll] == game.quadrant:
game.state.baseq[ll]=game.state.baseq[game.state.rembase]
break
# Stas Sergeev added the possibility that
# you can shove the Thingy and piss it off.
# It then becomes an enemy and may fire at you.
- #
+ #
+ global iqengry
iqengry = True
shoved = True
return None
game.quad[w.x][w.y]=IHDOT
game.quad[jw.x][jw.y]=iquad
prout(_(" displaced by blast to Sector %s ") % jw)
- for ll in range(1, game.nenhere+1):
+ for ll in range(game.nenhere):
game.kdist[ll] = game.kavgd[ll] = distance(game.sector,game.ks[ll])
sortklings()
return None
moveklings()
# if no enemies remain after movement, we're done
- if game.nenhere==0 or (game.nenhere==1 and iqhere and not iqengry):
+ if game.nenhere==0 or (game.nenhere==1 and thing == game.quadrant and not iqengry):
return
# set up partial hits if attack happens during shield status change
if game.skill <= SKILL_FAIR:
where = "sector"
- for loop in range(1, game.nenhere+1):
+ for loop in range(game.nenhere):
if game.kpower[loop] < 0:
continue; # too weak to attack
# compute hit strength and diminish shield power
game.casual += icas
game.state.crew -= icas
# After attack, reset average distance to enemies
- for loop in range(1, game.nenhere+1):
+ for loop in range(game.nenhere):
game.kavgd[loop] = game.kdist[loop]
sortklings()
return;
# Killed a Tholian
game.ithere = False
elif type == IHQUEST:
- # Killed a Thingy
- iqhere = iqengry = False
+ # Killed a Thingy
+ global iqengry
+ iqengry = False
invalidate(thing)
else:
# Some type of a Klingon
game.klhere -= 1
if type == IHC:
game.comhere = False
- for i in range(1, game.state.remcom+1):
+ for i in range(game.state.remcom):
if game.state.kcmdr[i] == game.quadrant:
break
game.state.kcmdr[i] = game.state.kcmdr[game.state.remcom]
# Remove enemy ship from arrays describing local conditions
if is_scheduled(FCDBAS) and game.battle == game.quadrant and type==IHC:
unschedule(FCDBAS)
- for i in range(1, game.nenhere+1):
+ for i in range(game.nenhere):
if game.ks[i] == w:
+ for j in range(i, game.nenhere):
+ game.ks[j] = game.ks[j+1]
+ game.kpower[j] = game.kpower[j+1]
+ game.kavgd[j] = game.kdist[j] = game.kdist[j+1]
+ game.ks[game.nenhere].x = 0
+ game.ks[game.nenhere].y = 0
+ game.kdist[game.nenhere] = 0
+ game.kavgd[game.nenhere] = 0
+ game.kpower[game.nenhere] = 0
+ game.nenhere -= 1
break
- game.nenhere -= 1
- if i <= game.nenhere:
- for j in range(i, game.nenhere+1):
- game.ks[j] = game.ks[j+1]
- game.kpower[j] = game.kpower[j+1]
- game.kavgd[j] = game.kdist[j] = game.kdist[j+1]
- game.ks[game.nenhere+1].x = 0
- game.ks[game.nenhere+1].x = 0
- game.kdist[game.nenhere+1] = 0
- game.kavgd[game.nenhere+1] = 0
- game.kpower[game.nenhere+1] = 0
+ break
return;
def targetcheck(x, y):
if key != IHREAL:
huh()
return
- targ[i][1] = aaitem
+ targ[i][1] = int(aaitem-0.5)
key = scan()
if key != IHREAL:
huh()
return
- targ[i][2] = aaitem
+ targ[i][2] = int(aaitem-0.5)
chew()
course[i] = targetcheck(targ[i][1], targ[i][2])
if course[i] == None:
overheat(rpow)
return True;
-def hittem(doublehits):
+def hittem(hits):
# register a phaser hit on Klingons and Romulans
nenhr2=game.nenhere; kk=1
w = coord()
skip(1)
- for k in range(1, nenhr2+1):
+ for k in range(nenhr2):
wham = hits[k]
if wham==0:
continue
proutn(_("Very small hit on "))
ienm = game.quad[w.x][w.y]
if ienm==IHQUEST:
+ global iqengry
iqengry = True
crmena(False, ienm, "sector", w)
skip(1)
while True:
chew()
if not kz:
- for i in range(1, game.nenhere+1):
+ for i in range(game.nenhere):
irec += math.fabs(game.kpower[i])/(PHASEFAC*math.pow(0.90,game.kdist[i]))*(1.01+0.05*random.random()) + 1.0
kz=1
proutn(_("%d units required. ") % irec)
if game.nenhere:
extra = 0.0
powrem = rpow
- for i in range(1, game.nenhere+1):
+ for i in range(game.nenhere):
hits[i] = 0.0
if powrem <= 0:
continue
skip(1)
elif automode == "MANUAL":
rpow = 0.0
- for k in range(1, game.nenhere+1):
+ for k in range(game.nenhere):
aim = game.ks[k]
ienm = game.quad[aim.x][aim.y]
if msgflag:
return game.future[evtype].date
def schedule(evtype, offset):
- # schedule an event of specified type
+ # schedule an event of specified type
game.future[evtype].date = game.state.date + offset
return game.future[evtype]
if game.condition == "docked":
repair /= game.docfac
# Don't fix Deathray here
- for l in range(0, NDEVICES):
+ for l in range(NDEVICES):
if game.damage[l] > 0.0 and l != DDRAY:
if game.damage[l]-repair > 0.0:
game.damage[l] -= repair
unschedule(FCDBAS)
continue
i = 0
- for j in range(1, game.state.rembase+1):
- for k in range(1, game.state.remcom+1):
+ for j in range(game.state.rembase):
+ for k in range(game.state.remcom):
if game.state.baseq[j] == game.state.kcmdr[k] and \
not game.state.baseq[j] == game.quadrant and \
not game.state.baseq[j] == game.state.kscmdr:
if evcode==FCDBAS:
unschedule(FCDBAS)
# find the lucky pair
- for i in range(1, game.state.remcom+1):
+ for i in range(game.state.remcom):
if game.state.kcmdr[i] == game.battle:
break
if i > game.state.remcom or game.state.rembase == 0 or \
game.quad[scratch.x][scratch.y] = IHDOT
elif iquad == IHB: # Destroy base
game.state.galaxy[game.quadrant.x][game.quadrant.y].starbase = False
- for i in range(1, game.state.rembase+1):
+ for i in range(game.state.rembase):
if game.state.baseq[i] == game.quadrant:
break
game.state.baseq[i] = game.state.baseq[game.state.rembase]
elif iquad == IHK: # kill klingon
deadkl(scratch,iquad, scratch)
elif iquad in (IHC,IHS,IHR): # Damage/destroy big enemies
- for ll in range(1, game.nenhere+1):
+ for ll in range(game.nenhere):
if game.ks[ll] == scratch:
break
game.kpower[ll] -= 800.0 # If firepower is lost, die
# Scheduled supernova -- select star
# logic changed here so that we won't favor quadrants in top
# left of universe
- for nq.x in range(1, GALSIZE+1):
- for nq.y in range(1, GALSIZE+1):
+ for nq.x in range(GALSIZE):
+ for nq.y in range(GALSIZE):
stars += game.state.galaxy[nq.x][nq.y].stars
if stars == 0:
return # nothing to supernova exists
num = random.random()*stars + 1
- for nq.x in range(1, GALSIZE+1):
- for nq.y in range(1, GALSIZE+1):
+ for nq.x in range(GALSIZE):
+ for nq.y in range(GALSIZE):
num -= game.state.galaxy[nq.x][nq.y].stars
if num <= 0:
break
ns = coord()
# we are in the quadrant!
num = random.random()* game.state.galaxy[nq.x][nq.y].stars + 1
- for ns.x in range(1, QUADSIZE+1):
- for ns.y in range(1, QUADSIZE+1):
+ for ns.x in range(QUADSIZE):
+ for ns.y in range(QUADSIZE):
if game.quad[ns.x][ns.y]==IHSTAR:
num -= 1
if num==0:
unschedule(FSCDBAS)
if game.state.remcom:
maxloop = game.state.remcom
- for l in range(1, maxloop+1):
+ for l in range(maxloop):
if game.state.kcmdr[l] == nq:
game.state.kcmdr[l] = game.state.kcmdr[game.state.remcom]
invalidate(game.state.kcmdr[game.state.remcom])
# Destroy any base in supernovaed quadrant
if game.state.rembase:
maxloop = game.state.rembase
- for loop in range(1, maxloop+1):
+ for loop in range(maxloop):
if game.state.baseq[loop] == nq:
game.state.baseq[loop] = game.state.baseq[game.state.rembase]
invalidate(game.state.baseq[game.state.rembase])
rows = linecount = 0 # for paging
stdscr = None
+replayfp = None
fullscreen_window = None
srscan_window = None
report_window = None
lrscan_window = None
message_window = None
prompt_window = None
+curwnd = None
def outro():
"wrap up, either normally or due to signal"
#resetterm()
#echo()
curses.endwin()
- stdout.write('\n')
+ sys.stdout.write('\n')
if logfp:
logfp.close()
def iostart():
- global stdscr
+ global stdscr, rows
#setlocale(LC_ALL, "")
#bindtextdomain(PACKAGE, LOCALEDIR)
#textdomain(PACKAGE)
setwnd(message_window)
else:
global linecount
- stdout.write('\n')
+ sys.stdout.write('\n')
proutn(prompt)
raw_input()
- for j in range(0, rows):
- stdout.write('\n')
+ for j in range(rows):
+ sys.stdout.write('\n')
linecount = 0
def skip(i):
"Skip i lines. Pause game if this would cause a scrolling event."
- while dummy in range(i):
+ for dummy in range(i):
if game.options & OPTION_CURSES:
(y, x) = curwnd.getyx()
(my, mx) = curwnd.getmaxyx()
else:
global linecount
linecount += 1
- if linecount >= rows:
+ if rows and linecount >= rows:
pause_game()
else:
- stdout.write('\n')
+ sys.stdout.write('\n')
def proutn(line):
"Utter a line with no following line feed."
curwnd.addstr(line)
curwnd.refresh()
else:
- stdout.write(line)
+ sys.stdout.write(line)
+ sys.stdout.flush()
def prout(line):
proutn(line)
if replayfp and not replayfp.closed:
line = replayfp.readline()
else:
- sys.stdin.readline()
+ line = raw_input()
if logfp:
logfp.write(line)
+ return line
def setwnd(wnd):
- "Change windows -- OK for this to be a no-op in tty mode."
+ "Change windows -- OK for this to be a no-op in tty mode."
+ global curwnd
if game.options & OPTION_CURSES:
curwnd = wnd
curses.curs_set(wnd == fullscreen_window or wnd == message_window or wnd == prompt_window)
if game.options & OPTION_CURSES:
curwnd.attron(curses.A_REVERSE)
-def commandhook(cmd, before):
- pass
-
#
# Things past this point have policy implications.
#
setwnd(report_window)
report_window.clear()
report_window.move(0, 0)
- status(0)
+ status()
setwnd(lrscan_window)
lrscan_window.clear()
lrscan_window.move(0, 0)
skip(1)
setwnd(status_window)
else:
- proutn(" " * NSYM - len(tx))
- vproutn(data)
+ proutn(" " * (NSYM - len(txt)))
+ proutn(data)
skip(1)
if game.options & OPTION_CURSES:
setwnd(report_window)
# No quadrant change -- compute new avg enemy distances
game.quad[game.sector.x][game.sector.y] = game.ship
if game.nenhere:
- for m in range(1, game.nenhere+1):
+ for m in range(game.nenhere):
finald = distance(w, game.ks[m])
game.kavgd[m] = 0.5 * (finald+game.kdist[m])
game.kdist[m] = finald
sortklings()
if not game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova:
attack(False)
- for m in range(1, game.nenhere+1):
+ for m in range(game.nenhere):
game.kavgd[m] = game.kdist[m]
newcnd()
drawmaps(0)
# Don't do it if being pushed by Nova
if game.nenhere != 0 and not novapush:
newcnd()
- for m in range(1, game.nenhere+1):
+ for m in range(game.nenhere):
finald = distance(w, game.ks[m])
game.kavgd[m] = 0.5 * (finald + game.kdist[m])
#
# possibility that you'll get timewarped instead.
#
n=0
- for m in range(0, NDEVICES):
+ for m in range(NDEVICES):
if game.damage[m]>0:
n += 1
probf=math.pow(1.4,(game.energy+game.shield)/5000.0-1.0)*math.pow(1.3,1.0/(n+1)-1.0)
if key != IHREAL:
huh()
return
- xi = aaitem
+ xi = int(aaitem-0.05)
key = scan()
if key != IHREAL:
huh()
return
- xj = aaitem
+ xj = int(aaitem-0.5)
key = scan()
if key == IHREAL:
# both quadrant and sector specified
ddist = distance(game.base, game.sector)
else:
ddist = FOREVER
- for m in range(1, game.state.rembase+1):
+ for m in range(game.state.rembase):
xdist = QUADSIZE * distance(game.state.baseq[m], game.quadrant)
if xdist < ddist:
ddist = xdist
while True:
# position next to base by trial and error
game.quad[game.sector.x][game.sector.y] = IHDOT
- for l in range(1, QUADSIZE+1):
+ for l in range(QUADSIZE):
game.sector.x = 3.0*random.random() - 1.0 + game.base.x
game.sector.y = 3.0*random.random() - 1.0 + game.base.y
if VALID_SECTOR(game.sector.x, game.sector.y) and \
game.iscraft = "offship" # Galileo disappears
# Resupply ship
game.condition="docked"
- for l in range(0, NDEVICES):
+ for l in range(NDEVICES):
game.damage[l] = 0.0
game.damage[DSHUTTL] = -1
game.energy = game.inenrg = 3000.0
proutn(_("Spock- \"I believe the word is"))
prouts(_(" *ASTONISHING*"))
prout(_(" Mr. Sulu."))
- for i in range(1, QUADSIZE+1):
- for j in range(1, QUADSIZE+1):
+ for i in range(QUADSIZE):
+ for j in range(QUADSIZE):
if game.quad[i][j] == IHDOT:
game.quad[i][j] = IHQUEST
prout(_(" Captain, our quadrant is now infested with"))
def rechart():
# update the chart in the Enterprise's computer from galaxy data
game.lastchart = game.state.date
- for i in range(1, GALSIZE+1):
- for j in range(1, GALSIZE+1):
+ for i in range(GALSIZE):
+ for j in range(GALSIZE):
if game.state.galaxy[i][j].charted:
game.state.chart[i][j].klingons = game.state.galaxy[i][j].klingons
game.state.chart[i][j].starbase = game.state.galaxy[i][j].starbase
if game.state.date > game.lastchart:
prout(_("(Last surveillance update %d stardates ago).") % ((int)(game.state.date-game.lastchart)))
prout(" 1 2 3 4 5 6 7 8")
- for i in range(1, GALSIZE+1):
+ for i in range(GALSIZE):
proutn("%d |" % (i))
- for j in range(1, GALSIZE+1):
+ for j in range(GALSIZE):
if (game.options & OPTION_SHOWME) and i == game.quadrant.x and j == game.quadrant.y:
proutn("<")
else:
proutn(" ")
if game.state.galaxy[i][j].supernova:
- strcpy(buf, "***")
+ show = "***"
elif not game.state.galaxy[i][j].charted and game.state.galaxy[i][j].starbase:
- strcpy(buf, ".1.")
+ show = ".1."
elif game.state.galaxy[i][j].charted:
- sprintf(buf, "%3d" % (game.state.chart[i][j].klingons*100 + game.state.chart[i][j].starbase * 10 + game.state.chart[i][j].stars))
+ show = "%3d" % (game.state.chart[i][j].klingons*100 + game.state.chart[i][j].starbase * 10 + game.state.chart[i][j].stars)
else:
- strcpy(buf, "...")
- proutn(buf)
+ show = "..."
+ proutn(show)
if (game.options & OPTION_SHOWME) and i == game.quadrant.x and j == game.quadrant.y:
proutn(">")
else:
else:
proutn("- ")
-def status(req):
+def status(req=0):
# print status report lines
if not req or req == 1:
prstat(_("Stardate"), _("%.1f, Time Left %.2f") \
% (game.state.date, game.state.remtime))
- elif not req or req == 2:
+ if not req or req == 2:
if game.condition != "docked":
newcnd()
dam = 0
- for t in range(0, NDEVICES):
+ for t in range(NDEVICES):
if game.damage[t]>0:
dam += 1
prstat(_("Condition"), _("%s, %i DAMAGES") % (game.condition.upper(), dam))
- elif not req or req == 3:
+ if not req or req == 3:
prstat(_("Position"), "%s , %s" % (game.quadrant, game.sector))
- elif not req or req == 4:
+ if not req or req == 4:
if damaged(DLIFSUP):
if game.condition == "docked":
- sprintf(s, _("DAMAGED, Base provides"))
+ s = _("DAMAGED, Base provides")
else:
- sprintf(s, _("DAMAGED, reserves=%4.2f") % game.lsupres)
+ s = _("DAMAGED, reserves=%4.2f") % game.lsupres
else:
- sprintf(s, _("ACTIVE"))
+ s = _("ACTIVE")
prstat(_("Life Support"), s)
- elif not req or req == 5:
- prstat(_("Warp Factor"), "%.1f" % (game.warpfac))
- elif not req or req == 6:
+ if not req or req == 5:
+ prstat(_("Warp Factor"), "%.1f" % game.warpfac)
+ if not req or req == 6:
extra = ""
if game.icrystl and (game.options & OPTION_SHOWME):
extra = _(" (have crystals)")
- prstat(_("Energy"), "%.2f%s" % game.energy, extra)
- elif not req or req == 7:
+ prstat(_("Energy"), "%.2f%s" % (game.energy, extra))
+ if not req or req == 7:
prstat(_("Torpedoes"), "%d" % (game.torps))
- elif not req or req == 8:
+ if not req or req == 8:
if damaged(DSHIELD):
- strcpy(s, _("DAMAGED,"))
+ s = _("DAMAGED,")
elif game.shldup:
- strcpy(s, _("UP,"))
+ s = _("UP,")
else:
- strcpy(s, _("DOWN,"))
+ s = _("DOWN,")
data = _(" %d%% %.1f units") \
% (int((100.0*game.shield)/game.inshld + 0.5), game.shield)
- prstat(_("Shields"), s)
- elif not req or req == 9:
+ prstat(_("Shields"), s+data)
+ if not req or req == 9:
prstat(_("Klingons Left"), "%d" \
% (game.state.remkl + game.state.remcom + game.state.nscrem))
- elif not req or req == 10:
+ if not req or req == 10:
if game.options & OPTION_WORLDS:
plnet = game.state.galaxy[game.quadrant.x][game.quadrant.y].planet
if plnet != NOPLANET and game.state.planets[plnet].inhabited:
prout(" 1 2 3 4 5 6 7 8 9 10")
if game.condition != "docked":
newcnd()
- for i in range(1, QUADSIZE+1):
+ for i in range(QUADSIZE):
proutn("%2d " % (i))
- for j in range(1, QUADSIZE+1):
+ for j in range(QUADSIZE):
sectscan(goodScan, i, j)
skip(1)
if scan()!=IHREAL:
huh()
return
- w1.y = aaitem +0.5
+ w1.y = int(aaitem-0.5)
if scan() != IHREAL:
huh()
return
- w1.x = aaitem + 0.5
+ w1.x = int(aaitem-0.5)
if scan() == IHREAL:
- w2.y = aaitem + 0.5
+ w2.y = int(aaitem-0.5)
if scan() != IHREAL:
huh()
return
- w2.x = aaitem + 0.5
+ w2.x = int(aaitem-0.5)
else:
if game.quadrant.y>w1.x:
- w2.x = 1
+ w2.x = 0
else:
- w2.x=QUADSIZE
+ w2.x=QUADSIZE-1
if game.quadrant.x>w1.y:
- w2.y = 1
+ w2.y = 0
else:
- w2.y=QUADSIZE
+ w2.y=QUADSIZE-1
if not VALID_QUADRANT(w1.x, w1.y) or not VALID_SECTOR(w2.x, w2.y):
huh()
co = '?'
else:
co = game.quad[ix][iy]
- printf("%d,%d %c " % (ix, iy, co))
+ printf("%d,%d %c " % (ix+1, iy+1, co))
v += 1
ix = game.sector.x + v.x
iy = game.sector.y + v.y
co = '?'
else:
co = game.quad[ix][iy]
- prout("%c %d,%d\n" % (co, ix, iy))
+ prout("%c %d,%d\n" % (co, ix+1, iy+1))
game.optime = 0.5
game.ididit = True
#endif
def setup(needprompt):
# prepare to play, set up cosmos
- intj, krem, klumper
w = coord()
# Decide how many of everything
game.nprobes = int(3.0*random.random() + 2.0) # Give them 2-4 of these
game.warpfac = 5.0
game.wfacsq = game.warpfac * game.warpfac
- for i in range(0, NDEVICES):
+ for i in range(NDEVICES):
game.damage[i] = 0.0
# Set up assorted game parameters
- invalidate(game.battle)
+ game.battle = coord()
game.state.date = game.indate = 100.0*int(31.0*random.random()+20.0)
game.nkinks = game.nhelp = game.casual = game.abandoned = 0
game.iscate = game.resting = game.imine = game.icrystl = game.icraft = False
game.landed = False
game.alive = True
game.docfac = 0.25
- for i in range(1, GALSIZE+1):
- for j in range(1, GALSIZE+1):
+ for i in range(GALSIZE):
+ for j in range(GALSIZE):
quad = game.state.galaxy[i][j]
quad.charted = 0
quad.planet = NOPLANET
game.lastchart = FOREVER
# Put stars in the galaxy
game.instar = 0
- for i in range(1, GALSIZE+1):
- for j in range(1, GALSIZE+1):
- k = random.random()*9.0 + 1.0
+ for i in range(GALSIZE):
+ for j in range(GALSIZE):
+ k = int(random.random()*9.0 + 1.0)
game.instar += k
game.state.galaxy[i][j].stars = k
# Locate star bases in galaxy
- for i in range(1, game.inbase+1):
+ for i in range(game.inbase):
while True:
while True:
w = randplace(GALSIZE)
contflag = False
# C version: for (j = i-1; j > 0; j--)
# so it did them in the opposite order.
- for j in range(i):
- # Improved placement algorithm to spread out bases
- distq = w.distance(baseq[j])
+ for j in range(1, i):
+ # Improved placement algorithm to spread out bases
+ distq = w.distance(game.state.baseq[j])
if distq < 6.0*(BASEMAX+1-game.inbase) and random.random() < 0.75:
contflag = True
if idebug:
if not game.state.galaxy[w.x][w.y].supernova and \
game.state.galaxy[w.x][w.y].klingons + klump <= MAXKLQUAD:
break
- game.state.galaxy[w.x][w.y].klingons += klump
+ game.state.galaxy[w.x][w.y].klingons += int(klump)
if krem <= 0:
break
# Position Klingon Commander Ships
new.name = systnames[i]
new.inhabited = True
else:
- new.pclass = ("M", "N", "O")[random.random()*3.0]
+ new.pclass = ("M", "N", "O")[random.randint(0, 2)]
if random.random()*1.5: # 1 in 3 chance of crystals
new.crystals = "present"
new.known = "unknown"
new.inhabited = False
game.state.galaxy[w.x][w.y].planet = new
- game.state.plnets.append(new)
+ game.state.planets.append(new)
# Locate Romulans
- for i in range(1, game.state.nromrem+1):
+ for i in range(game.state.nromrem):
w = randplace(GALSIZE)
game.state.galaxy[w.x][w.y].romulans += 1
# Locate the Super Commander
if game.state.nscrem > 0:
while True:
w = randplace(GALSIZE)
- if not game.state.galaxy[w.x][w.y].supernova and game.state.galaxy[w.x][w.y].klingons <= MXKLQUAD:
+ if not game.state.galaxy[w.x][w.y].supernova and game.state.galaxy[w.x][w.y].klingons <= MAXKLQUAD:
break
game.state.kscmdr = w
game.state.galaxy[w.x][w.y].klingons += 1
# Place thing (in tournament game, thingx == -1, don't want one!)
- if thing.x != -1:
+ global thing
+ if thing == None:
thing = randplace(GALSIZE)
- else:
- invalidate(thing)
skip(2)
game.state.snap = False
if game.skill == SKILL_NOVICE:
prout(_("And one (GULP) Super-Commander."))
prout(_("%d stardates.") % int(game.intime))
proutn(_("%d starbases in ") % game.inbase)
- for i in range(1, game.inbase+1):
+ for i in range(game.inbase):
proutn(`game.state.baseq[i]`)
proutn(" ")
skip(2)
prout(_(" YOU'LL NEED IT."))
waitfor()
newqad(False)
- if game.nenhere - iqhere-game.ithere:
+ if game.nenhere - (thing == game.quadrant) - game.ithere:
game.shldup = True
if game.neutz: # bad luck to start in a Romulan Neutral Zone
attack(False)
def choose(needprompt):
- # choose your game type
+ # choose your game type
+ global thing
while True:
game.tourn = 0
game.thawed = False
chew()
continue # We don't want a blank entry
game.tourn = int(aaitem)
- thing.x = -1
random.seed(aaitem)
break
if isit("saved") or isit("frozen"):
return True
if isit("regular"):
break
- proutn(_("What is \""))
- proutn(citem)
- prout("\"?")
+ proutn(_("What is \"%s\"?"), citem)
chew()
while game.length==0 or game.skill==SKILL_NONE:
if scan() == IHALPHA:
# Use parameters to generate initial values of things
game.damfac = 0.5 * game.skill
- game.state.rembase = 2.0 + random.random()*(BASEMAX-2.0)
+ game.state.rembase = random.randint(BASEMIN, BASEMAX)
game.inbase = game.state.rembase
game.inplan = 0
if game.options & OPTION_PLANETS:
- game.inplan += (MAXUNINHAB/2) + (MAXUNINHAB/2+1)*random.random()
+ game.inplan += int((MAXUNINHAB/2) + (MAXUNINHAB/2+1)*random.random())
if game.options & OPTION_WORLDS:
- game.inplan += NINHAB
- game.state.nromrem = game.inrom = (2.0+random.random())*game.skill
+ game.inplan += int(NINHAB)
+ game.state.nromrem = game.inrom = int((2.0+random.random())*game.skill)
game.state.nscrem = game.inscom = (game.skill > SKILL_FAIR)
game.state.remtime = 7.0 * game.length
game.intime = game.state.remtime
game.state.remkl = game.inkling = 2.0*game.intime*((game.skill+1 - 2*random.random())*game.skill*0.1+.15)
- game.incom = game.skill + 0.0625*game.inkling*random.random()
+ game.incom = int(game.skill + 0.0625*game.inkling*random.random())
game.state.remcom = min(10, game.incom)
game.incom = game.state.remcom
game.state.remres = (game.inkling+4*game.incom)*game.intime
# set up a new state of quadrant, for when we enter or re-enter it
w = coord()
game.justin = True
- invalidate(game.base)
game.klhere = 0
game.comhere = False
- invalidate(game.plnet)
game.ishere = False
game.irhere = 0
game.iplnet = 0
game.landed = False
game.ientesc = False
game.ithere = False
- iqhere = False
+ global iqengry
iqengry = False
game.iseenit = False
if game.iscate:
# Attempt to escape Super-commander, so tbeam back!
game.iscate = False
game.ientesc = True
- # Clear quadrant
- for i in range(1, QUADSIZE+1):
- for j in range(1, QUADSIZE+1):
- game.quad[i][j] = IHDOT
q = game.state.galaxy[game.quadrant.x][game.quadrant.y]
# cope with supernova
if q.supernova:
if q.klingons:
w.x = w.y = 0 # quiet a gcc warning
# Position ordinary Klingons
- for i in range(1, game.klhere+1):
+ for i in range(game.klhere):
w = newkling(i)
# If we need a commander, promote a Klingon
- for i in range(1, game.state.remcom+1):
- if same(game.state.kcmdr[i], game.quadrant):
+ for i in range(game.state.remcom):
+ if game.state.kcmdr[i] == game.quadrant:
break
if i <= game.state.remcom:
# If we need a super-commander, promote a Klingon
if same(game.quadrant, game.state.kscmdr):
- game.quad[game.ks[1].x][game.ks[1].y] = IHS
+ game.quad[game.ks[0].x][game.ks[0].y] = IHS
game.kpower[1] = 1175.0 + 400.0*random.random() + 125.0*game.skill
game.iscate = (game.state.remkl > 1)
game.ishere = True
# Put in Romulans if needed
- for i in range(game.klhere+1, game.nenhere+1):
+ for i in range(game.klhere, game.nenhere):
w = dropin(IHR)
game.ks[i] = w
game.kdist[i] = game.kavgd[i] = distance(game.sector, w)
# If quadrant needs a planet, put it in
if q.planet != NOPLANET:
game.iplnet = q.planet
- if game.state.planets[q.planet].inhabited == UNINHABITED:
+ if not q.planet.inhabited:
game.plnet = dropin(IHP)
else:
game.plnet = dropin(IHW)
# Check for condition
newcnd()
# And finally the stars
- for i in range(1, q.stars+1):
+ for i in range(q.stars):
dropin(IHSTAR)
# Check for RNZ
if shutup==0:
# Put in THING if needed
- if same(thing, game.quadrant):
+ global thing
+ if thing == game.quadrant:
w = dropin(IHQUEST)
thing = randplace(GALSIZE)
game.nenhere += 1
- iqhere = True
game.ks[game.nenhere] = w
game.kdist[game.nenhere] = game.kavgd[game.nenhere] = \
distance(game.sector, w)
(game.skill == SKILL_GOOD and random.random() <= 0.05) or \
(game.skill > SKILL_GOOD and random.random() <= 0.08):
while True:
- game.tholian.x = random.choice((1, QUADSIZE))
- game.tholian.y = random.choice((1, QUADSIZE))
+ game.tholian.x = random.choice((0, QUADSIZE-1))
+ game.tholian.y = random.choice((0, QUADSIZE-1))
if game.quad[game.tholian.x][game.tholian.y] == IHDOT:
break
game.quad[game.tholian.x][game.tholian.y] = IHT
distance(game.sector, game.tholian)
game.kpower[game.nenhere] = random.random()*400.0 +100.0 +25.0*game.skill
# Reserve unoccupied corners
- if game.quad[1][1]==IHDOT:
- game.quad[1][1] = 'X'
- if game.quad[1][QUADSIZE]==IHDOT:
- game.quad[1][QUADSIZE] = 'X'
- if game.quad[QUADSIZE][1]==IHDOT:
- game.quad[QUADSIZE][1] = 'X'
- if game.quad[QUADSIZE][QUADSIZE]==IHDOT:
- game.quad[QUADSIZE][QUADSIZE] = 'X'
+ if game.quad[0][0]==IHDOT:
+ game.quad[0][0] = 'X'
+ if game.quad[0][QUADSIZE-1]==IHDOT:
+ game.quad[0][QUADSIZE-1] = 'X'
+ if game.quad[QUADSIZE-1][0]==IHDOT:
+ game.quad[QUADSIZE-1][0] = 'X'
+ if game.quad[QUADSIZE-1][QUADSIZE-1]==IHDOT:
+ game.quad[QUADSIZE-1][QUADSIZE-1] = 'X'
sortklings()
# Put in a few black holes
# Take out X's in corners if Tholian present
if game.ithere:
- if game.quad[1][1]=='X':
- game.quad[1][1] = IHDOT
- if game.quad[1][QUADSIZE]=='X':
- game.quad[1][QUADSIZE] = IHDOT
- if game.quad[QUADSIZE][1]=='X':
- game.quad[QUADSIZE][1] = IHDOT
- if game.quad[QUADSIZE][QUADSIZE]=='X':
- game.quad[QUADSIZE][QUADSIZE] = IHDOT
+ if game.quad[0][0]=='X':
+ game.quad[0][0] = IHDOT
+ if game.quad[0][QUADSIZE-1]=='X':
+ game.quad[0][QUADSIZE-1] = IHDOT
+ if game.quad[QUADSIZE-1][0]=='X':
+ game.quad[QUADSIZE-1][0] = IHDOT
+ if game.quad[QUADSIZE-1][QUADSIZE-1]=='X':
+ game.quad[QUADSIZE-1][QUADSIZE-1] = IHDOT
def sortklings():
# sort Klingons by distance from us
# The author liked bubble sort. So we will use it. :-(
- if game.nenhere-iqhere-game.ithere < 2:
+ if game.nenhere-(thing==game.quadrant)-game.ithere < 2:
return
while True:
sw = False
- for j in range(1, game.nenhere):
+ for j in range(game.nenhere):
if game.kdist[j] > game.kdist[j+1]:
sw = True
t = game.kdist[j]
else:
game.passwd = ""
for i in range(3):
- game.passwd[i] += chr(97+int(random.random()*25))
+ game.passwd += chr(97+int(random.random()*25))
# Code from sst.c begins here
k = 0
proutn(_("LEGAL COMMANDS ARE:"))
for key in commands:
- if ACCEPT(cmd):
+ if ACCEPT(key):
if k % 5 == 0:
skip(1)
proutn("%-12s " % key)
clrscr()
setwnd(message_window)
clrscr()
- cmd = citem.upoper
- if cmd not in commands:
+ candidates = filter(lambda x: x.startswith(citem.upper()),
+ commands)
+ if len(candidates) == 1:
+ cmd = candidates[0]
+ break
+ else:
listCommands()
continue
- commandhook(commands[i].name, True)
if cmd == "SRSCAN": # srscan
srscan()
elif cmd == "STATUS": # status
- status(0)
+ status()
elif cmd == "REQUEST": # status request
request()
elif cmd == "LRSCAN": # long range scan
# elif cmd == "VISUAL":
# visual() # perform visual scan
#endif
- commandhook(commands[i].name, False)
while True:
if game.alldone:
break # Game has ended
def randplace(size):
# choose a random location
w = coord()
- w.x = random.randint(1, size)
- w.y = random.randint(1, size)
+ w.x = random.randint(0, size-1)
+ w.y = random.randint(0, size-1)
return w
def chew():
+ # Demand input for next scan
global inqueue
- inqueue = []
+ inqueue = None
def chew2():
# return IHEOL next time
global inqueue
- inqueue = ["\n"]
+ inqueue = []
def scan():
# Get a token from the user
- global inqueue
+ global inqueue, line, citem
aaitem = 0.0
citem = ''
# Read a line if nothing here
- if line == '\n':
- line = ''
- return IHEOL
- elif line == '':
+ if inqueue == None:
line = cgetline()
if curwnd==prompt_window:
clrscr()
setwnd(message_window)
clrscr()
- # Skip leading white space
- line = line.lstrip()
- # Nothing left
- if not line:
- return IHEOL
- else:
- inqueue += line.split()
+ # Skip leading white space
+ line = line.lstrip()
+ if line:
+ inqueue = line.split()
+ else:
+ inqueue = []
+ return IHEOL
+ elif not inqueue:
+ return IHEOL
# From here on in it's all looking at the queue
citem = inqueue.pop(0)
if citem == IHEOL:
try:
aaitem = float(citem)
return IHREAL
- except ValuError:
+ except ValueError:
pass
# Treat as alpha
citem = citem.lower()
prout(_("Beg your pardon, Captain?"))
def isit(s):
- # compares s to citem and returns true if it matches to the length of s
- return citem.startswith(s)
+ # compares s to citem and returns true if it matches to the length of s
+ return s.startswith(citem)
def debugme():
# access to the internals for debugging
game.lsupres = game.inlsr
proutn("Reset damage? ")
if ja() == True:
- for i in range(0, NDEVICES):
+ for i in range(NDEVICES):
if game.damage[i] > 0.0:
game.damage[i] = 0.0
proutn("Toggle debug flag? ")
atover(True)
if __name__ == '__main__':
- line = ""
+ global line, thing, game, idebug, iqengry
+ game = citem = aaitem = inqueue = None
+ line = ''
thing = coord()
+ iqengry = False
game = gamestate()
+ idebug = 0
game.options = OPTION_ALL &~ (OPTION_IOMODES | OPTION_SHOWME | OPTION_PLAIN | OPTION_ALMY)
- if os.getenv("TERM"):
- game.options |= OPTION_CURSES | OPTION_SHOWME
- else:
- game.options |= OPTION_TTY
+ # Disable curses mode until the game logic is working.
+ # if os.getenv("TERM"):
+ # game.options |= OPTION_CURSES | OPTION_SHOWME
+ # else:
+ game.options |= OPTION_TTY
seed = time.time()
(options, arguments) = getopt.getopt(sys.argv[1:], "r:tx")
for (switch, val) in options:
- if switch == 'r':
+ if switch == '-r':
try:
replayfp = open(optarg, "r")
except IOError:
os.exit(1)
game.options |= OPTION_TTY
game.options &=~ OPTION_CURSES
- elif switch == 't':
+ elif switch == '-t':
game.options |= OPTION_TTY
game.options &=~ OPTION_CURSES
- elif switch == 'x':
+ elif switch == '-x':
idebug = True
else:
sys.stderr.write("usage: sst [-t] [-x] [startcommand...].\n")
random.seed(seed)
iostart()
-
- for i in range(optind, argc):
- line += sys.argv[i]
- line += " "
+ if arguments:
+ inqueue = arguments
+ else:
+ inqueue = None
while True: # Play a game
setwnd(fullscreen_window)
clrscr()
prelim()
- setup(line[0] == '\0')
+ setup(needprompt=not inqueue)
if game.alldone:
score()
game.alldone = False