Invert the sense of a test for better readability.
[super-star-trek.git] / src / sst.py
index 3e7f2c2a94f4de890e9624e57917445909e53624..1fc432384991f5e232b05cb2e78a59ae3210a046 100644 (file)
@@ -179,13 +179,12 @@ more:
 the LRSCAN command is no longer needed.  (Controlled by OPTION_AUTOSCAN
 and turned off if game type is "plain" or "almy".)
 """
-import os, sys, math, curses, time, readline, cPickle, random, copy
+import os, sys, math, curses, time, readline, cPickle, random, copy, gettext
 
 SSTDOC         = "/usr/share/doc/sst/sst.doc"
 DOC_NAME       = "sst.doc"
 
-# Stub to be replaced
-def _(str): return str
+def _(str): return gettext.gettext(str)
 
 PHASEFAC       = 2.0
 GALSIZE        = 8
@@ -653,7 +652,6 @@ def tryexit(enemy, look, irun):
                break
     return True; # success 
 
-#
 # The bad-guy movement algorithm:
 # 
 # 1. Enterprise has "force" based on condition of phaser and photon torpedoes.
@@ -691,7 +689,6 @@ def tryexit(enemy, look, irun):
 # retreat, especially at high skill levels.
 # 
 # 5.  Motion is limited to skill level, except for SC hi-tailing it out.
-# 
 
 def movebaddy(enemy):
     "Tactical movement for the bad guys."
@@ -856,9 +853,9 @@ def movescom(iq, avoid):
     "Commander movement helper." 
     # Avoid quadrants with bases if we want to avoid Enterprise 
     if not welcoming(iq) or (avoid and iq in game.state.baseq):
-       return True
+       return False
     if game.justin and not game.iscate:
-       return True
+       return False
     # do the move 
     game.state.galaxy[game.state.kscmdr.i][game.state.kscmdr.j].klingons -= 1
     game.state.kscmdr = iq
@@ -890,7 +887,7 @@ def movescom(iq, avoid):
                proutn(_("   a planet in Quadrant %s has been destroyed") % game.state.kscmdr)
                prout(_("   by the Super-commander.\""))
            break
-    return False; # looks good! 
+    return True; # looks good! 
                        
 def supercommander():
     "Move the Super Commander." 
@@ -904,7 +901,7 @@ def supercommander():
     if not game.iscate and avoid:
        # compute move away from Enterprise 
        idelta = game.state.kscmdr-game.quadrant
-       if math.sqrt(idelta.i*idelta.i+idelta.j*idelta.j) > 2.0:
+       if idelta.distance() > 2.0:
            # circulate in space 
            idelta.i = game.state.kscmdr.j-game.quadrant.j
            idelta.j = game.quadrant.i-game.state.kscmdr.i
@@ -948,24 +945,24 @@ def supercommander():
     # there was what looked like a bug in the Almy C code here,
     # but it might be this translation is just wrong.
     iq = game.state.kscmdr + idelta
-    if movescom(iq, avoid):
+    if not movescom(iq, avoid):
        # failed -- try some other maneuvers 
        if idelta.i==0 or idelta.j==0:
            # attempt angle move 
            if idelta.i != 0:
                iq.j = game.state.kscmdr.j + 1
-               if movescom(iq, avoid):
+               if not movescom(iq, avoid):
                    iq.j = game.state.kscmdr.j - 1
                    movescom(iq, avoid)
-           else:
+           elif idelta.j != 0:
                iq.i = game.state.kscmdr.i + 1
-               if movescom(iq, avoid):
+               if not movescom(iq, avoid):
                    iq.i = game.state.kscmdr.i - 1
                    movescom(iq, avoid)
        else:
            # try moving just in x or y 
            iq.j = game.state.kscmdr.j
-           if movescom(iq, avoid):
+           if not movescom(iq, avoid):
                iq.j = game.state.kscmdr.j + idelta.j
                iq.i = game.state.kscmdr.i
                movescom(iq, avoid)
@@ -973,7 +970,7 @@ def supercommander():
     if len(game.state.baseq) == 0:
        unschedule(FSCMOVE)
     else:
-        for (i, ibq) in enumerate(game.state.baseq):
+        for ibq in game.state.baseq:
            if ibq == game.state.kscmdr and game.state.kscmdr == game.battle:
                # attack the base 
                if avoid:
@@ -1657,7 +1654,7 @@ def deadkl(w, type, mv):
     proutn(crmena(True, type, "sector", mv))
     # Decide what kind of enemy it is and update appropriately 
     if type == IHR:
-        # chalk up a Romulan 
+        # Chalk up a Romulan 
         game.state.galaxy[game.quadrant.i][game.quadrant.j].romulans -= 1
         game.irhere -= 1
         game.state.nromrem -= 1
@@ -1669,7 +1666,7 @@ def deadkl(w, type, mv):
         global thing
         thing = None
     else:
-        # Some type of a Klingon 
+        # Killed some type of Klingon 
         game.state.galaxy[game.quadrant.i][game.quadrant.j].klingons -= 1
         game.klhere -= 1
         if type == IHC:
@@ -3307,6 +3304,8 @@ curwnd = None
 
 def iostart():
     global stdscr, rows
+    gettext.bindtextdomain("sst", "/usr/local/share/locale")
+    gettext.textdomain("sst")
     if not (game.options & OPTION_CURSES):
        ln_env = os.getenv("LINES")
         if ln_env:
@@ -3358,7 +3357,7 @@ def pause_game():
     if game.options & OPTION_CURSES:
         drawmaps(0)
         setwnd(prompt_window)
-        prompt_window.wclear()
+        prompt_window.clear()
         prompt_window.addstr(prompt)
         prompt_window.getstr()
         prompt_window.clear()
@@ -3453,8 +3452,8 @@ def setwnd(wnd):
 def clreol():
     "Clear to end of line -- can be a no-op in tty mode" 
     if game.options & OPTION_CURSES:
-        wclrtoeol(curwnd)
-        wrefresh(curwnd)
+        curwnd.clrtoeol()
+        curwnd.refresh()
 
 def clrscr():
     "Clear screen -- can be a no-op in tty mode."
@@ -3904,8 +3903,8 @@ def getcourse(isprobe):
                prout(_("Ensign Chekov- \"Course laid in, Captain.\""))
         # the actual deltas get computed here
         delta = coord()
-       delta.j = dquad.j-game.quadrant.j + 0.1*(dsect.j-game.sector.j)
-       delta.i = game.quadrant.i-dquad.i + 0.1*(game.sector.i-dsect.i)
+       delta.j = dquad.j-game.quadrant.j + (dsect.j-game.sector.j)/(QUADSIZE*1.0)
+       delta.i = game.quadrant.i-dquad.i + (game.sector.i-dsect.i)/(QUADSIZE*1.0)
     else: # manual 
        while key == "IHEOL":
            proutn(_("X and Y displacements- "))
@@ -5291,8 +5290,8 @@ def eta():
     if not VALID_QUADRANT(w1.i, w1.j) or not VALID_SECTOR(w2.i, w2.j):
        huh()
        return
-    game.dist = math.sqrt((w1.j-game.quadrant.j+0.1*(w2.j-game.sector.j))**2+
-               (w1.i-game.quadrant.i+0.1*(w2.i-game.sector.i))**2)
+    game.dist = math.sqrt((w1.j-game.quadrant.j+(w2.j-game.sector.j)/(QUADSIZE*1.0))**2+
+               (w1.i-game.quadrant.i+(w2.i-game.sector.i)/(QUADSIZE*1.0))**2)
     wfl = False
     if prompt:
        prout(_("Answer \"no\" if you don't know the value:"))
@@ -5389,18 +5388,17 @@ def prelim():
 def freeze(boss):
     "Save game."
     if boss:
-       scanner.token = "emsave.trk"
-    else:
+       scanner.push("emsave.trk")
+    key = scanner.next()
+    if key == "IHEOL":
+        proutn(_("File name: "))
         key = scanner.next()
-       if key == "IHEOL":
-           proutn(_("File name: "))
-           key = scanner.next()
-       if key != "IHALPHA":
-           huh()
-           return
-       scanner.chew()
-        if '.' not in scanner.token:
-           scanner.token += ".trk"
+    if key != "IHALPHA":
+        huh()
+        return
+    scanner.chew()
+    if '.' not in scanner.token:
+        scanner.token += ".trk"
     try:
         fp = open(scanner.token, "wb")
     except IOError:
@@ -5443,11 +5441,11 @@ systnames = (
     _("Tellar Prime (Miracht)"),       # TOS: "Journey to Babel" 
     _("Vulcan (T'Khasi)"),     # many episodes 
     _("Medusa"),               # TOS: "Is There in Truth No Beauty?" 
-    _("Argelius II (Nelphia)"),# TOS: "Wolf in the Fold" ("IV" in BSD) 
+    _("Argelius II (Nelphia)"),        # TOS: "Wolf in the Fold" ("IV" in BSD) 
     _("Ardana"),               # TOS: "The Cloud Minders" 
     _("Catulla (Cendo-Prae)"), # TOS: "The Way to Eden" 
     _("Gideon"),               # TOS: "The Mark of Gideon" 
-    _("Aldebaran III"),        # TOS: "The Deadly Years" 
+    _("Aldebaran III"),                # TOS: "The Deadly Years" 
     _("Alpha Majoris I"),      # TOS: "Wolf in the Fold" 
     _("Altair IV"),            # TOS: "Amok Time 
     _("Ariannus"),             # TOS: "Let That Be Your Last Battlefield" 
@@ -5708,8 +5706,6 @@ def choose():
        if not scanner.inqueue: # Can start with command line options 
            proutn(_("Would you like a regular, tournament, or saved game? "))
         scanner.next()
-       if len(scanner.token)==0: # Try again
-           continue
         if scanner.sees("tournament"):
            while scanner.next() == "IHEOL":
                proutn(_("Type in tournament number-"))
@@ -5777,7 +5773,7 @@ def choose():
        # Approximates Tom Almy's version.
        game.options &=~ (OPTION_THINGY | OPTION_BLKHOLE | OPTION_BASE | OPTION_WORLDS)
        game.options |= OPTION_ALMY
-    elif scanner.sees("fancy"):
+    elif scanner.sees("fancy") or scanner.sees("\n"):
        pass
     elif len(scanner.token):
         proutn(_("What is \"%s\"?") % scanner.token)
@@ -6296,10 +6292,10 @@ class sstscanner:
             if not line:
                 continue
             else:
-                self.inqueue = line.lstrip().split() + ["IHEOL"] 
+                self.inqueue = line.lstrip().split() + ["\n"]
         # From here on in it's all looking at the queue
         self.token = self.inqueue.pop(0)
-        if self.token == "IHEOL":
+        if self.token == "\n":
             self.type = "IHEOL"
             return "IHEOL"
         try:
@@ -6323,10 +6319,6 @@ class sstscanner:
         # Demand input for next scan
         self.inqueue = []
         self.real = self.token = None
-    def chew2(self):
-        # return "IHEOL" next time 
-        self.inqueue = ["IHEOL"]
-        self.real = self.token = None
     def sees(self, s):
         # compares s to item and returns true if it matches to the length of s
         return s.startswith(self.token)
@@ -6530,7 +6522,8 @@ if __name__ == '__main__':
                 if game.tourn and game.alldone:
                     proutn(_("Do you want your score recorded?"))
                     if ja() == True:
-                        scanner.chew2()
+                        scanner.chew()
+                        scanner.push("\n")
                         freeze(False)
                 scanner.chew()
                 proutn(_("Do you want to play again? "))
@@ -6545,4 +6538,3 @@ if __name__ == '__main__':
         if logfp:
             logfp.close()
         print ""
-        pass