fixed visual bugs
[super-star-trek.git] / src / sst.py
index fe29b948d11870230dff7c043789bc50e9474b44..501b40750c9e2d502eb2b3c3060fb462825cfebf 100644 (file)
@@ -13,8 +13,7 @@ ion how to modify (and how not to modify!) this code.
 """
 import os, sys, math, curses, time, readline, cPickle, random, copy, gettext, getpass
 
 """
 import os, sys, math, curses, time, readline, cPickle, random, copy, gettext, getpass
 
-SSTDOC         = "/usr/share/doc/sst/sst.doc"
-DOC_NAME       = "sst.doc"
+docpath        = (".", "../doc", "/usr/share/doc/sst")
 
 def _(str): return gettext.gettext(str)
 
 
 def _(str): return gettext.gettext(str)
 
@@ -1483,8 +1482,8 @@ def targetcheck(w):
        return None
     return delta.bearing()
 
        return None
     return delta.bearing()
 
-def photon():
-    "Launch photon torpedo."
+def torps():
+    "Launch photon torpedo salvo."
     course = []
     game.ididit = False
     if damaged(DPHOTON):
     course = []
     game.ididit = False
     if damaged(DPHOTON):
@@ -3064,6 +3063,12 @@ curwnd = None
 
 def iostart():
     global stdscr, rows
 
 def iostart():
     global stdscr, rows
+    "for some recent versions of python2, the following enables UTF8"
+    "for the older ones we probably need to set C locale, and the python3"
+    "has no problems at all"
+    if sys.version_info.major < 3:
+       import locale
+       locale.setlocale(locale.LC_ALL, "")
     gettext.bindtextdomain("sst", "/usr/local/share/locale")
     gettext.textdomain("sst")
     if not (game.options & OPTION_CURSES):
     gettext.bindtextdomain("sst", "/usr/local/share/locale")
     gettext.textdomain("sst")
     if not (game.options & OPTION_CURSES):
@@ -3149,7 +3154,7 @@ def skip(i):
        if game.options & OPTION_CURSES:
             (y, x) = curwnd.getyx()
             (my, mx) = curwnd.getmaxyx()
        if game.options & OPTION_CURSES:
             (y, x) = curwnd.getyx()
             (my, mx) = curwnd.getmaxyx()
-           if curwnd == message_window and y >= my - 3:
+           if curwnd == message_window and y >= my - 2:
                pause_game()
                clrscr()
            else:
                pause_game()
                clrscr()
            else:
@@ -4874,7 +4879,8 @@ def lrscan(silent):
                    proutn(" ***")
                elif not silent:
                    proutn(" %3d" % (game.state.chart[x][y].klingons*100 + game.state.chart[x][y].starbase * 10 + game.state.chart[x][y].stars))
                    proutn(" ***")
                elif not silent:
                    proutn(" %3d" % (game.state.chart[x][y].klingons*100 + game.state.chart[x][y].starbase * 10 + game.state.chart[x][y].stars))
-       prout(" ")
+       if not silent:
+           prout(" ")
 
 def damagereport():
     "Damage report."
 
 def damagereport():
     "Damage report."
@@ -5812,7 +5818,7 @@ def helpme():
        setwnd(message_window)
        if key == "IHEOL":
            return
        setwnd(message_window)
        if key == "IHEOL":
            return
-        if scanner.token in commands or scanner.token == "ABBREV":
+        if scanner.token.upper() in commands or scanner.token == "ABBREV":
            break
        skip(1)
        listCommands()
            break
        skip(1)
        listCommands()
@@ -5820,22 +5826,20 @@ def helpme():
        scanner.chew()
        skip(1)
     cmd = scanner.token.upper()
        scanner.chew()
        skip(1)
     cmd = scanner.token.upper()
-    try:
-        fp = open(SSTDOC, "r")
-    except IOError:
+    for directory in docpath:
         try:
         try:
-            fp = open(DOC_NAME, "r")
+            fp = open(os.path.join(directory, "sst.doc"), "r")
+            break
         except IOError:
         except IOError:
-            prout(_("Spock-  \"Captain, that information is missing from the"))
-            proutn(_("   computer. You need to find "))
-            proutn(DOC_NAME)
-            prout(_(" and put it in the"))
-            proutn(_("   current directory or to "))
-            proutn(SSTDOC)
-            prout(".\"")
-            # This used to continue: "You need to find SST.DOC and put 
-            # it in the current directory."
-            return
+            pass
+    else:
+        prout(_("Spock-  \"Captain, that information is missing from the"))
+        prout(_("   computer. You need to find sst.doc and put it somewhere"))
+        proutn(_("   in these directories: %s") % ":".join(docpath))
+        prout(".\"")
+        # This used to continue: "You need to find SST.DOC and put 
+        # it in the current directory."
+        return
     while True:
         linebuf = fp.readline()
        if linebuf == '':
     while True:
         linebuf = fp.readline()
        if linebuf == '':
@@ -5844,12 +5848,13 @@ def helpme():
            return
        if linebuf[0] == '%' and linebuf[1] == '%' and linebuf[2] == ' ':
             linebuf = linebuf[3:].strip()
            return
        if linebuf[0] == '%' and linebuf[1] == '%' and linebuf[2] == ' ':
             linebuf = linebuf[3:].strip()
-            if cmd == linebuf:
+            if cmd.upper() == linebuf:
                break
     skip(1)
     prout(_("Spock- \"Captain, I've found the following information:\""))
     skip(1)
                break
     skip(1)
     prout(_("Spock- \"Captain, I've found the following information:\""))
     skip(1)
-    while linebuf in fp:
+    while True:
+        linebuf = fp.readline()
         if "******" in linebuf:
            break
        proutn(linebuf)
         if "******" in linebuf:
            break
        proutn(linebuf)
@@ -5900,8 +5905,8 @@ def makemoves():
            phasers()
            if game.ididit:
                hitme = True
            phasers()
            if game.ididit:
                hitme = True
-       elif cmd == "TORPEDO":          # photon torpedos
-           photon()
+       elif cmd in ("TORPEDO", "PHOTONS"):     # photon torpedos
+           torps()
            if game.ididit:
                hitme = True
        elif cmd == "MOVE":             # move under warp
            if game.ididit:
                hitme = True
        elif cmd == "MOVE":             # move under warp