X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=src%2Fsst.py;h=74dcbaa3aee8ab27ce8b09f73e4e642330a0c2ca;hp=fbd85f9b1c29460412f28205ab2f050d2c89de62;hb=29d86fb395ca01e4a4f65f02d67f5823a4ebba11;hpb=4162df86eb0d33c39014a02075294128fd2ca84d diff --git a/src/sst.py b/src/sst.py index fbd85f9..74dcbaa 100644 --- a/src/sst.py +++ b/src/sst.py @@ -180,7 +180,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 +227,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 +256,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: @@ -759,10 +755,7 @@ def movebaddy(enemy): else: motion = game.skill # calculate preferred number of steps - if motion < 0: - nsteps = -motion - else: - nsteps = motion + nsteps = abs(int(motion)) if motion > 0 and nsteps > mdist: nsteps = mdist; # don't overshoot if nsteps > QUADSIZE: @@ -777,16 +770,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): @@ -1073,11 +1057,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 +1080,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 +1139,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 +1273,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 +1284,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] @@ -1347,7 +1330,7 @@ def torpedo(origin, course, dispersion, number, nburst): shoved = True elif iquad in (IHC, IHS, IHR, IHK): # Hit a regular enemy # find the enemy - if withprob(0.05): + if iquad in (IHC, IHS) and withprob(0.05): prout(crmena(True, iquad, "sector", w) + _(" uses anti-photon device;")) prout(_(" torpedo neutralized.")) return None @@ -1590,7 +1573,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")) @@ -1742,7 +1725,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." @@ -1759,15 +1742,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() @@ -1784,24 +1767,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)) @@ -1965,12 +1948,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" @@ -1988,7 +1971,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" @@ -1997,7 +1980,7 @@ def phasers(): else: automode = "AUTOMATIC" else: - # IHEOL + # "IHEOL" if len(game.enemies)==0: prout(_("Energy will be expended into space.")) automode = "AUTOMATIC" @@ -2010,10 +1993,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: @@ -2026,13 +2009,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: @@ -2040,7 +2023,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! @@ -2079,7 +2062,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: @@ -2104,11 +2087,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 @@ -2121,14 +2104,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 @@ -2149,7 +2132,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() @@ -2624,11 +2607,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 @@ -3340,27 +3323,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: @@ -3370,19 +3334,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() @@ -3395,20 +3348,18 @@ 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 + 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) @@ -3449,7 +3400,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 @@ -3478,7 +3432,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: @@ -3885,7 +3839,7 @@ 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 @@ -3893,11 +3847,11 @@ def getcourse(isprobe, akey): akey = -1 else: key = scanner.next() - if key == IHEOL: + 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() @@ -3918,7 +3872,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: @@ -3926,21 +3880,21 @@ 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 @@ -3972,21 +3926,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.j-game.sector.j) - delta.j = game.quadrant.i-dquad.i + 0.1*(game.sector.i-dsect.i) + 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 @@ -4094,7 +4048,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")) @@ -4154,7 +4108,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: @@ -4170,12 +4124,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: @@ -4193,7 +4147,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)) @@ -4261,14 +4214,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 @@ -4363,7 +4315,7 @@ def probe(): prout(_("Uhura- \"The previous probe is still reporting data, Sir.\"")) return key = scanner.next() - if key == IHEOL: + if key == "IHEOL": # slow mode, so let Kirk know how many probes there are left if game.nprobes == 1: prout(_("1 probe left.")) @@ -4373,10 +4325,10 @@ 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): @@ -4471,13 +4423,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 @@ -4486,9 +4438,9 @@ 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!\"")) @@ -4605,7 +4557,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. @@ -5257,15 +5208,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("- ") @@ -5328,7 +5279,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: @@ -5363,7 +5314,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() @@ -5372,21 +5323,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) @@ -5410,7 +5361,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 @@ -5424,7 +5375,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: @@ -5442,7 +5393,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: @@ -5475,7 +5426,7 @@ def eta(): (scheduled(FCDBAS) 10.0: @@ -5503,10 +5454,10 @@ def freeze(boss): scanner.token = "emsave.trk" else: key = scanner.next() - if key == IHEOL: + if key == "IHEOL": proutn(_("File name: ")) key = scanner.next() - if key != IHALPHA: + if key != "IHALPHA": huh() return scanner.chew() @@ -5524,10 +5475,10 @@ def thaw(): "Retrieve saved game." game.passwd[0] = '\0' key = scanner.next() - if key == IHEOL: + if key == "IHEOL": proutn(_("File name: ")) key = scanner.next() - if key != IHALPHA: + if key != "IHALPHA": huh() return True scanner.chew() @@ -5620,13 +5571,11 @@ def setup(): if choose(): return # frozen game # Prepare the Enterprise - game.alldone = game.gamewon = False + game.alldone = game.gamewon = game.shldchg = game.shldup = False game.ship = IHE game.state.crew = FULLCREW game.energy = game.inenrg = 5000.0 game.shield = game.inshld = 2500.0 - game.shldchg = False - game.shldup = False game.inlsr = 4.0 game.lsupres = 4.0 game.quadrant = randplace(GALSIZE) @@ -5634,7 +5583,6 @@ def setup(): game.torps = game.intorps = 10 game.nprobes = randrange(2, 5) game.warpfac = 5.0 - game.wfacsq = game.warpfac * game.warpfac for i in range(NDEVICES): game.damage[i] = 0.0 # Set up assorted game parameters @@ -5825,7 +5773,7 @@ def choose(): if len(scanner.token)==0: # Try again continue if scanner.sees("tournament"): - while scanner.next() == IHEOL: + while scanner.next() == "IHEOL": proutn(_("Type in tournament number-")) if scanner.real == 0: scanner.chew() @@ -5851,7 +5799,7 @@ def choose(): proutn(_("What is \"%s\"?") % scanner.token) scanner.chew() while game.length==0 or game.skill==SKILL_NONE: - if scanner.next() == IHALPHA: + if scanner.next() == "IHALPHA": if scanner.sees("short"): game.length = 1 elif scanner.sees("medium"): @@ -5879,7 +5827,7 @@ def choose(): elif game.skill == SKILL_NONE: proutn(_("Are you a Novice, Fair, Good, Expert, or Emeritus player? ")) # Choose game options -- added by ESR for SST2K - if scanner.next() != IHALPHA: + if scanner.next() != "IHALPHA": scanner.chew() proutn(_("Choose your game style (or just press enter): ")) scanner.next() @@ -6116,30 +6064,32 @@ commands = { def listCommands(): "Generate a list of legal commands." - proutn(_("LEGAL COMMANDS ARE:")) - for (k, key) in enumerate(commands): + prout(_("LEGAL COMMANDS ARE:")) + emitted = 0 + for key in commands: if not commands[key] or (commands[key] & game.options): - if k % 5 == 0: + proutn("%-12s " % key) + emitted += 1 + if emitted % 5 == 4: skip(1) - proutn("%-12s " % key) skip(1) def helpme(): "Browse on-line help." key = scanner.next() while True: - if key == IHEOL: + if key == "IHEOL": setwnd(prompt_window) proutn(_("Help on what command? ")) key = scanner.next() setwnd(message_window) - if key == IHEOL: + if key == "IHEOL": return if scanner.token in commands or scanner.token == "ABBREV": break skip(1) listCommands() - key = IHEOL + key = "IHEOL" scanner.chew() skip(1) cmd = scanner.token.upper() @@ -6194,7 +6144,7 @@ def makemoves(): setwnd(prompt_window) clrscr() proutn("COMMAND> ") - if scanner.next() == IHEOL: + if scanner.next() == "IHEOL": if game.options & OPTION_CURSES: makechart() continue @@ -6405,30 +6355,30 @@ class sstscanner: clrscr() if line == '': return None - # Skip leading white space - line = line.lstrip() if not line: continue else: - self.inqueue = line.lstrip().split() + [IHEOL] + self.inqueue = line.lstrip().split() + ["IHEOL"] # From here on in it's all looking at the queue self.token = self.inqueue.pop(0) - if self.token == IHEOL: - self.type = IHEOL - return IHEOL + if self.token == "IHEOL": + self.type = "IHEOL" + return "IHEOL" try: self.real = float(self.token) - self.type = IHREAL - return IHREAL + self.type = "IHREAL" + return "IHREAL" except ValueError: pass # Treat as alpha self.token = self.token.lower() - self.type = IHALPHA + self.type = "IHALPHA" self.real = None - return IHALPHA - def push(self, tok): + return "IHALPHA" + def append(self, tok): self.inqueue.append(tok) + def push(self, tok): + self.inqueue.insert(0, tok) def waiting(self): return self.inqueue def chew(self): @@ -6436,8 +6386,8 @@ class sstscanner: self.inqueue = [] self.real = self.token = None def chew2(self): - # return IHEOL next time - self.inqueue = [IHEOL] + # return "IHEOL" next time + self.inqueue = ["IHEOL"] self.real = self.token = None def sees(self, s): # compares s to item and returns true if it matches to the length of s @@ -6448,16 +6398,18 @@ class sstscanner: def getcoord(self): s = coord() scanner.next() - if scanner.type != IHREAL: + if scanner.type != "IHREAL": huh() return None s.i = scanner.int()-1 scanner.next() - if scanner.type != IHREAL: + if scanner.type != "IHREAL": huh() return None s.j = scanner.int()-1 return s + def __repr__(str): + return "" % (scanner.token, scanner.type, scanner.inqueue) def ja(): "Yes-or-no confirmation." @@ -6504,7 +6456,7 @@ def debugme(): proutn("Kill %s?" % device[i]) scanner.chew() key = scanner.next() - if key == IHALPHA and scanner.sees("y"): + if key == "IHALPHA" and scanner.sees("y"): game.damage[i] = 10.0 proutn("Examine/change events? ") if ja() == True: @@ -6538,21 +6490,21 @@ def debugme(): if key == 'n': unschedule(i) scanner.chew() - elif key == IHREAL: + elif key == "IHREAL": ev = schedule(i, scanner.real) if i == FENSLV or i == FREPRO: scanner.chew() proutn("In quadrant- ") key = scanner.next() - # IHEOL says to leave coordinates as they are - if key != IHEOL: - if key != IHREAL: + # "IHEOL" says to leave coordinates as they are + if key != "IHEOL": + if key != "IHREAL": prout("Event %d canceled, no x coordinate." % (i)) unschedule(i) continue w.i = int(round(scanner.real)) key = scanner.next() - if key != IHREAL: + if key != "IHREAL": prout("Event %d canceled, no y coordinate." % (i)) unschedule(i) continue @@ -6565,6 +6517,7 @@ def debugme(): atover(True) if __name__ == '__main__': + import getopt, socket try: global line, thing, game, idebug game = None @@ -6573,11 +6526,10 @@ if __name__ == '__main__': game = gamestate() idebug = 0 game.options = OPTION_ALL &~ (OPTION_IOMODES | OPTION_PLAIN | OPTION_ALMY) - # Disable curses mode until the game logic is working. - # if os.getenv("TERM"): - # game.options |= OPTION_CURSES | OPTION_SHOWME - # else: - game.options |= OPTION_TTY + if os.getenv("TERM"): + game.options |= OPTION_CURSES + else: + game.options |= OPTION_TTY seed = int(time.time()) (options, arguments) = getopt.getopt(sys.argv[1:], "r:s:tx") for (switch, val) in options: @@ -6617,9 +6569,11 @@ if __name__ == '__main__': if logfp: 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())) random.seed(seed) scanner = sstscanner() - map(scanner.push, arguments) + map(scanner.append, arguments) try: iostart() while True: # Play a game @@ -6650,5 +6604,7 @@ if __name__ == '__main__': ioend() raise SystemExit, 0 except KeyboardInterrupt: - print"" + if logfp: + logfp.close() + print "" pass