X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=src%2Fsst.py;h=d3047cd7dd8b2d2e2e134ea02769505cc4f9f232;hp=103e49fa90c9a7d5a4c02bcb206bcd80f83b3010;hb=80a9f53a470b74014623901f67013b5be50a5552;hpb=9bb286f638aae37a21d25d3a2a4cb8f11deb22cc diff --git a/src/sst.py b/src/sst.py index 103e49f..d3047cd 100644 --- a/src/sst.py +++ b/src/sst.py @@ -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 @@ -335,9 +334,9 @@ class snapshot: self.baseq = [] # Base quadrant coordinates self.kcmdr = [] # Commander quadrant coordinates self.kscmdr = coord() # Supercommander quadrant coordinates - # the galaxy (subscript 0 not used) + # the galaxy self.galaxy = fill2d(GALSIZE, lambda i, j: quadrant()) - # the starchart (subscript 0 not used) + # the starchart self.chart = fill2d(GALSIZE, lambda i, j: page()) class event: @@ -524,10 +523,8 @@ class gamestate: self.damfac = 0.0 # damage factor self.lastchart = 0.0 # time star chart was last updated self.cryprob = 0.0 # probability that crystal will work - self.probex = 0.0 # location of probe - self.probey = 0.0 # - self.probeinx = 0.0 # probe x,y increment - self.probeiny = 0.0 # + self.probe = None # location of probe + self.probein = None # probe i,j increment self.height = 0.0 # height of orbit around planet def recompute(self): # Stas thinks this should be (C expression): @@ -537,7 +534,7 @@ class gamestate: # after killing the last klingon when score is shown -- perhaps also # if the only remaining klingon is SCOM. game.state.remtime = game.state.remres/(game.state.remkl + 4*len(game.state.kcmdr)) -# From enumerated type 'feature' + IHR = 'R' IHK = 'K' IHC = 'C' @@ -557,8 +554,6 @@ IHMATER0 = '-' IHMATER1 = 'o' IHMATER2 = '0' - -# From enumerated type 'FINTYPE' FWON = 0 FDEPLETE = 1 FLIFESUP = 2 @@ -582,10 +577,6 @@ FTRIBBLE = 19 FHOLE = 20 FCREW = 21 -# Log the results of pulling random numbers so we can check determinism. - -import traceback - def withprob(p): v = random.random() #logfp.write("# withprob(%s) -> %f (%s) at %s\n" % (p, v, v 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 @@ -2465,21 +2454,20 @@ def events(): supercommander() elif evcode == FDSPROB: # Move deep space probe schedule(FDSPROB, 0.01) - game.probex += game.probeinx - game.probey += game.probeiny - i = (int)(game.probex/QUADSIZE +0.05) - j = (int)(game.probey/QUADSIZE + 0.05) + game.probe += game.probein + i = int(round(game.probe.i/float(QUADSIZE))) + j = int(round(game.probe.j/float(QUADSIZE))) if game.probec.i != i or game.probec.j != j: game.probec.i = i game.probec.j = j if not VALID_QUADRANT(i, j) or \ game.state.galaxy[game.probec.i][game.probec.j].supernova: # Left galaxy or ran into supernova - if comunicating(): + if communicating(): announce() skip(1) proutn(_("Lt. Uhura- \"The deep space probe ")) - if not VALID_QUADRANT(j, i): + if not VALID_QUADRANT(i, j): proutn(_("has left the galaxy")) else: proutn(_("is no longer transmitting")) @@ -2500,8 +2488,7 @@ def events(): pdest.charted = True game.proben -= 1 # One less to travel if game.proben == 0 and game.isarmed and pdest.stars: - # lets blow the sucker! - supernova(game.probec) + supernova(game.probec) # fire in the hole! unschedule(FDSPROB) if game.state.galaxy[game.quadrant.i][game.quadrant.j].supernova: return @@ -3317,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: @@ -3811,7 +3800,7 @@ def dock(verbose): # because it involves giving x and y motions, yet the coordinates # are always displayed y - x, where +y is downward! -def getcourse(isprobe, akey): +def getcourse(isprobe): "Get a course and distance from the user." key = 0 dquad = copy.copy(game.quadrant) @@ -3834,12 +3823,7 @@ def getcourse(isprobe, akey): navmode = "manual" key = "IHEOL" break - if isprobe and akey != -1: - # For probe launch, use pre-scanned value first time - key = akey - akey = -1 - else: - key = scanner.next() + key = scanner.next() if key == "IHEOL": proutn(_("Manual or automatic- ")) iprompt = True @@ -3919,8 +3903,8 @@ def getcourse(isprobe, akey): 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- ")) @@ -3961,7 +3945,7 @@ def impulse(): prout(_("Engineer Scott- \"The impulse engines are damaged, Sir.\"")) return if game.energy > 30.0: - if not getcourse(isprobe=False, akey=0): + if not getcourse(isprobe=False): return power = 20.0 + 100.0*game.dist else: @@ -4016,7 +4000,7 @@ def warp(timewarp): prout(_(" is repaired, I can only give you warp 4.\"")) return # Read in course and distance - if not getcourse(isprobe=False, akey=0): + if not getcourse(isprobe=False): return # Make sure starship has enough energy for the trip power = (game.dist+0.05)*game.warpfac*game.warpfac*game.warpfac*(game.shldup+1) @@ -4195,8 +4179,7 @@ def atover(igrab): proutn(_("The %s has stopped in a quadrant containing") % crmshp()) prouts(_(" a supernova.")) skip(2) - prout(_("***Emergency automatic override attempts to hurl ")+crmshp()) - skip(1) + proutn(_("***Emergency automatic override attempts to hurl ")+crmshp()) prout(_("safely out of quadrant.")) if not damaged(DRADIO): game.state.galaxy[game.quadrant.i][game.quadrant.j].charted = True @@ -4309,7 +4292,6 @@ def probe(): return key = scanner.next() if key == "IHEOL": - # slow mode, so let Kirk know how many probes there are left if game.nprobes == 1: prout(_("1 probe left.")) else: @@ -4324,22 +4306,19 @@ def probe(): elif key == "IHEOL": proutn(_("Arm NOVAMAX warhead? ")) game.isarmed = ja() - if not getcourse(isprobe=True, akey=key): + elif key == "IHREAL": # first element of course + scanner.push(scanner.token) + if not getcourse(isprobe=True): return game.nprobes -= 1 angle = ((15.0 - game.direc) * 0.5235988) - game.probeinx = -math.sin(angle) - game.probeiny = math.cos(angle) - if math.fabs(game.probeinx) > math.fabs(game.probeiny): - bigger = math.fabs(game.probeinx) - else: - bigger = math.fabs(game.probeiny) - game.probeiny /= bigger - game.probeinx /= bigger + game.probein = coord(-math.sin(angle), math.cos(angle)) + bigger = max(abs(game.probein.i), abs(game.probein.j)) + game.probein /= bigger game.proben = 10.0*game.dist*bigger +0.5 - game.probex = game.quadrant.i*QUADSIZE + game.sector.i - 1 # We will use better packing than original - game.probey = game.quadrant.j*QUADSIZE + game.sector.j - 1 - game.probec = game.quadrant + game.probe = coord(game.quadrant.i*QUADSIZE + game.sector.i, + game.quadrant.j*QUADSIZE + game.sector.j) + game.probec = copy.copy(game.quadrant) schedule(FDSPROB, 0.01) # Time to move one sector prout(_("Ensign Chekov- \"The deep space probe is launched, Captain.\"")) game.ididit = True @@ -5311,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:")) @@ -5463,11 +5442,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" @@ -5728,8 +5707,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-")) @@ -6343,10 +6320,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) @@ -6550,7 +6523,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? ")) @@ -6565,4 +6539,3 @@ if __name__ == '__main__': if logfp: logfp.close() print "" - pass