Put a timestamp an email in lofiles. Add the replay debugging script.
[super-star-trek.git] / src / sst.py
index 864dfa1b78586e179b3bd614af62375ad2d3250e..74dcbaa3aee8ab27ce8b09f73e4e642330a0c2ca 100644 (file)
@@ -180,7 +180,7 @@ 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,atexit,readline,cPickle,random,getopt,copy
+import os, sys, math, curses, time, readline, cPickle, random, copy
 
 SSTDOC         = "/usr/share/doc/sst/sst.doc"
 DOC_NAME       = "sst.doc"
@@ -256,7 +256,7 @@ class coord:
         return math.sqrt((self.i - other.i)**2 + (self.j - other.j)**2)
     def bearing(self, other=None):
         if not other: other = coord(0, 0)
-        return 1.90985*math.atan2(self.i-other.i, self.j-other.j)
+        return 1.90985*math.atan2(self.j-other.j, self.i-other.i)
     def sgn(self):
         s = coord()
         if self.i == 0:
@@ -1057,11 +1057,11 @@ def movetholian():
     for i in range(QUADSIZE):
        if game.quad[0][i]!=IHWEB and game.quad[0][i]!=IHT:
            return
-       if game.quad[QUADSIZE][i]!=IHWEB and game.quad[QUADSIZE][i]!=IHT:
+       if game.quad[QUADSIZE-1][i]!=IHWEB and game.quad[QUADSIZE-1][i]!=IHT:
            return
        if game.quad[i][0]!=IHWEB and game.quad[i][0]!=IHT:
            return
-       if game.quad[i][QUADSIZE]!=IHWEB and game.quad[i][QUADSIZE]!=IHT:
+       if game.quad[i][QUADSIZE-1]!=IHWEB and game.quad[i][QUADSIZE-1]!=IHT:
            return
     # All plugged up -- Tholian splits 
     game.quad[game.tholian.kloc.i][game.tholian.kloc.j]=IHWEB
@@ -1330,7 +1330,7 @@ def torpedo(origin, course, dispersion, number, nburst):
            shoved = True
        elif iquad in (IHC, IHS, IHR, IHK): # Hit a regular enemy 
            # find the enemy 
-           if withprob(0.05):
+           if iquad in (IHC, IHS) and withprob(0.05):
                prout(crmena(True, iquad, "sector", w) + _(" uses anti-photon device;"))
                prout(_("   torpedo neutralized."))
                return None
@@ -1725,7 +1725,7 @@ def targetcheck(w):
        prout(_("  the Captain's psychological profile.\""))
        scanner.chew()
        return None
-    return 1.90985932*math.atan2(delta.j, delta.i)
+    return delta.bearing()
 
 def photon():
     "Launch photon torpedo."
@@ -3400,7 +3400,10 @@ def skip(i):
                pause_game()
                clrscr()
            else:
-               proutn("\n")
+                try:
+                    curwnd.move(y+1, 0)
+                except curses.error:
+                    pass
        else:
             global linecount
            linecount += 1
@@ -3429,7 +3432,7 @@ def prouts(line):
             time.sleep(0.03)
        proutn(c)
        if game.options & OPTION_CURSES:
-           wrefresh(curwnd)
+           curwnd.refresh()
        else:
            sys.stdout.flush()
     if not replayfp or replayfp.closed:
@@ -3923,8 +3926,8 @@ def getcourse(isprobe, akey):
                prout(_("Ensign Chekov- \"Course laid in, Captain.\""))
         # the actual deltas get computed here
         delta = coord()
-       delta.i = dquad.j-game.quadrant.j + 0.1*(dsect.j-game.sector.j)
-       delta.j = game.quadrant.i-dquad.i + 0.1*(game.sector.i-dsect.i)
+       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)
     else: # manual 
        while key == "IHEOL":
            proutn(_("X and Y displacements- "))
@@ -5311,7 +5314,7 @@ def srscan():
        for j in range(QUADSIZE):
            sectscan(goodScan, i, j)
        skip(1)
-                       
+               
 def eta():
     "Use computer to get estimated time of arrival for a warp jump."
     w1 = coord(); w2 = coord()
@@ -6061,12 +6064,14 @@ commands = {
 
 def listCommands():
     "Generate a list of legal commands."
-    proutn(_("LEGAL COMMANDS ARE:"))
-    for (k, key) in enumerate(commands):
+    prout(_("LEGAL COMMANDS ARE:"))
+    emitted = 0
+    for key in commands:
        if not commands[key] or (commands[key] & game.options):
-            if k % 5 == 0:
+            proutn("%-12s " % key)
+            emitted += 1
+            if emitted % 5 == 4:
                 skip(1)
-            proutn("%-12s " % key) 
     skip(1)
 
 def helpme():
@@ -6512,6 +6517,7 @@ def debugme():
        atover(True)
 
 if __name__ == '__main__':
+    import getopt, socket
     try:
         global line, thing, game, idebug
         game = None
@@ -6563,6 +6569,8 @@ if __name__ == '__main__':
         if logfp:
             logfp.write("# seed %s\n" % seed)
             logfp.write("# options %s\n" % " ".join(arguments))
+            logfp.write("# recorded by %s@%s on %s\n" % \
+                    (os.getenv("LOGNAME"),socket.gethostname(),time.ctime()))
         random.seed(seed)
         scanner = sstscanner()
         map(scanner.append, arguments)