status command is almost working. Must resolve the mess with planet pointers.
[super-star-trek.git] / src / sst.py
index 5655c7e09c96f494b34e202c7767794863603e7a..5419624172b8151ae37bbe2eb8d8888e12a4a910 100644 (file)
@@ -1587,7 +1587,7 @@ def attack(torps_ok):
        moveklings()
 
     # if no enemies remain after movement, we're done 
-    if game.nenhere==0 or (game.nenhere==1 and iqhere and not iqengry):
+    if game.nenhere==0 or (game.nenhere==1 and thing == game.quadrant and not iqengry):
        return
 
     # set up partial hits if attack happens during shield status change 
@@ -1737,8 +1737,8 @@ def deadkl(w, type, mv):
        game.ithere = False
     elif type == IHQUEST:
        # Killed a Thingy
-        global iqhere, iqengry
-       iqhere = iqengry = False
+        global iqengry
+       iqengry = False
        invalidate(thing)
     else:
        # Some type of a Klingon 
@@ -3712,9 +3712,6 @@ def highvideo():
     if game.options & OPTION_CURSES:
        curwnd.attron(curses.A_REVERSE)
  
-def commandhook(cmd, before):
-    pass
-
 #
 # Things past this point have policy implications.
 # 
@@ -3734,7 +3731,7 @@ def drawmaps(mode):
            setwnd(report_window)
            report_window.clear()
            report_window.move(0, 0)
-           status(0)
+           status()
            setwnd(lrscan_window)
            lrscan_window.clear()
            lrscan_window.move(0, 0)
@@ -3825,8 +3822,8 @@ def prstat(txt, data):
        skip(1)
        setwnd(status_window)
     else:
-        proutn(" " * NSYM - len(tx))
-    vproutn(data)
+        proutn(" " * (NSYM - len(txt)))
+    proutn(data)
     skip(1)
     if game.options & OPTION_CURSES:
        setwnd(report_window)
@@ -5455,14 +5452,14 @@ def chart():
            else:
                proutn(" ")
            if game.state.galaxy[i][j].supernova:
-               strcpy(buf, "***")
+               show = "***"
            elif not game.state.galaxy[i][j].charted and game.state.galaxy[i][j].starbase:
-               strcpy(buf, ".1.")
+               show = ".1."
            elif game.state.galaxy[i][j].charted:
-               sprintf(buf, "%3d" % (game.state.chart[i][j].klingons*100 + game.state.chart[i][j].starbase * 10 + game.state.chart[i][j].stars))
+               show = "%3d" % (game.state.chart[i][j].klingons*100 + game.state.chart[i][j].starbase * 10 + game.state.chart[i][j].stars)
            else:
-               strcpy(buf, "...")
-           proutn(buf)
+               show = "..."
+           proutn(show)
            if (game.options & OPTION_SHOWME) and i == game.quadrant.x and j == game.quadrant.y:
                proutn(">")
            else:
@@ -5487,13 +5484,13 @@ def sectscan(goodScan, i, j):
     else:
        proutn("- ")
 
-def status(req):
+def status(req=0):
     # print status report lines 
 
     if not req or req == 1:
        prstat(_("Stardate"), _("%.1f, Time Left %.2f") \
                % (game.state.date, game.state.remtime))
-    elif not req or req == 2:
+    if not req or req == 2:
        if game.condition != "docked":
            newcnd()
         dam = 0
@@ -5501,40 +5498,40 @@ def status(req):
            if game.damage[t]>0: 
                dam += 1
        prstat(_("Condition"), _("%s, %i DAMAGES") % (game.condition.upper(), dam))
-    elif not req or req == 3:
+    if not req or req == 3:
        prstat(_("Position"), "%s , %s" % (game.quadrant, game.sector))
-    elif not req or req == 4:
+    if not req or req == 4:
        if damaged(DLIFSUP):
            if game.condition == "docked":
-               sprintf(s, _("DAMAGED, Base provides"))
+               s = _("DAMAGED, Base provides")
            else:
-               sprintf(s, _("DAMAGED, reserves=%4.2f") % game.lsupres)
+               s = _("DAMAGED, reserves=%4.2f") % game.lsupres
        else:
-           sprintf(s, _("ACTIVE"))
+           s = _("ACTIVE")
        prstat(_("Life Support"), s)
-    elif not req or req == 5:
-       prstat(_("Warp Factor"), "%.1f" % (game.warpfac))
-    elif not req or req == 6:
+    if not req or req == 5:
+       prstat(_("Warp Factor"), "%.1f" % game.warpfac)
+    if not req or req == 6:
         extra = ""
         if game.icrystl and (game.options & OPTION_SHOWME):
             extra = _(" (have crystals)")
-       prstat(_("Energy"), "%.2f%s" % game.energy, extra)
-    elif not req or req == 7:
+       prstat(_("Energy"), "%.2f%s" % (game.energy, extra))
+    if not req or req == 7:
        prstat(_("Torpedoes"), "%d" % (game.torps))
-    elif not req or req == 8:
+    if not req or req == 8:
        if damaged(DSHIELD):
-           strcpy(s, _("DAMAGED,"))
+           s = _("DAMAGED,")
        elif game.shldup:
-           strcpy(s, _("UP,"))
+           s = _("UP,")
        else:
-           strcpy(s, _("DOWN,"))
+           s = _("DOWN,")
        data = _(" %d%% %.1f units") \
                % (int((100.0*game.shield)/game.inshld + 0.5), game.shield)
-       prstat(_("Shields"), s)
-    elif not req or req == 9:
+       prstat(_("Shields"), s+data)
+    if not req or req == 9:
         prstat(_("Klingons Left"), "%d" \
                % (game.state.remkl + game.state.remcom + game.state.nscrem))
-    elif not req or req == 10:
+    if not req or req == 10:
        if game.options & OPTION_WORLDS:
            plnet = game.state.galaxy[game.quadrant.x][game.quadrant.y].planet
            if plnet != NOPLANET and game.state.planets[plnet].inhabited:
@@ -6017,7 +6014,7 @@ def setup(needprompt):
             if not game.state.galaxy[w.x][w.y].supernova and \
                game.state.galaxy[w.x][w.y].klingons + klump <= MAXKLQUAD:
                 break
-       game.state.galaxy[w.x][w.y].klingons += klump
+       game.state.galaxy[w.x][w.y].klingons += int(klump)
         if krem <= 0:
             break
     # Position Klingon Commander Ships
@@ -6103,7 +6100,7 @@ def setup(needprompt):
        prout(_("  YOU'LL NEED IT."))
     waitfor()
     newqad(False)
-    if game.nenhere - iqhere-game.ithere:
+    if game.nenhere - (thing == game.quadrant) - game.ithere:
        game.shldup = True
     if game.neutz:     # bad luck to start in a Romulan Neutral Zone
        attack(False)
@@ -6262,8 +6259,7 @@ def newqad(shutup):
     game.landed = False
     game.ientesc = False
     game.ithere = False
-    global iqhere, iqengry
-    iqhere = False
+    global iqengry
     iqengry = False
     game.iseenit = False
     if game.iscate:
@@ -6343,8 +6339,6 @@ def newqad(shutup):
            w = dropin(IHQUEST)
            thing = randplace(GALSIZE)
            game.nenhere += 1
-            global iqhere
-           iqhere = True
            game.ks[game.nenhere] = w
            game.kdist[game.nenhere] = game.kavgd[game.nenhere] = \
                distance(game.sector, w)
@@ -6401,7 +6395,7 @@ def newqad(shutup):
 def sortklings():
     # sort Klingons by distance from us 
     # The author liked bubble sort. So we will use it. :-(
-    if game.nenhere-iqhere-game.ithere < 2:
+    if game.nenhere-(thing==game.quadrant)-game.ithere < 2:
        return
     while True:
        sw = False
@@ -6494,7 +6488,7 @@ def listCommands():
     k = 0
     proutn(_("LEGAL COMMANDS ARE:"))
     for key in commands:
-       if ACCEPT(cmd):
+       if ACCEPT(key):
             if k % 5 == 0:
                 skip(1)
             proutn("%-12s " % key) 
@@ -6582,15 +6576,18 @@ def makemoves():
            clrscr()
            setwnd(message_window)
            clrscr()
-            cmd = citem.upper()
-            if cmd not in commands:
+            candidates = filter(lambda x: x.startswith(citem.upper()),
+                                commands)
+            if len(candidates) == 1:
+                cmd = candidates[0]
+                break
+            else:
                 listCommands()
                 continue
-       commandhook(commands[i].name, True)
        if cmd == "SRSCAN":             # srscan
            srscan()
        elif cmd == "STATUS":           # status
-           status(0)
+           status()
        elif cmd == "REQUEST":          # status request 
            request()
        elif cmd == "LRSCAN":           # long range scan
@@ -6695,7 +6692,6 @@ def makemoves():
 #      elif cmd == "VISUAL":
 #          visual()                    # perform visual scan
 #endif
-       commandhook(commands[i].name, False)
        while True:
            if game.alldone:
                break           # Game has ended
@@ -6936,11 +6932,11 @@ def debugme():
        atover(True)
 
 if __name__ == '__main__':
-    global line, thing, game, idebug, iqhere, iqengry
+    global line, thing, game, idebug, iqengry
     game = citem = aaitem = inqueue = None
     line = ''
     thing = coord()
-    iqhere = iqengry = False
+    iqengry = False
     game = gamestate()
     idebug = 0
 
@@ -6997,7 +6993,7 @@ if __name__ == '__main__':
        setwnd(fullscreen_window)
        clrscr()
        prelim()
-       setup(needprompt=not line)
+       setup(needprompt=not inqueue)
        if game.alldone:
            score()
            game.alldone = False