Fix bug in capture.
[super-star-trek.git] / sst.py
diff --git a/sst.py b/sst.py
index 97e038796f9d44a20f9731c66ba12d420acdee78..cef7b8f13b4a9e2c2e3f63dd71f2806ee125c2fa 100755 (executable)
--- a/sst.py
+++ b/sst.py
@@ -21,6 +21,13 @@ try:
 except ImportError:
     pass
 
+# Prevent lossage under Python 3
+try:
+    my_input = raw_input
+except NameError:
+    my_input = input
+
+
 version = "2.1"
 
 docpath        = (".", "doc/", "/usr/share/doc/sst/")
@@ -943,12 +950,12 @@ def cloak():
             return
     else:
         if not game.iscloaked:
-            proutn(_("Switch cloaking device on?"))
+            proutn(_("Switch cloaking device on? "))
             if not ja():
                 return
             action = "CLON"
         else:
-            proutn(_("Switch cloaking device off?"))
+            proutn(_("Switch cloaking device off? "))
             if not ja():
                 return
             action = "CLOFF"
@@ -961,7 +968,7 @@ def cloak():
             if not ja():
                 return;
         prout("Engineer Scott- \"Aye, Sir.\"");
-        game.iscloaked = FALSE;
+        game.iscloaked = False;
         if game.irhere and game.state.date >= ALGERON and not game.isviolreported:
             prout(_("The Romulan ship discovers you are breaking the Treaty of Algeron!"))
             game.ncviol += 1
@@ -971,7 +978,7 @@ def cloak():
             return;
 
     if action == "CLON":
-        if damage(DCLOAK):
+        if damaged(DCLOAK):
             prout(_("Engineer Scott- \"The cloaking device is damaged, Sir.\""))
             return;
 
@@ -979,9 +986,9 @@ def cloak():
             prout(_("You cannot cloak while docked."))
 
        if game.state.date >= ALGERON and not game.isviolreported:
-            prout(_("Spock- \"Captain, using the cloaking device is be a violation"))
+            prout(_("Spock- \"Captain, using the cloaking device is a violation"))
             prout(_("  of the Treaty of Algeron. Considering the alternatives,"))
-            proutn("  are you sure this is wise?");
+            proutn(_("  are you sure this is wise? "))
             if not ja():
                 return
        prout(_("Engineer Scott- \"Cloaking device has engaging, Sir...\""))
@@ -2111,7 +2118,7 @@ def capture():
     #  Nah, just select the weakest one since it is most likely to
     #  surrender (Tom Almy mod)
     klingons = [e for e in game.enemies if e.type == 'K']
-    weakest = sorted(klingons, key=lambda e: e.power)
+    weakest = sorted(klingons, key=lambda e: e.power)[0]
     game.optime = 0.05         # This action will take some time
     game.ididit = True #  So any others can strike back
 
@@ -2141,7 +2148,7 @@ def capture():
         return
 
        # big surprise, he refuses to surrender */
-       prout(_("Fat chance, captain!"))
+    prout(_("Fat chance, captain!"))
 
 # Code from events.c begins here.
 
@@ -3156,6 +3163,7 @@ def finish(ifin):
         prout(_("to think about pigeons."))
         game.gamewon = True
     score()
+    scanner.chew()     # Clean up leftovers
 
 def score():
     "Compute player's score."
@@ -3403,7 +3411,7 @@ def pause_game():
         sys.stdout.write('\n')
         proutn(prompt)
         if not replayfp:
-            input()
+            my_input()
         sys.stdout.write('\n' * rows)
         linecount = 0
 
@@ -3475,7 +3483,11 @@ def cgetline():
                 elif linein[0] != "#":
                     break
         else:
-            linein = eval(input()) + "\n"
+            try:
+                linein = my_input() + "\n"
+            except EOFError:
+                prout("")
+                sys.exit(0)
     if logfp:
         logfp.write(linein)
     return linein
@@ -5273,6 +5285,8 @@ 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] in ('E', 'F'):
+            if game.iscloaked:
+                highvideo()
             textcolor({"green":GREEN,
                        "yellow":YELLOW,
                        "red":RED,
@@ -5286,8 +5300,6 @@ def sectscan(goodScan, i, j):
                        'R':LIGHTRED,
                        'T':LIGHTRED,
                        }.get(game.quad[i][j], DEFAULT))
-        if game.iscloaked:
-            highvideo()
         proutn("%c " % game.quad[i][j])
         textcolor(DEFAULT)
     else:
@@ -5856,9 +5868,9 @@ def choose():
         game.tourn = game.length = 0
         game.thawed = False
         game.skill = SKILL_NONE
-        scanner.chew()
-#        if not scanner.inqueue: # Can start with command line options
-        proutn(_("Would you like a regular, tournament, or saved game? "))
+        # Do not chew here, we want to use command-line tokens
+        if not scanner.inqueue: # Can start with command line options
+            proutn(_("Would you like a regular, tournament, or saved game? "))
         scanner.nexttok()
         if scanner.sees("tournament"):
             while scanner.nexttok() == "IHEOL":
@@ -6359,6 +6371,8 @@ def makemoves():
                 hitme = True
         elif cmd == "CAPTURE":
             capture()
+        elif cmd == "CLOAK":
+            cloak()
         elif cmd == "DEBUGCMD":                # What do we want for debug???
             debugme()
         elif cmd == "MAYDAY":                # Call for help