X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=src%2Fsst.py;h=3e7f2c2a94f4de890e9624e57917445909e53624;hb=63a85c0b15819cc85d8acf7a6ee6e067ff6c4362;hp=3c40cabcea1d7137a8344bd64f96ecacfd83c259;hpb=e67cf36a789c4ab1cd905a9a08e91d219395f538;p=super-star-trek.git diff --git a/src/sst.py b/src/sst.py index 3c40cab..3e7f2c2 100644 --- a/src/sst.py +++ b/src/sst.py @@ -2,10 +2,9 @@ """ 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 a lot of -parallel arrays where a more modern language would use structures -or objects. (However, 1-origin array indexing was fixed.) +This code is a Python translation of a C translation of a FORTRAN +original dating back to 1973. Beautiful Python it is not. But it +works. Dave Matuszek says: @@ -46,11 +45,11 @@ however mine had some feature it didn't have. So I merged its features that I liked. I also took a peek at the DECUS version (a port, less sources, to the PDP-10), and some other variations. -1, Compared to the original UT version, I've changed the "help" command to -"call" and the "terminate" command to "quit" to better match -user expectations. The DECUS version apparently made those changes -as well as changing "freeze" to "save". However I like "freeze". -(Both "freeze" and "save" work in SST2K.) +1, Compared to the original UT version, I've changed the "help" +command to "call" and the "terminate" command to "quit" to better +match user expectations. The DECUS version apparently made those +changes as well as changing "freeze" to "save". However I like +"freeze". (Both "freeze" and "save" work in SST2K.) 2. The experimental deathray originally had only a 5% chance of success, but could be used repeatedly. I guess after a couple @@ -180,7 +179,7 @@ more: the LRSCAN command is no longer needed. (Controlled by OPTION_AUTOSCAN and turned off if game type is "plain" or "almy".) """ -import os,sys,math,curses,time,atexit,readline,cPickle,random,getopt,copy +import os, sys, math, curses, time, readline, cPickle, random, copy SSTDOC = "/usr/share/doc/sst/sst.doc" DOC_NAME = "sst.doc" @@ -227,10 +226,6 @@ IHMATER0 = '-', IHMATER1 = 'o', IHMATER2 = '0' -IHEOL = '\n' -IHREAL = 0.0 -IHALPHA = " " - class coord: def __init__(self, x=None, y=None): self.i = x @@ -260,7 +255,7 @@ class coord: return math.sqrt((self.i - other.i)**2 + (self.j - other.j)**2) def bearing(self, other=None): if not other: other = coord(0, 0) - return 1.90985*math.atan2(self.i-other.i, self.j-other.j) + return 1.90985*math.atan2(self.j-other.j, self.i-other.i) def sgn(self): s = coord() if self.i == 0: @@ -340,9 +335,9 @@ class snapshot: self.baseq = [] # Base quadrant coordinates self.kcmdr = [] # Commander quadrant coordinates self.kscmdr = coord() # Supercommander quadrant coordinates - # the galaxy (subscript 0 not used) + # the galaxy self.galaxy = fill2d(GALSIZE, lambda i, j: quadrant()) - # the starchart (subscript 0 not used) + # the starchart self.chart = fill2d(GALSIZE, lambda i, j: page()) class event: @@ -529,10 +524,8 @@ class gamestate: 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 - self.probex = 0.0 # location of probe - self.probey = 0.0 # - self.probeinx = 0.0 # probe x,y increment - self.probeiny = 0.0 # + self.probe = None # location of probe + self.probein = None # probe i,j increment self.height = 0.0 # height of orbit around planet def recompute(self): # Stas thinks this should be (C expression): @@ -542,7 +535,7 @@ class gamestate: # after killing the last klingon when score is shown -- perhaps also # if the only remaining klingon is SCOM. game.state.remtime = game.state.remres/(game.state.remkl + 4*len(game.state.kcmdr)) -# From enumerated type 'feature' + IHR = 'R' IHK = 'K' IHC = 'C' @@ -562,8 +555,6 @@ IHMATER0 = '-' IHMATER1 = 'o' IHMATER2 = '0' - -# From enumerated type 'FINTYPE' FWON = 0 FDEPLETE = 1 FLIFESUP = 2 @@ -587,10 +578,6 @@ FTRIBBLE = 19 FHOLE = 20 FCREW = 21 -# Log the results of pulling random numbers so we can check determinism. - -import traceback - def withprob(p): v = random.random() #logfp.write("# withprob(%s) -> %f (%s) at %s\n" % (p, v, v
0 and nsteps > mdist:
nsteps = mdist; # don't overshoot
if nsteps > QUADSIZE:
@@ -777,16 +761,7 @@ def movebaddy(enemy):
m.i = 0
if 2.0 * abs(m.j) < abs(game.sector.i-enemy.kloc.i):
m.j = 0
- if m.i != 0:
- if m.i*motion < 0:
- m.i = -1
- else:
- m.i = 1
- if m.j != 0:
- if m.j*motion < 0:
- m.j = -1
- else:
- m.j = 1
+ m = (motion * m).sgn()
next = enemy.kloc
# main move loop
for ll in range(nsteps):
@@ -795,13 +770,13 @@ def movebaddy(enemy):
# Check if preferred position available
look = next + m
if m.i < 0:
- krawlx = 1
+ krawli = 1
else:
- krawlx = -1
+ krawli = -1
if m.j < 0:
- krawly = 1
+ krawlj = 1
else:
- krawly = -1
+ krawlj = -1
success = False
attempts = 0; # Settle mysterious hang problem
while attempts < 20 and not success:
@@ -809,29 +784,29 @@ def movebaddy(enemy):
if look.i < 0 or look.i >= QUADSIZE:
if motion < 0 and tryexit(enemy, look, irun):
return
- if krawlx == m.i or m.j == 0:
+ if krawli == m.i or m.j == 0:
break
- look.i = next.i + krawlx
- krawlx = -krawlx
+ look.i = next.i + krawli
+ krawli = -krawli
elif look.j < 0 or look.j >= QUADSIZE:
if motion < 0 and tryexit(enemy, look, irun):
return
- if krawly == m.j or m.i == 0:
+ if krawlj == m.j or m.i == 0:
break
- look.j = next.j + krawly
- krawly = -krawly
+ look.j = next.j + krawlj
+ krawlj = -krawlj
elif (game.options & OPTION_RAMMING) and game.quad[look.i][look.j] != IHDOT:
# See if enemy should ram ship
if game.quad[look.i][look.j] == game.ship and \
(enemy.type == IHC or enemy.type == IHS):
collision(rammed=True, enemy=enemy)
return
- if krawlx != m.i and m.j != 0:
- look.i = next.i + krawlx
- krawlx = -krawlx
- elif krawly != m.j and m.i != 0:
- look.j = next.j + krawly
- krawly = -krawly
+ if krawli != m.i and m.j != 0:
+ look.i = next.i + krawli
+ krawli = -krawli
+ elif krawlj != m.j and m.i != 0:
+ look.j = next.j + krawlj
+ krawlj = -krawlj
else:
break; # we have failed
else:
@@ -1073,11 +1048,11 @@ def movetholian():
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:
+ if game.quad[QUADSIZE-1][i]!=IHWEB and game.quad[QUADSIZE-1][i]!=IHT:
return
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:
+ if game.quad[i][QUADSIZE-1]!=IHWEB and game.quad[i][QUADSIZE-1]!=IHT:
return
# All plugged up -- Tholian splits
game.quad[game.tholian.kloc.i][game.tholian.kloc.j]=IHWEB
@@ -1096,7 +1071,7 @@ def doshield(shraise):
action = "SHUP"
else:
key = scanner.next()
- if key == IHALPHA:
+ if key == "IHALPHA":
if scanner.sees("transfer"):
action = "NRG"
else:
@@ -1155,7 +1130,7 @@ def doshield(shraise):
game.ididit = True
return
elif action == "NRG":
- while scanner.next() != IHREAL:
+ while scanner.next() != "IHREAL":
scanner.chew()
proutn(_("Energy to transfer to shields- "))
scanner.chew()
@@ -1289,6 +1264,10 @@ def collision(rammed, enemy):
def torpedo(origin, course, dispersion, number, nburst):
"Let a photon torpedo fly"
+ if not damaged(DSRSENS) or game.condition=="docked":
+ setwnd(srscan_window)
+ else:
+ setwnd(message_window)
shoved = False
ac = course + 0.25*dispersion
angle = (15.0-ac)*0.5235988
@@ -1296,17 +1275,12 @@ def torpedo(origin, course, dispersion, number, nburst):
delta = coord(-math.sin(angle), math.cos(angle))
bigger = max(abs(delta.i), abs(delta.j))
delta /= bigger
- x = origin.i; y = origin.j
w = coord(0, 0); jw = coord(0, 0)
- if not damaged(DSRSENS) or game.condition=="docked":
- setwnd(srscan_window)
- else:
- setwnd(message_window)
+ ungridded = copy.copy(origin)
# Loop to move a single torpedo
- for step in range(1, 15+1):
- x += delta.i
- y += delta.j
- w = coord(x, y).snaptogrid()
+ for step in range(1, QUADSIZE*2):
+ ungridded += delta
+ w = ungridded.snaptogrid()
if not VALID_SECTOR(w.i, w.j):
break
iquad=game.quad[w.i][w.j]
@@ -1345,13 +1319,12 @@ def torpedo(origin, course, dispersion, number, nburst):
game.sector = jw
proutn(crmshp())
shoved = True
- elif iquad in (IHC, IHS): # Hit a commander
- if withprob(0.05):
+ elif iquad in (IHC, IHS, IHR, IHK): # Hit a regular enemy
+ # find the enemy
+ if iquad in (IHC, IHS) and withprob(0.05):
prout(crmena(True, iquad, "sector", w) + _(" uses anti-photon device;"))
prout(_(" torpedo neutralized."))
return None
- elif iquad in (IHR, IHK): # Hit a regular enemy
- # find the enemy
for enemy in game.enemies:
if w == enemy.kloc:
break
@@ -1591,7 +1564,7 @@ def attack(torps_ok):
hit = enemy.kpower*math.pow(dustfac,enemy.kavgd)
enemy.kpower *= 0.75
else: # Enemy uses photon torpedo
- #course2 = (enemy.kloc-game.sector).bearing()
+ # We should be able to make the bearing() method work here
course = 1.90985*math.atan2(game.sector.j-enemy.kloc.j, enemy.kloc.i-game.sector.i)
hit = 0
proutn(_("***TORPEDO INCOMING"))
@@ -1743,7 +1716,7 @@ def targetcheck(w):
prout(_(" the Captain's psychological profile.\""))
scanner.chew()
return None
- return 1.90985932*math.atan2(delta.j, delta.i)
+ return delta.bearing()
def photon():
"Launch photon torpedo."
@@ -1760,15 +1733,15 @@ def photon():
# First, get torpedo count
while True:
scanner.next()
- if scanner.token == IHALPHA:
+ if scanner.token == "IHALPHA":
huh()
return
- elif scanner.token == IHEOL or not scanner.waiting():
+ elif scanner.token == "IHEOL" or not scanner.waiting():
prout(_("%d torpedoes left.") % game.torps)
scanner.chew()
proutn(_("Number of torpedoes to fire- "))
continue # Go back around to get a number
- else: # key == IHREAL
+ else: # key == "IHREAL"
n = scanner.int()
if n <= 0: # abort command
scanner.chew()
@@ -1785,24 +1758,24 @@ def photon():
target = []
for i in range(n):
key = scanner.next()
- if i==0 and key == IHEOL:
+ if i==0 and key == "IHEOL":
break; # no coordinate waiting, we will try prompting
- if i==1 and key == IHEOL:
+ if i==1 and key == "IHEOL":
# direct all torpedoes at one target
while i < n:
- target.append(targets[0])
+ target.append(target[0])
course.append(course[0])
i += 1
break
- scanner.push(key)
+ scanner.push(scanner.token)
target.append(scanner.getcoord())
if target[-1] == None:
return
- course.append(targetcheck(target[1]))
- if course[i] == None:
+ course.append(targetcheck(target[-1]))
+ if course[-1] == None:
return
scanner.chew()
- if i == 0:
+ if len(target) == 0:
# prompt for each one
for i in range(n):
proutn(_("Target sector for torpedo number %d- ") % (i+1))
@@ -1966,12 +1939,12 @@ def phasers():
# (That was Tom Almy talking about the C code, I think -- ESR)
while automode=="NOTSET":
key=scanner.next()
- if key == IHALPHA:
+ if key == "IHALPHA":
if scanner.sees("manual"):
if len(game.enemies)==0:
prout(_("There is no enemy present to select."))
scanner.chew()
- key = IHEOL
+ key = "IHEOL"
automode="AUTOMATIC"
else:
automode = "MANUAL"
@@ -1989,7 +1962,7 @@ def phasers():
else:
huh()
return
- elif key == IHREAL:
+ elif key == "IHREAL":
if len(game.enemies)==0:
prout(_("Energy will be expended into space."))
automode = "AUTOMATIC"
@@ -1998,7 +1971,7 @@ def phasers():
else:
automode = "AUTOMATIC"
else:
- # IHEOL
+ # "IHEOL"
if len(game.enemies)==0:
prout(_("Energy will be expended into space."))
automode = "AUTOMATIC"
@@ -2011,10 +1984,10 @@ def phasers():
if ifast:
avail -= 200.0
if automode == "AUTOMATIC":
- if key == IHALPHA and scanner.sees("no"):
+ if key == "IHALPHA" and scanner.sees("no"):
no = True
key = scanner.next()
- if key != IHREAL and len(game.enemies) != 0:
+ if key != "IHREAL" and len(game.enemies) != 0:
prout(_("Phasers locked on target. Energy available: %.2f")%avail)
irec=0
while True:
@@ -2027,13 +2000,13 @@ def phasers():
scanner.chew()
proutn(_("Units to fire= "))
key = scanner.next()
- if key!=IHREAL:
+ if key!="IHREAL":
return
rpow = scanner.real
if rpow > avail:
proutn(_("Energy available= %.2f") % avail)
skip(1)
- key = IHEOL
+ key = "IHEOL"
if not rpow > avail:
break
if rpow<=0:
@@ -2041,7 +2014,7 @@ def phasers():
scanner.chew()
return
key=scanner.next()
- if key == IHALPHA and scanner.sees("no"):
+ if key == "IHALPHA" and scanner.sees("no"):
no = True
if ifast:
game.energy -= 200; # Go and do it!
@@ -2080,7 +2053,7 @@ def phasers():
prout(_("%d expended on empty space.") % int(extra))
elif automode == "FORCEMAN":
scanner.chew()
- key = IHEOL
+ key = "IHEOL"
if damaged(DCOMPTR):
prout(_("Battle computer damaged, manual fire only."))
else:
@@ -2105,11 +2078,11 @@ def phasers():
not game.sector.distance(aim)<2**0.5 and ienm in (IHC, IHS):
prout(cramen(ienm) + _(" can't be located without short range scan."))
scanner.chew()
- key = IHEOL
+ key = "IHEOL"
hits[k] = 0; # prevent overflow -- thanks to Alexei Voitenko
k += 1
continue
- if key == IHEOL:
+ if key == "IHEOL":
scanner.chew()
if itarg and k > kz:
irec=(abs(game.enemies[k].kpower)/(PHASEFAC*math.pow(0.9,game.enemies[k].kdist))) * randreal(1.01, 1.06) + 1.0
@@ -2122,14 +2095,14 @@ def phasers():
proutn(") ")
proutn(_("units to fire at %s- ") % crmena(False, ienm, "sector", aim))
key = scanner.next()
- if key == IHALPHA and scanner.sees("no"):
+ if key == "IHALPHA" and scanner.sees("no"):
no = True
key = scanner.next()
continue
- if key == IHALPHA:
+ if key == "IHALPHA":
huh()
return
- if key == IHEOL:
+ if key == "IHEOL":
if k==1: # Let me say I'm baffled by this
msgflag = True
continue
@@ -2150,7 +2123,7 @@ def phasers():
# zero energy -- abort
scanner.chew()
return
- if key == IHALPHA and scanner.sees("no"):
+ if key == "IHALPHA" and scanner.sees("no"):
no = True
game.energy -= rpow
scanner.chew()
@@ -2382,7 +2355,7 @@ def events():
game.optime -= xtime
if evcode == FSNOVA: # Supernova
announce()
- supernova(False)
+ supernova(None)
schedule(FSNOVA, expran(0.5*game.intime))
if game.state.galaxy[game.quadrant.i][game.quadrant.j].supernova:
return
@@ -2429,12 +2402,14 @@ def events():
for ibq in game.state.baseq:
for cmdr in game.state.kcmdr:
if ibq == cmdr and ibq != game.quadrant and ibq != game.state.kscmdr:
- raise "foundit"
- except "foundit":
- # no match found -- try later
- schedule(FBATTAK, expran(0.3*game.intime))
- unschedule(FCDBAS)
- continue
+ raise ibq
+ else:
+ # no match found -- try later
+ schedule(FBATTAK, expran(0.3*game.intime))
+ unschedule(FCDBAS)
+ continue
+ except coord:
+ pass
# commander + starbase combination found -- launch attack
game.battle = ibq
schedule(FCDBAS, randreal(1.0, 4.0))
@@ -2482,21 +2457,20 @@ def events():
supercommander()
elif evcode == FDSPROB: # Move deep space probe
schedule(FDSPROB, 0.01)
- game.probex += game.probeinx
- game.probey += game.probeiny
- i = (int)(game.probex/QUADSIZE +0.05)
- j = (int)(game.probey/QUADSIZE + 0.05)
+ game.probe += game.probein
+ i = int(round(game.probe.i/float(QUADSIZE)))
+ j = int(round(game.probe.j/float(QUADSIZE)))
if game.probec.i != i or game.probec.j != j:
game.probec.i = i
game.probec.j = j
if not VALID_QUADRANT(i, j) or \
game.state.galaxy[game.probec.i][game.probec.j].supernova:
# Left galaxy or ran into supernova
- if comunicating():
+ if communicating():
announce()
skip(1)
proutn(_("Lt. Uhura- \"The deep space probe "))
- if not VALID_QUADRANT(j, i):
+ if not VALID_QUADRANT(i, j):
proutn(_("has left the galaxy"))
else:
proutn(_("is no longer transmitting"))
@@ -2517,8 +2491,7 @@ def events():
pdest.charted = True
game.proben -= 1 # One less to travel
if game.proben == 0 and game.isarmed and pdest.stars:
- # lets blow the sucker!
- supernova(True, game.probec)
+ supernova(game.probec) # fire in the hole!
unschedule(FDSPROB)
if game.state.galaxy[game.quadrant.i][game.quadrant.j].supernova:
return
@@ -2623,11 +2596,11 @@ def wait():
game.ididit = False
while True:
key = scanner.next()
- if key != IHEOL:
+ if key != "IHEOL":
break
proutn(_("How long? "))
scanner.chew()
- if key != IHREAL:
+ if key != "IHREAL":
huh()
return
origTime = delay = scanner.real
@@ -2669,20 +2642,13 @@ def wait():
game.resting = False
game.optime = 0
-# A nova occurs. It is the result of having a star hit with a
-# photon torpedo, or possibly of a probe warhead going off.
-# Stars that go nova cause stars which surround them to undergo
-# the same probabilistic process. Klingons next to them are
-# destroyed. And if the starship is next to it, it gets zapped.
-# If the zap is too much, it gets destroyed.
-
def nova(nov):
"Star goes nova."
course = (0.0, 10.5, 12.0, 1.5, 9.0, 0.0, 3.0, 7.5, 6.0, 4.5)
newc = coord(); neighbor = coord(); bump = coord(0, 0)
if withprob(0.05):
# Wow! We've supernova'ed
- supernova(False, nov)
+ supernova(game.quadrant)
return
# handle initial nova
game.quad[nov.i][nov.j] = IHDOT
@@ -2709,7 +2675,7 @@ def nova(nov):
elif iquad == IHSTAR: # Affect another star
if withprob(0.05):
# This star supernovas
- supernova(False)
+ supernova(game.quadrant)
return
else:
hits.append(neighbor)
@@ -2804,17 +2770,15 @@ def nova(nov):
game.optime = 10.0*game.dist/16.0
return
-def supernova(induced, w=None):
+def supernova(w):
"Star goes supernova."
num = 0; npdead = 0
- nq = coord()
if w != None:
- nq = w
+ nq = copy.copy(w)
else:
+ # Scheduled supernova -- select star at random.
stars = 0
- # Scheduled supernova -- select star
- # logic changed here so that we won't favor quadrants in top
- # left of universe
+ nq = coord()
for nq.i in range(GALSIZE):
for nq.j in range(GALSIZE):
stars += game.state.galaxy[nq.i][nq.j].stars
@@ -2860,7 +2824,7 @@ def supernova(induced, w=None):
skip(1)
stars()
game.alldone = True
- # destroy any Klingons in supernovaed quadrant
+ # destroy any Klingons in supernovaed quadrant
kldead = game.state.galaxy[nq.i][nq.j].klingons
game.state.galaxy[nq.i][nq.j].klingons = 0
if nq == game.state.kscmdr:
@@ -2888,7 +2852,7 @@ def supernova(induced, w=None):
# Destroy any base in supernovaed quadrant
game.state.baseq = filter(lambda x: x != nq, game.state.baseq)
# If starship caused supernova, tally up destruction
- if induced:
+ if w != None:
game.state.starkl += game.state.galaxy[nq.i][nq.j].stars
game.state.basekl += game.state.galaxy[nq.i][nq.j].starbase
game.state.nplankl += npdead
@@ -2898,7 +2862,7 @@ def supernova(induced, w=None):
# If supernova destroys last Klingons give special message
if (game.state.remkl + len(game.state.kcmdr) + game.state.nscrem)==0 and not nq == game.quadrant:
skip(2)
- if not induced:
+ if w == None:
prout(_("Lucky you!"))
proutn(_("A supernova in %s has just destroyed the last Klingons.") % nq)
finish(FWON)
@@ -3341,27 +3305,8 @@ message_window = None
prompt_window = None
curwnd = None
-def outro():
- "Wrap up, either normally or due to signal"
- if game.options & OPTION_CURSES:
- #clear()
- #curs_set(1)
- #refresh()
- #resetterm()
- #echo()
- curses.endwin()
- sys.stdout.write('\n')
- if logfp:
- logfp.close()
-
def iostart():
global stdscr, rows
- #setlocale(LC_ALL, "")
- #bindtextdomain(PACKAGE, LOCALEDIR)
- #textdomain(PACKAGE)
- if atexit.register(outro):
- sys.stderr.write("Unable to register outro(), exiting...\n")
- raise SysExit,1
if not (game.options & OPTION_CURSES):
ln_env = os.getenv("LINES")
if ln_env:
@@ -3371,19 +3316,8 @@ def iostart():
else:
stdscr = curses.initscr()
stdscr.keypad(True)
- #saveterm()
curses.nonl()
curses.cbreak()
- curses.start_color()
- curses.init_pair(curses.COLOR_BLACK, curses.COLOR_BLACK, curses.COLOR_BLACK)
- curses.init_pair(curses.COLOR_GREEN, curses.COLOR_GREEN, curses.COLOR_BLACK)
- curses.init_pair(curses.COLOR_RED, curses.COLOR_RED, curses.COLOR_BLACK)
- curses.init_pair(curses.COLOR_CYAN, curses.COLOR_CYAN, curses.COLOR_BLACK)
- curses.init_pair(curses.COLOR_WHITE, curses.COLOR_WHITE, curses.COLOR_BLACK)
- curses.init_pair(curses.COLOR_MAGENTA, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
- curses.init_pair(curses.COLOR_BLUE, curses.COLOR_BLUE, curses.COLOR_BLACK)
- curses.init_pair(curses.COLOR_YELLOW, curses.COLOR_YELLOW, curses.COLOR_BLACK)
- #noecho()
global fullscreen_window, srscan_window, report_window, status_window
global lrscan_window, message_window, prompt_window
(rows, columns) = stdscr.getmaxyx()
@@ -3396,20 +3330,19 @@ def iostart():
prompt_window = curses.newwin(1, 0, rows-2, 0)
message_window.scrollok(True)
setwnd(fullscreen_window)
- textcolor(DEFAULT)
-
-def textcolor(color):
- "Set text foreground color. Presently a stub."
- pass # FIXME
def ioend():
- "Wrap up I/O. Presently a stub."
- pass
+ "Wrap up I/O."
+ if game.options & OPTION_CURSES:
+ stdscr.keypad(False)
+ curses.echo()
+ curses.nocbreak()
+ curses.endwin()
def waitfor():
"Wait for user action -- OK to do nothing if on a TTY"
if game.options & OPTION_CURSES:
- stsdcr.getch()
+ stdscr.getch()
def announce():
skip(1)
@@ -3450,7 +3383,10 @@ def skip(i):
pause_game()
clrscr()
else:
- proutn("\n")
+ try:
+ curwnd.move(y+1, 0)
+ except curses.error:
+ pass
else:
global linecount
linecount += 1
@@ -3479,7 +3415,7 @@ def prouts(line):
time.sleep(0.03)
proutn(c)
if game.options & OPTION_CURSES:
- wrefresh(curwnd)
+ curwnd.refresh()
else:
sys.stdout.flush()
if not replayfp or replayfp.closed:
@@ -3865,7 +3801,7 @@ def dock(verbose):
# because it involves giving x and y motions, yet the coordinates
# are always displayed y - x, where +y is downward!
-def getcourse(isprobe, akey):
+def getcourse(isprobe):
"Get a course and distance from the user."
key = 0
dquad = copy.copy(game.quadrant)
@@ -3886,19 +3822,14 @@ def getcourse(isprobe, akey):
prout(_("Computer damaged; manual movement only"))
scanner.chew()
navmode = "manual"
- key = IHEOL
+ key = "IHEOL"
break
- if isprobe and akey != -1:
- # For probe launch, use pre-scanned value first time
- key = akey
- akey = -1
- else:
- key = scanner.next()
- if key == IHEOL:
+ key = scanner.next()
+ if key == "IHEOL":
proutn(_("Manual or automatic- "))
iprompt = True
scanner.chew()
- elif key == IHALPHA:
+ elif key == "IHALPHA":
if scanner.sees("manual"):
navmode = "manual"
key = scanner.next()
@@ -3919,7 +3850,7 @@ def getcourse(isprobe, akey):
navmode = "manual"
break
if navmode == "automatic":
- while key == IHEOL:
+ while key == "IHEOL":
if isprobe:
proutn(_("Target quadrant or quadrant§or- "))
else:
@@ -3927,28 +3858,28 @@ def getcourse(isprobe, akey):
scanner.chew()
iprompt = True
key = scanner.next()
- if key != IHREAL:
+ if key != "IHREAL":
huh()
return False
xi = int(round(scanner.real))-1
key = scanner.next()
- if key != IHREAL:
+ if key != "IHREAL":
huh()
return False
xj = int(round(scanner.real))-1
key = scanner.next()
- if key == IHREAL:
+ if key == "IHREAL":
# both quadrant and sector specified
xk = int(round(scanner.real))-1
key = scanner.next()
- if key != IHREAL:
+ if key != "IHREAL":
huh()
return False
xl = int(round(scanner.real))-1
dquad.i = xi
dquad.j = xj
- dsect.j = xk
- dsect.i = xl
+ dsect.i = xk
+ dsect.j = xl
else:
# only one pair of numbers was specified
if isprobe:
@@ -3958,10 +3889,10 @@ def getcourse(isprobe, akey):
dsect.j = dsect.i = 4 # preserves 1-origin behavior
else:
# only sector specified
- dsect.j = xi
- dsect.i = xj
+ dsect.i = xi
+ dsect.j = xj
itemp = "normal"
- if not VALID_QUADRANT(dquad.j,dquad.i) or not VALID_SECTOR(dsect.i,dsect.j):
+ if not VALID_QUADRANT(dquad.i,dquad.j) or not VALID_SECTOR(dsect.i,dsect.j):
huh()
return False
skip(1)
@@ -3973,21 +3904,21 @@ def getcourse(isprobe, akey):
prout(_("Ensign Chekov- \"Course laid in, Captain.\""))
# the actual deltas get computed here
delta = coord()
- delta.i = dquad.j-game.quadrant.j + 0.1*(dsect.i-game.sector.j)
- delta.j = game.quadrant.i-dquad.i + 0.1*(game.sector.i-dsect.j)
+ delta.j = dquad.j-game.quadrant.j + 0.1*(dsect.j-game.sector.j)
+ delta.i = game.quadrant.i-dquad.i + 0.1*(game.sector.i-dsect.i)
else: # manual
- while key == IHEOL:
+ while key == "IHEOL":
proutn(_("X and Y displacements- "))
scanner.chew()
iprompt = True
key = scanner.next()
itemp = "verbose"
- if key != IHREAL:
+ if key != "IHREAL":
huh()
return False
delta.j = scanner.real
key = scanner.next()
- if key != IHREAL:
+ if key != "IHREAL":
huh()
return False
delta.i = scanner.real
@@ -4015,7 +3946,7 @@ def impulse():
prout(_("Engineer Scott- \"The impulse engines are damaged, Sir.\""))
return
if game.energy > 30.0:
- if not getcourse(isprobe=False, akey=0):
+ if not getcourse(isprobe=False):
return
power = 20.0 + 100.0*game.dist
else:
@@ -4070,7 +4001,7 @@ def warp(timewarp):
prout(_(" is repaired, I can only give you warp 4.\""))
return
# Read in course and distance
- if not getcourse(isprobe=False, akey=0):
+ if not getcourse(isprobe=False):
return
# Make sure starship has enough energy for the trip
power = (game.dist+0.05)*game.warpfac*game.warpfac*game.warpfac*(game.shldup+1)
@@ -4095,7 +4026,7 @@ def warp(timewarp):
return
# Make sure enough time is left for the trip
- game.optime = 10.0*game.dist/game.wfacsq
+ game.optime = 10.0*game.dist/game.warpfac**2
if game.optime >= 0.8*game.state.remtime:
skip(1)
prout(_("First Officer Spock- \"Captain, I compute that such"))
@@ -4155,7 +4086,7 @@ def warp(timewarp):
game.energy -= game.dist*game.warpfac*game.warpfac*game.warpfac*(game.shldup+1)
if game.energy <= 0:
finish(FNRG)
- game.optime = 10.0*game.dist/game.wfacsq
+ game.optime = 10.0*game.dist/game.warpfac**2
if twarp:
timwrp()
if blooey:
@@ -4171,12 +4102,12 @@ def setwarp():
"Change the warp factor."
while True:
key=scanner.next()
- if key != IHEOL:
+ if key != "IHEOL":
break
scanner.chew()
proutn(_("Warp factor- "))
scanner.chew()
- if key != IHREAL:
+ if key != "IHREAL":
huh()
return
if game.damage[DWARPEN] > 10.0:
@@ -4194,7 +4125,6 @@ def setwarp():
return
oldfac = game.warpfac
game.warpfac = scanner.real
- game.wfacsq=game.warpfac*game.warpfac
if game.warpfac <= oldfac or game.warpfac <= 6.0:
prout(_("Helmsman Sulu- \"Warp factor %d, Captain.\"") %
int(game.warpfac))
@@ -4250,8 +4180,7 @@ def atover(igrab):
proutn(_("The %s has stopped in a quadrant containing") % crmshp())
prouts(_(" a supernova."))
skip(2)
- prout(_("***Emergency automatic override attempts to hurl ")+crmshp())
- skip(1)
+ proutn(_("***Emergency automatic override attempts to hurl ")+crmshp())
prout(_("safely out of quadrant."))
if not damaged(DRADIO):
game.state.galaxy[game.quadrant.i][game.quadrant.j].charted = True
@@ -4262,14 +4191,13 @@ def atover(igrab):
finish(FSNOVAED)
return
game.warpfac = randreal(6.0, 8.0)
- game.wfacsq = game.warpfac * game.warpfac
prout(_("Warp factor set to %d") % int(game.warpfac))
power = 0.75*game.energy
game.dist = power/(game.warpfac*game.warpfac*game.warpfac*(game.shldup+1))
distreq = randreal(math.sqrt(2))
if distreq < game.dist:
game.dist = distreq
- game.optime = 10.0*game.dist/game.wfacsq
+ game.optime = 10.0*game.dist/game.warpfac**2
game.direc = randreal(12) # How dumb!
game.justin = False
game.inorbit = False
@@ -4364,8 +4292,7 @@ def probe():
prout(_("Uhura- \"The previous probe is still reporting data, Sir.\""))
return
key = scanner.next()
- if key == IHEOL:
- # slow mode, so let Kirk know how many probes there are left
+ if key == "IHEOL":
if game.nprobes == 1:
prout(_("1 probe left."))
else:
@@ -4374,50 +4301,30 @@ def probe():
if ja() == False:
return
game.isarmed = False
- if key == IHALPHA and scanner.token == "armed":
+ if key == "IHALPHA" and scanner.token == "armed":
game.isarmed = True
key = scanner.next()
- elif key == IHEOL:
+ elif key == "IHEOL":
proutn(_("Arm NOVAMAX warhead? "))
game.isarmed = ja()
- if not getcourse(isprobe=True, akey=key):
+ elif key == "IHREAL": # first element of course
+ scanner.push(scanner.token)
+ if not getcourse(isprobe=True):
return
game.nprobes -= 1
angle = ((15.0 - game.direc) * 0.5235988)
- game.probeinx = -math.sin(angle)
- game.probeiny = math.cos(angle)
- if math.fabs(game.probeinx) > math.fabs(game.probeiny):
- bigger = math.fabs(game.probeinx)
- else:
- bigger = math.fabs(game.probeiny)
- game.probeiny /= bigger
- game.probeinx /= bigger
+ game.probein = coord(-math.sin(angle), math.cos(angle))
+ bigger = max(abs(game.probein.i), abs(game.probein.j))
+ game.probein /= bigger
game.proben = 10.0*game.dist*bigger +0.5
- game.probex = game.quadrant.i*QUADSIZE + game.sector.i - 1 # We will use better packing than original
- game.probey = game.quadrant.j*QUADSIZE + game.sector.j - 1
- game.probec = game.quadrant
+ game.probe = coord(game.quadrant.i*QUADSIZE + game.sector.i,
+ game.quadrant.j*QUADSIZE + game.sector.j)
+ game.probec = copy.copy(game.quadrant)
schedule(FDSPROB, 0.01) # Time to move one sector
prout(_("Ensign Chekov- \"The deep space probe is launched, Captain.\""))
game.ididit = True
return
-# Here's how the mayday code works:
-#
-# First, the closest starbase is selected. If there is a a starbase
-# in your own quadrant, you are in good shape. This distance takes
-# quadrant distances into account only.
-#
-# A magic number is computed based on the distance which acts as the
-# probability that you will be rematerialized. You get three tries.
-#
-# When it is determined that you should be able to be rematerialized
-# (i.e., when the probability thing mentioned above comes up
-# positive), you are put into that quadrant (anywhere). Then, we try
-# to see if there is a spot adjacent to the star- base. If not, you
-# can't be rematerialized!!! Otherwise, it drops you there. It only
-# tries five times to find a spot to drop you. After that, it's your
-# problem.
-
def mayday():
"Yell for help from nearest starbase."
# There's more than one way to move in this game!
@@ -4472,13 +4379,13 @@ def mayday():
elif m == 3: proutn(_("3rd"))
proutn(_(" attempt to re-materialize ") + crmshp())
game.quad[ix][iy]=(IHMATER0,IHMATER1,IHMATER2)[m-1]
- textcolor("red")
+ #textcolor("red")
warble()
if randreal() > probf:
break
prout(_("fails."))
curses.delay_output(500)
- textcolor(None)
+ #textcolor(None)
if m > 3:
game.quad[ix][iy]=IHQUEST
game.alive = False
@@ -4487,31 +4394,13 @@ def mayday():
finish(FMATERIALIZE)
return
game.quad[ix][iy]=game.ship
- textcolor("green")
+ #textcolor("green")
prout(_("succeeds."))
- textcolor(None)
+ #textcolor(None)
dock(False)
skip(1)
prout(_("Lt. Uhura- \"Captain, we made it!\""))
-# Abandon Ship (the BSD-Trek description)
-#
-# The ship is abandoned. If your current ship is the Faire
-# Queene, or if your shuttlecraft is dead, you're out of
-# luck. You need the shuttlecraft in order for the captain
-# (that's you!!) to escape.
-#
-# Your crew can beam to an inhabited starsystem in the
-# quadrant, if there is one and if the transporter is working.
-# If there is no inhabited starsystem, or if the transporter
-# is out, they are left to die in outer space.
-#
-# If there are no starbases left, you are captured by the
-# Klingons, who torture you mercilessly. However, if there
-# is at least one starbase, you are returned to the
-# Federation in a prisoner of war exchange. Of course, this
-# can't happen unless you have taken some prisoners.
-
def abandon():
"Abandon ship."
scanner.chew()
@@ -4606,7 +4495,6 @@ def abandon():
game.lsupres=game.inlsr=3.0
game.shldup=False
game.warpfac=5.0
- game.wfacsq=25.0
return
# Code from planets.c begins here.
@@ -5258,15 +5146,15 @@ def sectscan(goodScan, i, j):
"Light up an individual dot in a sector."
if goodScan or (abs(i-game.sector.i)<= 1 and abs(j-game.sector.j) <= 1):
if (game.quad[i][j]==IHMATER0) or (game.quad[i][j]==IHMATER1) or (game.quad[i][j]==IHMATER2) or (game.quad[i][j]==IHE) or (game.quad[i][j]==IHF):
- if game.condition == "red": textcolor("red")
- elif game.condition == "green": textcolor("green")
- elif game.condition == "yellow": textcolor("yellow")
- elif game.condition == "docked": textcolor("cyan")
- elif game.condition == "dead": textcolor("brown")
+ #if game.condition == "red": textcolor("red")
+ #elif game.condition == "green": textcolor("green")
+ #elif game.condition == "yellow": textcolor("yellow")
+ #elif game.condition == "docked": textcolor("cyan")
+ #elif game.condition == "dead": textcolor("brown")
if game.quad[i][j] != game.ship:
highvideo()
proutn("%c " % game.quad[i][j])
- textcolor(None)
+ #textcolor(None)
else:
proutn("- ")
@@ -5329,7 +5217,7 @@ def status(req=0):
def request():
"Request specified status data, a historical relic from slow TTYs."
requests = ("da","co","po","ls","wa","en","to","sh","kl","sy", "ti")
- while scanner.next() == IHEOL:
+ while scanner.next() == "IHEOL":
proutn(_("Information desired? "))
scanner.chew()
if scanner.token in requests:
@@ -5364,7 +5252,7 @@ def srscan():
for j in range(QUADSIZE):
sectscan(goodScan, i, j)
skip(1)
-
+
def eta():
"Use computer to get estimated time of arrival for a warp jump."
w1 = coord(); w2 = coord()
@@ -5373,21 +5261,21 @@ def eta():
prout(_("COMPUTER DAMAGED, USE A POCKET CALCULATOR."))
skip(1)
return
- if scanner.next() != IHREAL:
+ if scanner.next() != "IHREAL":
prompt = True
scanner.chew()
proutn(_("Destination quadrant and/or sector? "))
- if scanner.next()!=IHREAL:
+ if scanner.next()!="IHREAL":
huh()
return
w1.j = int(scanner.real-0.5)
- if scanner.next() != IHREAL:
+ if scanner.next() != "IHREAL":
huh()
return
w1.i = int(scanner.real-0.5)
- if scanner.next() == IHREAL:
+ if scanner.next() == "IHREAL":
w2.j = int(scanner.real-0.5)
- if scanner.next() != IHREAL:
+ if scanner.next() != "IHREAL":
huh()
return
w2.i = int(scanner.real-0.5)
@@ -5411,7 +5299,7 @@ def eta():
while True:
scanner.chew()
proutn(_("Time or arrival date? "))
- if scanner.next()==IHREAL:
+ if scanner.next()=="IHREAL":
ttime = scanner.real
if ttime > game.state.date:
ttime -= game.state.date # Actually a star date
@@ -5425,7 +5313,7 @@ def eta():
break
scanner.chew()
proutn(_("Warp factor? "))
- if scanner.next()== IHREAL:
+ if scanner.next()== "IHREAL":
wfl = True
twarp = scanner.real
if twarp<1.0 or twarp > 10.0:
@@ -5443,7 +5331,7 @@ def eta():
if not wfl:
return
proutn(_("New warp factor to try? "))
- if scanner.next() == IHREAL:
+ if scanner.next() == "IHREAL":
wfl = True
twarp = scanner.real
if twarp<1.0 or twarp > 10.0:
@@ -5476,7 +5364,7 @@ def eta():
(scheduled(FCDBAS)