Make m m .1 work again.
[super-star-trek.git] / sst.py
diff --git a/sst.py b/sst.py
index a4ed80e97f5d5b29f23421e7846f9b4fa0816ee2..7c7d075a8c9527a484e089dcfd070ae77badfade 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
 
@@ -2120,20 +2127,22 @@ def capture():
     # intelligent design
     # x = 300 + 25*skill;
     x = game.energy / (weakest.power * len(klingons))
-    x *= 2.5;  # would originally have been equivalent of 1.4,
+    #prout(_("Stats: energy = %s, kpower = %s, klingons = %s")
+    #      % (game.energy, weakest.power, len(klingons))) 
+    x *= 2.5  # would originally have been equivalent of 1.4,
                # but we want command to work more often, more humanely */
-    #prout(_("Prob = %d (%.4f)\n", i, x))
+    #prout(_("Prob = %.4f" % x))
     #  x = 100; // For testing, of course!
-    if x > randreal(100):
+    if x < randreal(100):
         # guess what, he surrendered!!! */
         prout(_("Klingon captain at %s surrenders.") % weakest.location)
         i = randreal(200)
         if i > 0:
-            prout(_("%d Klingons commit suicide rather than be taken captive.") % 200 - i)
-        if i > brigfree:
-            prout(_("%d Klingons die because there is no room for them in the brig.") % i-brigfree)
-            i = brigfree
-        brigfree -= i
+            prout(_("%d Klingons commit suicide rather than be taken captive.") % (200 - i))
+        if i > game.brigfree:
+            prout(_("%d Klingons die because there is no room for them in the brig.") % (i-brigfree))
+            i = game.brigfree
+        game.brigfree -= i
         prout(_("%d captives taken") % i)
         deadkl(weakest.location, weakest.type, game.sector)
         if (game.state.remkl + len(game.state.kcmdr) + game.state.nscrem)<=0:
@@ -2141,7 +2150,7 @@ def capture():
         return
 
        # big surprise, he refuses to surrender */
-       prout(_("Fat chance, captain!"))
+    prout(_("Fat chance, captain!"))
 
 # Code from events.c begins here.
 
@@ -2362,7 +2371,7 @@ def events():
             if game.state.galaxy[game.quadrant.i][game.quadrant.j].supernova:
                 return
         elif evcode == FSPY: # Check with spy to see if SC should tractor beam
-            if game.state.nscrem == 0 or game.state.iscloaked or \
+            if game.state.nscrem == 0 or game.iscloaked or \
                 ictbeam or istract or \
                 game.condition == "docked" or game.isatb == 1 or game.iscate:
                 return
@@ -3156,6 +3165,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 +3413,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 +3485,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
@@ -3526,7 +3540,7 @@ def clrscr():
     linecount = 0
 
 def textcolor(color=DEFAULT):
-    if game.options & OPTION_COLOR:
+    if (game.options & OPTION_COLOR) and (game.options & OPTION_CURSES):
         if color == DEFAULT:
             curwnd.attrset(0)
         elif color ==  BLACK:
@@ -3563,7 +3577,7 @@ def textcolor(color=DEFAULT):
             curwnd.attron(curses.color_pair(curses.COLOR_WHITE) | curses.A_BOLD)
 
 def highvideo():
-    if game.options & OPTION_COLOR:
+    if (game.options & OPTION_COLOR) and (game.options & OPTION_CURSES):
         curwnd.attron(curses.A_REVERSE)
 
 #
@@ -3997,15 +4011,16 @@ def getcourse(isprobe):
             iprompt = True
             key = scanner.nexttok()
         itemp = "verbose"
-        if key != "IHREAL":
+        if key == "IHREAL":
+            delta.j = scanner.real
+        else:
             huh()
             raise TrekError
-        delta.j = scanner.real
         key = scanner.nexttok()
-        if key != "IHREAL":
-            huh()
-            raise TrekError
-        delta.i = scanner.real
+        if key == "IHREAL":
+            delta.i = scanner.real
+        else:
+            delta.i = 0
     # Check for zero movement
     if delta.i == 0 and delta.j == 0:
         scanner.chew()
@@ -5273,6 +5288,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 +5303,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 +5871,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 +6374,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