X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=sst.py;h=08377bea38bcd2956ba158391b0482e04bc5b845;hp=4e65748dd6f7b35f195c3129e9cb1a36891b5bde;hb=972cea516e66fb65c86f084103f583d1c51941ef;hpb=a9fb126d166bb25141c7a0d072d0bd4508084549 diff --git a/sst.py b/sst.py index 4e65748..08377be 100755 --- a/sst.py +++ b/sst.py @@ -416,7 +416,7 @@ def randreal(*args): def welcoming(iq): "Would this quadrant welcome another Klingon?" - return iq.valid_Quadrant() and \ + return iq.valid_quadrant() and \ not game.state.galaxy[iq.i][iq.j].supernova and \ game.state.galaxy[iq.i][iq.j].klingons < MAXKLQUAD @@ -663,7 +663,7 @@ def moveklings(): for enemy in game.enemies: if enemy.type in ('K', 'R'): movebaddy(enemy) - game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist)) + sortenemies() def movescom(iq, avoid): "Commander movement helper." @@ -689,7 +689,7 @@ def movescom(iq, avoid): game.klhere -= 1 if game.condition != "docked": newcnd() - game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist)) + sortenemies() # check for a helpful planet for i in range(game.inplan): if game.state.planets[i].quadrant == game.state.kscmdr and \ @@ -915,7 +915,7 @@ def doshield(shraise): action = "SHUP" else: scanner.chew() - return + return if action == "SHUP": # raise shields if game.shldup: prout(_("Shields already up.")) @@ -1107,7 +1107,7 @@ def torpedo(origin, bearing, dispersion, number, nburst): prout(_(" displaced by blast to Sector %s ") % bumpto) for enemy in game.enemies: enemy.kdist = enemy.kavgd = (game.sector-enemy.location).distance() - game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist)) + sortenemies() return None elif iquad in ('C', 'S', 'R', 'K'): # Hit a regular enemy # find the enemy @@ -1150,7 +1150,7 @@ def torpedo(origin, bearing, dispersion, number, nburst): game.quad[bumpto.i][bumpto.j]=iquad for enemy in game.enemies: enemy.kdist = enemy.kavgd = (game.sector-enemy.location).distance() - game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist)) + sortenemies() return None elif iquad == 'B': # Hit a base skip(1) @@ -1423,7 +1423,7 @@ def attack(torps_ok): # After attack, reset average distance to enemies for enemy in game.enemies: enemy.kavgd = enemy.kdist - game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist)) + sortenemies() return def deadkl(w, type, mv): @@ -2664,7 +2664,6 @@ def selfdestruct(): prout(_("SELF-DESTRUCT-SEQUENCE-WILL-BE-ABORTED")) skip(1) scanner.next() - scanner.chew() if game.passwd != scanner.token: prouts(_("PASSWORD-REJECTED;")) skip(1) @@ -2692,11 +2691,9 @@ def kaboom(): skip(1) if len(game.enemies) != 0: whammo = 25.0 * game.energy - l=1 - while l <= len(game.enemies): + for l in range(len(game.enemies)): if game.enemies[l].power*game.enemies[l].kdist <= whammo: deadkl(game.enemies[l].location, game.quad[game.enemies[l].location.i][game.enemies[l].location.j], game.enemies[l].location) - l += 1 finish(FDILITHIUM) def killrate(): @@ -3161,16 +3158,11 @@ def skip(i): "Skip i lines. Pause game if this would cause a scrolling event." for dummy in range(i): if game.options & OPTION_CURSES: - (y, x) = curwnd.getyx() - (my, mx) = curwnd.getmaxyx() - if curwnd == message_window and y >= my - 2: - pause_game() - clrscr() - else: - try: - curwnd.move(y+1, 0) - except curses.error: - pass + (y, x) = curwnd.getyx() + try: + curwnd.move(y+1, 0) + except curses.error: + pass else: global linecount linecount += 1 @@ -3182,6 +3174,11 @@ def skip(i): def proutn(line): "Utter a line with no following line feed." if game.options & OPTION_CURSES: + (y, x) = curwnd.getyx() + (my, mx) = curwnd.getmaxyx() + if curwnd == message_window and y >= my - 2: + pause_game() + clrscr() curwnd.addstr(line) curwnd.refresh() else: @@ -3545,7 +3542,7 @@ def imove(icourse=None, noattack=False): finald = (w-enemy.location).distance() enemy.kavgd = 0.5 * (finald + enemy.kdist) enemy.kdist = finald - game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist)) + sortenemies() if not game.state.galaxy[game.quadrant.i][game.quadrant.j].supernova: attack(torps_ok=False) for enemy in game.enemies: @@ -5511,8 +5508,9 @@ def choose(): game.tourn = game.length = 0 game.thawed = False game.skill = SKILL_NONE - if not scanner.inqueue: # Can start with command line options - proutn(_("Would you like a regular, tournament, or saved game? ")) + scanner.chew() +# if not scanner.inqueue: # Can start with command line options + proutn(_("Would you like a regular, tournament, or saved game? ")) scanner.next() if scanner.sees("tournament"): while scanner.next() == "IHEOL": @@ -5634,6 +5632,10 @@ def newkling(): "Drop new Klingon into current quadrant." return Enemy('K', loc=dropin(), power=randreal(300,450)+25.0*game.skill) +def sortenemies(): + "Sort enemies by distance so 'nearest' is meaningful." + game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist)) + def newqad(): "Set up a new state of quadrant, for when we enter or re-enter it." game.justin = True @@ -5727,8 +5729,7 @@ def newqad(): game.quad[QUADSIZE-1][0] = 'X' if game.quad[QUADSIZE-1][QUADSIZE-1]=='.': game.quad[QUADSIZE-1][QUADSIZE-1] = 'X' - # Sort enemies by distance so 'nearest' is meaningful - game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist)) + sortenemies() # And finally the stars for i in range(q.stars): dropin('*')