X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=sst.py;h=691eff84dbb4e2f179528a3ecbce5becc9cc9795;hp=08377bea38bcd2956ba158391b0482e04bc5b845;hb=2a1e7baaa229ba188baa2cf8b35cc6ec1485f35b;hpb=972cea516e66fb65c86f084103f583d1c51941ef diff --git a/sst.py b/sst.py index 08377be..691eff8 100755 --- a/sst.py +++ b/sst.py @@ -13,7 +13,7 @@ on how to modify (and how not to modify!) this code. """ import os, sys, math, curses, time, readline, cPickle, random, copy, gettext, getpass -version="2.0" +version="2.1" docpath = (".", "../doc", "/usr/share/doc/sst") @@ -3530,7 +3530,7 @@ def imove(icourse=None, noattack=False): if icourse.origin.quadrant() != icourse.location.quadrant(): newquadrant(noattack) break - elif check_collision(icourse, w): + elif check_collision(w): print "Collision detected" break else: @@ -3901,7 +3901,7 @@ def warp(wcourse, involuntary): twarp = False wcourse.reset() # Activate Warp Engines and pay the cost - imove(course, noattack=False) + imove(wcourse, noattack=False) if game.alldone: return game.energy -= wcourse.power(game.warpfac) @@ -5203,7 +5203,6 @@ def freeze(boss): if key != "IHALPHA": huh() return - scanner.chew() if '.' not in scanner.token: scanner.token += ".trk" try: @@ -5213,11 +5212,12 @@ def freeze(boss): return cPickle.dump(game, fp) fp.close() + scanner.chew() def thaw(): "Retrieve saved game." global game - game.passwd[0] = '\0' + game.passwd = None key = scanner.next() if key == "IHEOL": proutn(_("File name: ")) @@ -5225,7 +5225,6 @@ def thaw(): if key != "IHALPHA": huh() return True - scanner.chew() if '.' not in scanner.token: scanner.token += ".trk" try: @@ -5235,6 +5234,7 @@ def thaw(): return game = cPickle.load(fp) fp.close() + scanner.chew() return False # I used to find planets @@ -5335,10 +5335,21 @@ def setup(): game.nkinks = game.nhelp = game.casual = game.abandoned = 0 game.iscate = game.resting = game.imine = game.icrystl = game.icraft = False game.isatb = game.state.nplankl = 0 - game.state.starkl = game.state.basekl = 0 + game.state.starkl = game.state.basekl = game.state.nworldkl = 0 game.iscraft = "onship" game.landed = False game.alive = True + + # the galaxy + game.state.galaxy = fill2d(GALSIZE, lambda i_unused, j_unused: Quadrant()) + # the starchart + game.state.chart = fill2d(GALSIZE, lambda i_unused, j_unused: Page()) + + game.state.planets = [] # Planet information + game.state.baseq = [] # Base quadrant coordinates + game.state.kcmdr = [] # Commander quadrant coordinates + game.statekscmdr = Coord() # Supercommander quadrant coordinates + # Starchart is functional but we've never seen it game.lastchart = FOREVER # Put stars in the galaxy @@ -5496,6 +5507,8 @@ def setup(): if game.state.nscrem: prout(_(" YOU'LL NEED IT.")) waitfor() + clrscr() + setwnd(message_window) newqad() if len(game.enemies) - (thing == game.quadrant) - (game.tholian != None): game.shldup = True @@ -5536,7 +5549,7 @@ def choose(): return True if scanner.sees("regular"): break - proutn(_("What is \"%s\"?") % scanner.token) + proutn(_("What is \"%s\"? ") % scanner.token) scanner.chew() while game.length==0 or game.skill==SKILL_NONE: if scanner.next() == "IHALPHA": @@ -5766,54 +5779,55 @@ def setpassword(): # Code from sst.c begins here -commands = { - "SRSCAN": OPTION_TTY, - "STATUS": OPTION_TTY, - "REQUEST": OPTION_TTY, - "LRSCAN": OPTION_TTY, - "PHASERS": 0, - "TORPEDO": 0, - "PHOTONS": 0, - "MOVE": 0, - "SHIELDS": 0, - "DOCK": 0, - "DAMAGES": 0, - "CHART": 0, - "IMPULSE": 0, - "REST": 0, - "WARP": 0, - "SCORE": 0, - "SENSORS": OPTION_PLANETS, - "ORBIT": OPTION_PLANETS, - "TRANSPORT": OPTION_PLANETS, - "MINE": OPTION_PLANETS, - "CRYSTALS": OPTION_PLANETS, - "SHUTTLE": OPTION_PLANETS, - "PLANETS": OPTION_PLANETS, - "REPORT": 0, - "COMPUTER": 0, - "COMMANDS": 0, - "EMEXIT": 0, - "PROBE": OPTION_PROBE, - "SAVE": 0, - "FREEZE": 0, # Synonym for SAVE - "ABANDON": 0, - "DESTRUCT": 0, - "DEATHRAY": 0, - "DEBUG": 0, - "MAYDAY": 0, - "SOS": 0, # Synonym for MAYDAY - "CALL": 0, # Synonym for MAYDAY - "QUIT": 0, - "HELP": 0, -} +commands = [ + ("SRSCAN", OPTION_TTY), + ("STATUS", OPTION_TTY), + ("REQUEST", OPTION_TTY), + ("LRSCAN", OPTION_TTY), + ("PHASERS", 0), + ("TORPEDO", 0), + ("PHOTONS", 0), + ("MOVE", 0), + ("SHIELDS", 0), + ("DOCK", 0), + ("DAMAGES", 0), + ("CHART", 0), + ("IMPULSE", 0), + ("REST", 0), + ("WARP", 0), + ("SCORE", 0), + ("SENSORS", OPTION_PLANETS), + ("ORBIT", OPTION_PLANETS), + ("TRANSPORT", OPTION_PLANETS), + ("MINE", OPTION_PLANETS), + ("CRYSTALS", OPTION_PLANETS), + ("SHUTTLE", OPTION_PLANETS), + ("PLANETS", OPTION_PLANETS), + ("REPORT", 0), + ("COMPUTER", 0), + ("COMMANDS", 0), + ("EMEXIT", 0), + ("PROBE", OPTION_PROBE), + ("SAVE", 0), + ("FREEZE", 0), # Synonym for SAVE + ("ABANDON", 0), + ("DESTRUCT", 0), + ("DEATHRAY", 0), + ("DEBUG", 0), + ("MAYDAY", 0), + ("SOS", 0), # Synonym for MAYDAY + ("CALL", 0), # Synonym for MAYDAY + ("QUIT", 0), + ("HELP", 0), + ("", 0), +] def listCommands(): "Generate a list of legal commands." prout(_("LEGAL COMMANDS ARE:")) emitted = 0 - for key in commands: - if not commands[key] or (commands[key] & game.options): + for (key, opt) in commands: + if not opt or (opt & game.options): proutn("%-12s " % key) emitted += 1 if emitted % 5 == 4: @@ -5831,7 +5845,8 @@ def helpme(): setwnd(message_window) if key == "IHEOL": return - if scanner.token.upper() in commands or scanner.token == "ABBREV": + cmds = map(lambda x: x[0], commands) + if scanner.token.upper() in cmds or scanner.token.upper() == "ABBREV": break skip(1) listCommands() @@ -5875,8 +5890,6 @@ def helpme(): def makemoves(): "Command-interpretation loop." - clrscr() - setwnd(message_window) while True: # command loop drawmaps(1) while True: # get a command @@ -5896,16 +5909,19 @@ def makemoves(): clrscr() setwnd(message_window) clrscr() - candidates = filter(lambda x: x.startswith(scanner.token.upper()), - commands) - if len(candidates) == 1: - cmd = candidates[0] - break - elif candidates and not (game.options & OPTION_PLAIN): - prout("Commands with prefix '%s': %s" % (scanner.token, " ".join(candidates))) - else: + abandon_passed = False + for (cmd, opt) in commands: + # commands after ABANDON cannot be abbreviated + if cmd == "ABANDON": + abandon_passed = True + if cmd == scanner.token.upper() or (not abandon_passed \ + and cmd.startswith(scanner.token.upper())): + break; + if cmd == "": listCommands() continue + else: + break; if cmd == "SRSCAN": # srscan srscan() elif cmd == "STATUS": # status @@ -6353,3 +6369,5 @@ if __name__ == '__main__': if logfp: logfp.close() print "" + +# End.