X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=src%2Fsst.py;h=e7a54919341fe3d348ff7492a97a2015380e2e94;hp=41d6c0f5094de61f26dd4319c74070517f1bc5c1;hb=5582ed2207d6a03b841afc376af746813881bebd;hpb=ad7e6b2e5d6f82e729fafaf4752f0fd8fed97fc3 diff --git a/src/sst.py b/src/sst.py index 41d6c0f..e7a5491 100644 --- a/src/sst.py +++ b/src/sst.py @@ -1992,7 +1992,7 @@ def hittem(hits): else: # decide whether or not to emasculate klingon if kpow > 0 and random.random() >= 0.9 and \ kpow <= ((0.4 + 0.4*random.random())*kpini): - prout(_("***Mr. Spock- \"Captain, the vessel at Sector %s"), w) + prout(_("***Mr. Spock- \"Captain, the vessel at Sector %s") % w) prout(_(" has just lost its firepower.\"")) game.kpower[kk] = -kpow kk += 1 @@ -3089,7 +3089,13 @@ def kaboom(): def killrate(): "Compute our rate of kils over time." - return ((game.inkling + game.incom + game.inscom) - (game.state.remkl + game.state.remcom + game.state.nscrem))/(game.state.date-game.indate) + elapsed = game.state.date - game.indate + if elapsed == 0: # Avoid divide-by-zero error if calculated on turn 0 + return 0 + else: + starting = (game.inkling + game.incom + game.inscom) + remaining = (game.state.remkl + game.state.remcom + game.state.nscrem) + return (starting - remaining)/elapsed def badpoints(): "Compute demerits." @@ -3490,7 +3496,7 @@ def iostart(): #textdomain(PACKAGE) if atexit.register(outro): sys.stderr.write("Unable to register outro(), exiting...\n") - os.exit(1) + raise SysExit,1 if not (game.options & OPTION_CURSES): ln_env = os.getenv("LINES") if ln_env: @@ -3614,8 +3620,11 @@ def cgetline(): else: if replayfp and not replayfp.closed: line = replayfp.readline() + if line == '': + prout("*** Replay finished") + replayfp.close() else: - line = raw_input() + line = raw_input("COMMAND> ") if logfp: logfp.write(line + "\n") return line @@ -3925,7 +3934,7 @@ def imove(novapush): # object encountered in flight path stopegy = 50.0*game.dist/game.optime game.dist = distance(game.sector, w) / (QUADSIZE * 1.0) - if iquad in (IHT, IHK, OHC, IHS, IHR, IHQUEST): + if iquad in (IHT, IHK, IHC, IHS, IHR, IHQUEST): game.sector = w ram(False, iquad, game.sector) final = game.sector @@ -5651,69 +5660,6 @@ def eta(): return -#ifdef BSD_BUG_FOR_BUG -# A visual scan is made in a particular direction of three sectors -# in the general direction specified. This takes time, and -# Klingons can attack you, so it should be done only when sensors -# are out. Code swiped from BSD-Trek. Not presently used, as we -# automatically display all adjacent sectors on the short-range -# scan even when short-range sensors are out. - -# This struct[] has the delta x, delta y for particular directions - -visdelta = ( - (-1,-1), - (-1, 0), - (-1, 1), - (0, 1), - (1, 1), - (1, 0), - (1, -1), - (0, -1), - (-1,-1), - (-1, 0), - (-1, 1), -) - -def visual(): - v = coord() - if scan() != IHREAL: - chew() - proutn(_("Direction? ")) - if scan()!=IHREAL: - huh() - return - if aaitem < 0.0 or aaitem > 360.0: - return - co = (aaitem + 22) / 45 - v = visdelta[co] - ix = game.sector.x + v.x - iy = game.sector.y + v.y - if ix < 0 or ix >= QUADSIZE or iy < 0 or iy >= QUADSIZE: - co = '?' - else: - co = game.quad[ix][iy] - printf("%d,%d %c " % (ix+1, iy+1, co)) - v += 1 - ix = game.sector.x + v.x - iy = game.sector.y + v.y - if ix < 0 or ix >= QUADSIZE or iy < 0 or iy >= QUADSIZE: - co = '?' - else: - co = game.quad[ix][iy] - printf("%c " % (co)) - v += 1 - ix = game.sector.x + v.x - iy = game.sector.y + v.y - if ix < 0 or ix >= QUADSIZE or iy < 0 or iy >= QUADSIZE: - co = '?' - else: - co = game.quad[ix][iy] - prout("%c %d,%d\n" % (co, ix+1, iy+1)) - game.optime = 0.5 - game.ididit = True -#endif - # Code from setup.c begins here def prelim(): @@ -5721,10 +5667,9 @@ def prelim(): skip(2) prout(_("-SUPER- STAR TREK")) skip(1) -#ifdef __HISTORICAL__ +# From the FORTRAN original # prout(_("Latest update-21 Sept 78")) # skip(1) -#endif __HISTORICAL__ def freeze(boss): # save game @@ -6499,7 +6444,6 @@ def makemoves(): chew() setwnd(prompt_window) clrscr() - proutn("COMMAND> ") if scan() == IHEOL: if game.options & OPTION_CURSES: makechart() @@ -6590,7 +6534,7 @@ def makemoves(): elif cmd == "EMEXIT": # Emergency exit clrscr() # Hide screen freeze(True) # forced save - os.exit(1) # And quick exit + raise SysExit,1 # And quick exit elif cmd == "PROBE": probe() # Launch probe if game.ididit: @@ -6618,14 +6562,6 @@ def makemoves(): game.alldone = True # quit the game elif cmd == "HELP": helpme() # get help - elif cmd == "SEED": # set random-number seed - key = scan() - if key == IHREAL: - seed = int(round(aaitem)) -#ifdef BSD_BUG_FOR_BUG -# elif cmd == "VISUAL": -# visual() # perform visual scan -#endif while True: if game.alldone: break # Game has ended @@ -6880,16 +6816,17 @@ if __name__ == '__main__': for (switch, val) in options: if switch == '-r': try: - replayfp = open(optarg, "r") + replayfp = open(val, "r") except IOError: - sys.stderr.write("sst: can't open replay file %s\n" % optarg) - os.exit(1) + sys.stderr.write("sst: can't open replay file %s\n" % val) + raise SysExit, 1 line = replayfp.readline().strip() try: (key, seed) = line.split() seed = int(seed) + sys.stderr.write("sst2k: seed set to %d\n" % seed) except ValueError: - sys.stderr.write("sst: replay file %s is ill-formed\n"%optarg) + sys.stderr.write("sst: replay file %s is ill-formed\n"% val) os.exit(1) game.options |= OPTION_TTY game.options &=~ OPTION_CURSES @@ -6933,6 +6870,7 @@ if __name__ == '__main__': if ja() == True: chew2() freeze(False) + chew() proutn(_("Do you want to play again? ")) if not ja(): break