+
+# Code from reports.c begins here
+
+def attackreport(curt):
+ "eport status of bases under attack."
+ if not curt:
+ if is_scheduled(FCDBAS):
+ prout(_("Starbase in Quadrant %s is currently under Commander attack.") % game.battle)
+ prout(_("It can hold out until Stardate %d.") % int(scheduled(FCDBAS)))
+ elif game.isatb == 1:
+ prout(_("Starbase in Quadrant %s is under Super-commander attack.") % game.state.kscmdr)
+ prout(_("It can hold out until Stardate %d.") % int(scheduled(FSCDBAS)))
+ else:
+ prout(_("No Starbase is currently under attack."))
+ else:
+ if is_scheduled(FCDBAS):
+ proutn(_("Base in %s attacked by C. Alive until %.1f") % (game.battle, scheduled(FCDBAS)))
+ if game.isatb:
+ proutn(_("Base in %s attacked by S. Alive until %.1f") % (game.state.kscmdr, scheduled(FSCDBAS)))
+ clreol()
+
+def report():
+ # report on general game status
+ scanner.chew()
+ s1 = "" and game.thawed and _("thawed ")
+ s2 = {1:"short", 2:"medium", 4:"long"}[game.length]
+ s3 = (None, _("novice"). _("fair"),
+ _("good"), _("expert"), _("emeritus"))[game.skill]
+ prout(_("You %s a %s%s %s game.") % ((_("were playing"), _("are playing"))[game.alldone], s1, s2, s3))
+ if game.skill>SKILL_GOOD and game.thawed and not game.alldone:
+ prout(_("No plaque is allowed."))
+ if game.tourn:
+ prout(_("This is tournament game %d.") % game.tourn)
+ prout(_("Your secret password is \"%s\"") % game.passwd)
+ proutn(_("%d of %d Klingons have been killed") % (((game.inkling + game.incom + game.inscom) - (game.state.remkl + len(game.state.kcmdr) + game.state.nscrem)),
+ (game.inkling + game.incom + game.inscom)))
+ if game.incom - len(game.state.kcmdr):
+ prout(_(", including %d Commander%s.") % (game.incom - len(game.state.kcmdr), (_("s"), "")[(game.incom - len(game.state.kcmdr))==1]))
+ elif game.inkling - game.state.remkl + (game.inscom - game.state.nscrem) > 0:
+ prout(_(", but no Commanders."))
+ else:
+ prout(".")
+ if game.skill > SKILL_FAIR:
+ prout(_("The Super Commander has %sbeen destroyed.") % ("", _("not "))[game.state.nscrem])
+ if len(game.state.baseq) != game.inbase:
+ proutn(_("There "))
+ if game.inbase-len(game.state.baseq)==1:
+ proutn(_("has been 1 base"))
+ else:
+ proutn(_("have been %d bases") % (game.inbase-len(game.state.baseq)))
+ prout(_(" destroyed, %d remaining.") % len(game.state.baseq))
+ else:
+ prout(_("There are %d bases.") % game.inbase)
+ if communicating() or game.iseenit:
+ # Don't report this if not seen and
+ # either the radio is dead or not at base!
+ attackreport(False)
+ game.iseenit = True
+ if game.casual:
+ prout(_("%d casualt%s suffered so far.") % (game.casual, ("y", "ies")[game.casual!=1]))
+ if game.nhelp:
+ prout(_("There were %d call%s for help.") % (game.nhelp, ("" , _("s"))[game.nhelp!=1]))
+ if game.ship == IHE:
+ proutn(_("You have "))
+ if game.nprobes:
+ proutn("%d" % (game.nprobes))
+ else:
+ proutn(_("no"))
+ proutn(_(" deep space probe"))
+ if game.nprobes!=1:
+ proutn(_("s"))
+ prout(".")
+ if communicating() and is_scheduled(FDSPROB):
+ if game.isarmed:
+ proutn(_("An armed deep space probe is in "))
+ else:
+ proutn(_("A deep space probe is in "))
+ prout("Quadrant %s." % game.probec)
+ if game.icrystl:
+ if game.cryprob <= .05:
+ prout(_("Dilithium crystals aboard ship... not yet used."))
+ else:
+ i=0
+ ai = 0.05
+ while game.cryprob > ai:
+ ai *= 2.0
+ i += 1
+ prout(_("Dilithium crystals have been used %d time%s.") % \
+ (i, (_("s"), "")[i==1]))
+ skip(1)
+
+def lrscan(silent):
+ "Long-range sensor scan."
+ if damaged(DLRSENS):
+ # Now allow base's sensors if docked
+ if game.condition != "docked":
+ if not silent:
+ prout(_("LONG-RANGE SENSORS DAMAGED."))
+ return
+ if not silent:
+ prout(_("Starbase's long-range scan"))
+ elif not silent:
+ prout(_("Long-range scan"))
+ for x in range(game.quadrant.i-1, game.quadrant.i+2):
+ if not silent:
+ proutn(" ")
+ for y in range(game.quadrant.j-1, game.quadrant.j+2):
+ if not coord(x, y).valid_quadrant():
+ if not silent:
+ proutn(" -1")
+ else:
+ if not damaged(DRADIO):
+ game.state.galaxy[x][y].charted = True
+ game.state.chart[x][y].klingons = game.state.galaxy[x][y].klingons
+ game.state.chart[x][y].starbase = game.state.galaxy[x][y].starbase
+ game.state.chart[x][y].stars = game.state.galaxy[x][y].stars
+ if not silent and game.state.galaxy[x][y].supernova:
+ 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(" ")
+
+def damagereport():
+ "Damage report."
+ jdam = False
+ scanner.chew()
+ for i in range(NDEVICES):
+ if damaged(i):
+ if not jdam:
+ prout(_("\tDEVICE\t\t\t-REPAIR TIMES-"))
+ prout(_("\t\t\tIN FLIGHT\t\tDOCKED"))
+ jdam = True
+ prout(" %-26s\t%8.2f\t\t%8.2f" % (device[i],
+ game.damage[i]+0.05,
+ game.docfac*game.damage[i]+0.005))
+ if not jdam:
+ prout(_("All devices functional."))
+
+def rechart():
+ "Update the chart in the Enterprise's computer from galaxy data."
+ game.lastchart = game.state.date
+ for i in range(GALSIZE):
+ for j in range(GALSIZE):
+ if game.state.galaxy[i][j].charted:
+ game.state.chart[i][j].klingons = game.state.galaxy[i][j].klingons
+ game.state.chart[i][j].starbase = game.state.galaxy[i][j].starbase
+ game.state.chart[i][j].stars = game.state.galaxy[i][j].stars
+
+def chart():
+ "Display the star chart."
+ scanner.chew()
+ if (game.options & OPTION_AUTOSCAN):
+ lrscan(silent=True)
+ if not damaged(DRADIO):
+ rechart()
+ if game.lastchart < game.state.date and game.condition == "docked":
+ prout(_("Spock- \"I revised the Star Chart from the starbase's records.\""))
+ rechart()
+ prout(_(" STAR CHART FOR THE KNOWN GALAXY"))
+ if game.state.date > game.lastchart:
+ prout(_("(Last surveillance update %d stardates ago).") % ((int)(game.state.date-game.lastchart)))
+ prout(" 1 2 3 4 5 6 7 8")
+ for i in range(GALSIZE):
+ proutn("%d |" % (i+1))
+ for j in range(GALSIZE):
+ if (game.options & OPTION_SHOWME) and i == game.quadrant.i and j == game.quadrant.j:
+ proutn("<")
+ else:
+ proutn(" ")
+ if game.state.galaxy[i][j].supernova:
+ show = "***"
+ elif not game.state.galaxy[i][j].charted and game.state.galaxy[i][j].starbase:
+ show = ".1."
+ elif game.state.galaxy[i][j].charted:
+ show = "%3d" % (game.state.chart[i][j].klingons*100 + game.state.chart[i][j].starbase * 10 + game.state.chart[i][j].stars)
+ else:
+ show = "..."
+ proutn(show)
+ if (game.options & OPTION_SHOWME) and i == game.quadrant.i and j == game.quadrant.j:
+ proutn(">")
+ else:
+ proutn(" ")
+ proutn(" |")
+ if i<GALSIZE:
+ skip(1)
+
+def sectscan(goodScan, i, j):
+ "Light up an individual dot in a sector."
+ if goodScan or (abs(i-game.sector.i)<= 1 and abs(j-game.sector.j) <= 1):
+ if (game.quad[i][j]==IHMATER0) or (game.quad[i][j]==IHMATER1) or (game.quad[i][j]==IHMATER2) or (game.quad[i][j]==IHE) or (game.quad[i][j]==IHF):
+ #if game.condition == "red": textcolor("red")
+ #elif game.condition == "green": textcolor("green")
+ #elif game.condition == "yellow": textcolor("yellow")
+ #elif game.condition == "docked": textcolor("cyan")
+ #elif game.condition == "dead": textcolor("brown")
+ if game.quad[i][j] != game.ship:
+ highvideo()
+ proutn("%c " % game.quad[i][j])
+ #textcolor(None)
+ else:
+ proutn("- ")
+
+def status(req=0):
+ "Emit status report lines"
+ if not req or req == 1:
+ prstat(_("Stardate"), _("%.1f, Time Left %.2f") \
+ % (game.state.date, game.state.remtime))
+ if not req or req == 2:
+ if game.condition != "docked":
+ newcnd()
+ prstat(_("Condition"), _("%s, %i DAMAGES") % \
+ (game.condition.upper(), sum(map(lambda x: x > 0, game.damage))))
+ if not req or req == 3:
+ prstat(_("Position"), "%s , %s" % (game.quadrant, game.sector))
+ if not req or req == 4:
+ if damaged(DLIFSUP):
+ if game.condition == "docked":
+ s = _("DAMAGED, Base provides")
+ else:
+ s = _("DAMAGED, reserves=%4.2f") % game.lsupres
+ else:
+ s = _("ACTIVE")
+ prstat(_("Life Support"), s)
+ 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))
+ if not req or req == 7:
+ prstat(_("Torpedoes"), "%d" % (game.torps))
+ if not req or req == 8:
+ if damaged(DSHIELD):
+ s = _("DAMAGED,")
+ elif game.shldup:
+ s = _("UP,")
+ else:
+ s = _("DOWN,")
+ data = _(" %d%% %.1f units") \
+ % (int((100.0*game.shield)/game.inshld + 0.5), game.shield)
+ prstat(_("Shields"), s+data)
+ if not req or req == 9:
+ prstat(_("Klingons Left"), "%d" \
+ % (game.state.remkl+len(game.state.kcmdr)+game.state.nscrem))
+ if not req or req == 10:
+ if game.options & OPTION_WORLDS:
+ plnet = game.state.galaxy[game.quadrant.i][game.quadrant.j].planet
+ if plnet and plnet.inhabited:
+ prstat(_("Major system"), plnet.name)
+ else:
+ prout(_("Sector is uninhabited"))
+ elif not req or req == 11:
+ attackreport(not req)
+
+def request():
+ "Request specified status data, a historical relic from slow TTYs."
+ requests = ("da","co","po","ls","wa","en","to","sh","kl","sy", "ti")
+ while scanner.next() == "IHEOL":
+ proutn(_("Information desired? "))
+ scanner.chew()
+ if scanner.token in requests:
+ status(requests.index(scanner.token))
+ else:
+ prout(_("UNRECOGNIZED REQUEST. Legal requests are:"))
+ prout((" date, condition, position, lsupport, warpfactor,"))
+ prout((" energy, torpedoes, shields, klingons, system, time."))
+
+def srscan():
+ "Short-range scan."
+ goodScan=True
+ if damaged(DSRSENS):
+ # Allow base's sensors if docked
+ if game.condition != "docked":
+ prout(_(" S.R. SENSORS DAMAGED!"))
+ goodScan=False
+ else:
+ prout(_(" [Using Base's sensors]"))
+ else:
+ prout(_(" Short-range scan"))
+ if goodScan and not damaged(DRADIO):
+ game.state.chart[game.quadrant.i][game.quadrant.j].klingons = game.state.galaxy[game.quadrant.i][game.quadrant.j].klingons
+ game.state.chart[game.quadrant.i][game.quadrant.j].starbase = game.state.galaxy[game.quadrant.i][game.quadrant.j].starbase
+ game.state.chart[game.quadrant.i][game.quadrant.j].stars = game.state.galaxy[game.quadrant.i][game.quadrant.j].stars
+ game.state.galaxy[game.quadrant.i][game.quadrant.j].charted = True
+ prout(" 1 2 3 4 5 6 7 8 9 10")
+ if game.condition != "docked":
+ newcnd()
+ for i in range(QUADSIZE):
+ proutn("%2d " % (i+1))
+ 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()
+ prompt = False
+ if damaged(DCOMPTR):
+ prout(_("COMPUTER DAMAGED, USE A POCKET CALCULATOR."))
+ skip(1)
+ return
+ if scanner.next() != "IHREAL":
+ prompt = True
+ scanner.chew()
+ proutn(_("Destination quadrant and/or sector? "))
+ if scanner.next()!="IHREAL":
+ huh()
+ return
+ w1.j = int(scanner.real-0.5)
+ if scanner.next() != "IHREAL":
+ huh()
+ return
+ w1.i = int(scanner.real-0.5)
+ if scanner.next() == "IHREAL":
+ w2.j = int(scanner.real-0.5)
+ if scanner.next() != "IHREAL":
+ huh()
+ return
+ w2.i = int(scanner.real-0.5)
+ else:
+ if game.quadrant.j>w1.i:
+ w2.i = 0
+ else:
+ w2.i=QUADSIZE-1
+ if game.quadrant.i>w1.j:
+ w2.j = 0
+ else:
+ w2.j=QUADSIZE-1
+ if not w1.valid_quadrant() or not w2.valid_sector():
+ huh()
+ return
+ 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:"))
+ while True:
+ scanner.chew()
+ proutn(_("Time or arrival date? "))
+ if scanner.next()=="IHREAL":
+ ttime = scanner.real
+ if ttime > game.state.date:
+ ttime -= game.state.date # Actually a star date
+ twarp=(math.floor(math.sqrt((10.0*dist)/ttime)*10.0)+1.0)/10.0
+ if ttime <= 1e-10 or twarp > 10:
+ prout(_("We'll never make it, sir."))
+ scanner.chew()
+ return
+ if twarp < 1.0:
+ twarp = 1.0
+ break
+ scanner.chew()
+ proutn(_("Warp factor? "))
+ if scanner.next()== "IHREAL":
+ wfl = True
+ twarp = scanner.real
+ if twarp<1.0 or twarp > 10.0:
+ huh()
+ return
+ break
+ prout(_("Captain, certainly you can give me one of these."))
+ while True:
+ scanner.chew()
+ ttime = (10.0*dist)/twarp**2
+ tpower = dist*twarp*twarp*twarp*(game.shldup+1)
+ if tpower >= game.energy:
+ prout(_("Insufficient energy, sir."))
+ if not game.shldup or tpower > game.energy*2.0:
+ if not wfl:
+ return
+ proutn(_("New warp factor to try? "))
+ if scanner.next() == "IHREAL":
+ wfl = True
+ twarp = scanner.real
+ if twarp<1.0 or twarp > 10.0:
+ huh()
+ return
+ continue
+ else:
+ scanner.chew()
+ skip(1)
+ return
+ prout(_("But if you lower your shields,"))
+ proutn(_("remaining"))
+ tpower /= 2
+ else:
+ proutn(_("Remaining"))
+ prout(_(" energy will be %.2f.") % (game.energy-tpower))
+ if wfl:
+ prout(_("And we will arrive at stardate %.2f.") % (game.state.date+ttime))
+ elif twarp==1.0:
+ prout(_("Any warp speed is adequate."))
+ else:
+ prout(_("Minimum warp needed is %.2f,") % (twarp))
+ prout(_("and we will arrive at stardate %.2f.") % (game.state.date+ttime))
+ if game.state.remtime < ttime:
+ prout(_("Unfortunately, the Federation will be destroyed by then."))
+ if twarp > 6.0:
+ prout(_("You'll be taking risks at that speed, Captain"))
+ if (game.isatb==1 and game.state.kscmdr == w1 and \
+ scheduled(FSCDBAS)< ttime+game.state.date) or \
+ (scheduled(FCDBAS)<ttime+game.state.date and game.battle == w1):
+ prout(_("The starbase there will be destroyed by then."))
+ proutn(_("New warp factor to try? "))
+ if scanner.next() == "IHREAL":
+ wfl = True
+ twarp = scanner.real
+ if twarp<1.0 or twarp > 10.0:
+ huh()
+ return
+ else:
+ scanner.chew()
+ skip(1)
+ return
+
+# Code from setup.c begins here
+
+def prelim():
+ "Issue a historically correct banner."
+ skip(2)
+ prout(_("-SUPER- STAR TREK"))
+ skip(1)
+# From the FORTRAN original
+# prout(_("Latest update-21 Sept 78"))
+# skip(1)
+
+def freeze(boss):
+ "Save game."
+ if boss:
+ scanner.push("emsave.trk")
+ 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"
+ try:
+ fp = open(scanner.token, "wb")
+ except IOError:
+ prout(_("Can't freeze game as file %s") % scanner.token)
+ return
+ cPickle.dump(game, fp)
+ fp.close()
+
+def thaw():
+ "Retrieve saved game."
+ game.passwd[0] = '\0'
+ key = scanner.next()
+ if key == "IHEOL":
+ proutn(_("File name: "))
+ key = scanner.next()
+ if key != "IHALPHA":
+ huh()
+ return True
+ scanner.chew()
+ if '.' not in scanner.token:
+ scanner.token += ".trk"
+ try:
+ fp = open(scanner.token, "rb")
+ except IOError:
+ prout(_("Can't thaw game in %s") % scanner.token)
+ return
+ game = cPickle.load(fp)
+ fp.close()
+ return False
+
+# I used <http://www.memory-alpha.org> to find planets
+# with references in ST:TOS. Eath and the Alpha Centauri
+# Colony have been omitted.
+#
+# Some planets marked Class G and P here will be displayed as class M
+# because of the way planets are generated. This is a known bug.
+systnames = (
+ # Federation Worlds
+ _("Andoria (Fesoan)"), # several episodes
+ _("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)
+ _("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"
+ _("Alpha Majoris I"), # TOS: "Wolf in the Fold"
+ _("Altair IV"), # TOS: "Amok Time
+ _("Ariannus"), # TOS: "Let That Be Your Last Battlefield"
+ _("Benecia"), # TOS: "The Conscience of the King"
+ _("Beta Niobe I (Sarpeidon)"), # TOS: "All Our Yesterdays"
+ _("Alpha Carinae II"), # TOS: "The Ultimate Computer"
+ _("Capella IV (Kohath)"), # TOS: "Friday's Child" (Class G)
+ _("Daran V"), # TOS: "For the World is Hollow and I Have Touched the Sky"
+ _("Deneb II"), # TOS: "Wolf in the Fold" ("IV" in BSD)
+ _("Eminiar VII"), # TOS: "A Taste of Armageddon"
+ _("Gamma Canaris IV"), # TOS: "Metamorphosis"
+ _("Gamma Tranguli VI (Vaalel)"), # TOS: "The Apple"
+ _("Ingraham B"), # TOS: "Operation: Annihilate"
+ _("Janus IV"), # TOS: "The Devil in the Dark"
+ _("Makus III"), # TOS: "The Galileo Seven"
+ _("Marcos XII"), # TOS: "And the Children Shall Lead",
+ _("Omega IV"), # TOS: "The Omega Glory"
+ _("Regulus V"), # TOS: "Amok Time
+ _("Deneva"), # TOS: "Operation -- Annihilate!"
+ # Worlds from BSD Trek
+ _("Rigel II"), # TOS: "Shore Leave" ("III" in BSD)
+ _("Beta III"), # TOS: "The Return of the Archons"
+ _("Triacus"), # TOS: "And the Children Shall Lead",
+ _("Exo III"), # TOS: "What Are Little Girls Made Of?" (Class P)
+# # Others
+# _("Hansen's Planet"), # TOS: "The Galileo Seven"
+# _("Taurus IV"), # TOS: "The Galileo Seven" (class G)
+# _("Antos IV (Doraphane)"), # TOS: "Whom Gods Destroy", "Who Mourns for Adonais?"
+# _("Izar"), # TOS: "Whom Gods Destroy"
+# _("Tiburon"), # TOS: "The Way to Eden"
+# _("Merak II"), # TOS: "The Cloud Minders"
+# _("Coridan (Desotriana)"), # TOS: "Journey to Babel"
+# _("Iotia"), # TOS: "A Piece of the Action"
+)
+
+device = (
+ _("S. R. Sensors"), \
+ _("L. R. Sensors"), \
+ _("Phasers"), \
+ _("Photon Tubes"), \
+ _("Life Support"), \
+ _("Warp Engines"), \
+ _("Impulse Engines"), \
+ _("Shields"), \
+ _("Subspace Radio"), \
+ _("Shuttle Craft"), \
+ _("Computer"), \
+ _("Navigation System"), \
+ _("Transporter"), \
+ _("Shield Control"), \
+ _("Death Ray"), \
+ _("D. S. Probe"), \
+)
+
+def setup():
+ "Prepare to play, set up cosmos."
+ w = coord()
+ # Decide how many of everything
+ if choose():
+ return # frozen game
+ # Prepare the Enterprise
+ game.alldone = game.gamewon = game.shldchg = game.shldup = False
+ game.ship = IHE
+ game.state.crew = FULLCREW
+ game.energy = game.inenrg = 5000.0
+ game.shield = game.inshld = 2500.0
+ game.inlsr = 4.0
+ game.lsupres = 4.0
+ game.quadrant = randplace(GALSIZE)
+ game.sector = randplace(QUADSIZE)
+ game.torps = game.intorps = 10
+ game.nprobes = randrange(2, 5)
+ game.warpfac = 5.0
+ for i in range(NDEVICES):
+ game.damage[i] = 0.0
+ # Set up assorted game parameters
+ game.battle = coord()
+ game.state.date = game.indate = 100.0 * randreal(20, 51)
+ game.nkinks = game.nhelp = game.casual = game.abandoned = 0
+ game.iscate = game.resting = game.imine = game.icrystl = game.icraft = False
+ game.isatb = game.state.nplankl = 0
+ game.state.starkl = game.state.basekl = 0
+ game.iscraft = "onship"
+ game.landed = False
+ game.alive = True
+ game.docfac = 0.25
+ # Starchart is functional but we've never seen it
+ game.lastchart = FOREVER
+ # Put stars in the galaxy
+ game.instar = 0
+ for i in range(GALSIZE):
+ for j in range(GALSIZE):
+ k = randrange(1, QUADSIZE**2/10+1)
+ game.instar += k
+ game.state.galaxy[i][j].stars = k
+ # Locate star bases in galaxy
+ for i in range(game.inbase):
+ while True:
+ while True:
+ w = randplace(GALSIZE)
+ if not game.state.galaxy[w.i][w.j].starbase:
+ break
+ contflag = False
+ # C version: for (j = i-1; j > 0; j--)
+ # so it did them in the opposite order.
+ for j in range(1, i):
+ # Improved placement algorithm to spread out bases
+ distq = (w - game.state.baseq[j]).distance()
+ if distq < 6.0*(BASEMAX+1-game.inbase) and withprob(0.75):
+ contflag = True
+ if idebug:
+ prout("=== Abandoning base #%d at %s" % (i, w))
+ break
+ elif distq < 6.0 * (BASEMAX+1-game.inbase):
+ if idebug:
+ prout("=== Saving base #%d, close to #%d" % (i, j))
+ if not contflag:
+ break
+ game.state.baseq.append(w)
+ game.state.galaxy[w.i][w.j].starbase = game.state.chart[w.i][w.j].starbase = True
+ # Position ordinary Klingon Battle Cruisers
+ krem = game.inkling
+ klumper = 0.25*game.skill*(9.0-game.length)+1.0
+ if klumper > MAXKLQUAD:
+ klumper = MAXKLQUAD
+ while True:
+ r = randreal()
+ klump = (1.0 - r*r)*klumper
+ if klump > krem:
+ klump = krem
+ krem -= klump
+ while True:
+ w = randplace(GALSIZE)
+ if not game.state.galaxy[w.i][w.j].supernova and \
+ game.state.galaxy[w.i][w.j].klingons + klump <= MAXKLQUAD:
+ break
+ game.state.galaxy[w.i][w.j].klingons += int(klump)
+ if krem <= 0:
+ break
+ # Position Klingon Commander Ships
+ for i in range(game.incom):
+ while True:
+ w = randplace(GALSIZE)
+ if not welcoming(w) or w in game.state.kcmdr:
+ continue
+ if (game.state.galaxy[w.i][w.j].klingons or withprob(0.25)):
+ break
+ game.state.galaxy[w.i][w.j].klingons += 1
+ game.state.kcmdr.append(w)
+ # Locate planets in galaxy
+ for i in range(game.inplan):
+ while True:
+ w = randplace(GALSIZE)
+ if game.state.galaxy[w.i][w.j].planet == None:
+ break
+ new = planet()
+ new.quadrant = w
+ new.crystals = "absent"
+ if (game.options & OPTION_WORLDS) and i < NINHAB:
+ new.pclass = "M" # All inhabited planets are class M
+ new.crystals = "absent"
+ new.known = "known"
+ new.name = systnames[i]
+ new.inhabited = True
+ else:
+ new.pclass = ("M", "N", "O")[randrange(0, 3)]
+ if withprob(0.33):
+ new.crystals = "present"
+ new.known = "unknown"
+ new.inhabited = False
+ game.state.galaxy[w.i][w.j].planet = new
+ game.state.planets.append(new)
+ # Locate Romulans
+ for i in range(game.state.nromrem):
+ w = randplace(GALSIZE)
+ game.state.galaxy[w.i][w.j].romulans += 1
+ # Place the Super-Commander if needed
+ if game.state.nscrem > 0:
+ while True:
+ w = randplace(GALSIZE)
+ if welcoming(w):
+ break
+ game.state.kscmdr = w
+ game.state.galaxy[w.i][w.j].klingons += 1
+ # Initialize times for extraneous events
+ schedule(FSNOVA, expran(0.5 * game.intime))
+ schedule(FTBEAM, expran(1.5 * (game.intime / len(game.state.kcmdr))))
+ schedule(FSNAP, randreal(1.0, 2.0)) # Force an early snapshot
+ schedule(FBATTAK, expran(0.3*game.intime))
+ unschedule(FCDBAS)
+ if game.state.nscrem:
+ schedule(FSCMOVE, 0.2777)
+ else:
+ unschedule(FSCMOVE)
+ unschedule(FSCDBAS)
+ unschedule(FDSPROB)
+ if (game.options & OPTION_WORLDS) and game.skill >= SKILL_GOOD:
+ schedule(FDISTR, expran(1.0 + game.intime))
+ else:
+ unschedule(FDISTR)
+ unschedule(FENSLV)
+ unschedule(FREPRO)
+ # Place thing (in tournament game, we don't want one!)
+ # New in SST2K: never place the Thing near a starbase.
+ # This makes sense and avoids a special case in the old code.
+ global thing
+ if game.tourn is None:
+ while True:
+ thing = randplace(GALSIZE)
+ if thing not in game.state.baseq:
+ break
+ skip(2)
+ game.state.snap = False
+ if game.skill == SKILL_NOVICE:
+ prout(_("It is stardate %d. The Federation is being attacked by") % int(game.state.date))
+ prout(_("a deadly Klingon invasion force. As captain of the United"))
+ prout(_("Starship U.S.S. Enterprise, it is your mission to seek out"))
+ prout(_("and destroy this invasion force of %d battle cruisers.") % ((game.inkling + game.incom + game.inscom)))
+ prout(_("You have an initial allotment of %d stardates to complete") % int(game.intime))
+ prout(_("your mission. As you proceed you may be given more time."))
+ skip(1)
+ prout(_("You will have %d supporting starbases.") % (game.inbase))
+ proutn(_("Starbase locations- "))
+ else:
+ prout(_("Stardate %d.") % int(game.state.date))
+ skip(1)
+ prout(_("%d Klingons.") % (game.inkling + game.incom + game.inscom))
+ prout(_("An unknown number of Romulans."))
+ if game.state.nscrem:
+ prout(_("And one (GULP) Super-Commander."))
+ prout(_("%d stardates.") % int(game.intime))
+ proutn(_("%d starbases in ") % game.inbase)
+ for i in range(game.inbase):
+ proutn(`game.state.baseq[i]`)
+ proutn(" ")
+ skip(2)
+ proutn(_("The Enterprise is currently in Quadrant %s") % game.quadrant)
+ proutn(_(" Sector %s") % game.sector)
+ skip(2)
+ prout(_("Good Luck!"))
+ if game.state.nscrem:
+ prout(_(" YOU'LL NEED IT."))
+ waitfor()
+ newqad()
+ if len(game.enemies) - (thing == game.quadrant) - (game.tholian != None):
+ game.shldup = True
+ if game.neutz: # bad luck to start in a Romulan Neutral Zone
+ attack(torps_ok=False)
+
+def choose():
+ "Choose your game type."
+ global thing
+ while True:
+ game.tourn = 0
+ game.thawed = False
+ game.skill = SKILL_NONE
+ game.length = 0
+ if not scanner.inqueue: # Can start with command line options
+ proutn(_("Would you like a regular, tournament, or saved game? "))
+ scanner.next()
+ if scanner.sees("tournament"):
+ while scanner.next() == "IHEOL":
+ proutn(_("Type in tournament number-"))
+ if scanner.real == 0:
+ scanner.chew()
+ continue # We don't want a blank entry
+ game.tourn = int(round(scanner.real))
+ random.seed(scanner.real)
+ if logfp:
+ logfp.write("# random.seed(%d)\n" % scanner.real)
+ break
+ if scanner.sees("saved") or scanner.sees("frozen"):
+ if thaw():
+ continue
+ scanner.chew()
+ if game.passwd == None:
+ continue
+ if not game.alldone:
+ game.thawed = True # No plaque if not finished
+ report()
+ waitfor()
+ return True
+ if scanner.sees("regular"):
+ break
+ proutn(_("What is \"%s\"?") % scanner.token)
+ scanner.chew()
+ while game.length==0 or game.skill==SKILL_NONE:
+ if scanner.next() == "IHALPHA":
+ if scanner.sees("short"):
+ game.length = 1
+ elif scanner.sees("medium"):
+ game.length = 2
+ elif scanner.sees("long"):
+ game.length = 4
+ elif scanner.sees("novice"):
+ game.skill = SKILL_NOVICE
+ elif scanner.sees("fair"):
+ game.skill = SKILL_FAIR
+ elif scanner.sees("good"):
+ game.skill = SKILL_GOOD
+ elif scanner.sees("expert"):
+ game.skill = SKILL_EXPERT
+ elif scanner.sees("emeritus"):
+ game.skill = SKILL_EMERITUS
+ else:
+ proutn(_("What is \""))
+ proutn(scanner.token)
+ prout("\"?")
+ else:
+ scanner.chew()
+ if game.length==0:
+ proutn(_("Would you like a Short, Medium, or Long game? "))
+ elif game.skill == SKILL_NONE:
+ proutn(_("Are you a Novice, Fair, Good, Expert, or Emeritus player? "))
+ # Choose game options -- added by ESR for SST2K
+ if scanner.next() != "IHALPHA":
+ scanner.chew()
+ proutn(_("Choose your game style (or just press enter): "))
+ scanner.next()
+ if scanner.sees("plain"):
+ # Approximates the UT FORTRAN version.
+ game.options &=~ (OPTION_THOLIAN | OPTION_PLANETS | OPTION_THINGY | OPTION_PROBE | OPTION_RAMMING | OPTION_MVBADDY | OPTION_BLKHOLE | OPTION_BASE | OPTION_WORLDS)
+ game.options |= OPTION_PLAIN
+ elif scanner.sees("almy"):
+ # Approximates Tom Almy's version.
+ game.options &=~ (OPTION_THINGY | OPTION_BLKHOLE | OPTION_BASE | OPTION_WORLDS)
+ game.options |= OPTION_ALMY
+ elif scanner.sees("fancy") or scanner.sees("\n"):
+ pass
+ elif len(scanner.token):
+ proutn(_("What is \"%s\"?") % scanner.token)
+ setpassword()
+ if game.passwd == "debug":
+ idebug = True
+ prout("=== Debug mode enabled.")
+ # Use parameters to generate initial values of things
+ game.damfac = 0.5 * game.skill
+ game.inbase = randrange(BASEMIN, BASEMAX+1)
+ game.inplan = 0
+ if game.options & OPTION_PLANETS:
+ game.inplan += randrange(MAXUNINHAB/2, MAXUNINHAB+1)
+ if game.options & OPTION_WORLDS:
+ game.inplan += int(NINHAB)
+ game.state.nromrem = game.inrom = randrange(2 *game.skill)
+ game.state.nscrem = game.inscom = (game.skill > SKILL_FAIR)
+ game.state.remtime = 7.0 * game.length
+ game.intime = game.state.remtime
+ game.state.remkl = game.inkling = 2.0*game.intime*((game.skill+1 - 2*randreal())*game.skill*0.1+.15)
+ game.incom = min(MINCMDR, int(game.skill + 0.0625*game.inkling*randreal()))
+ game.state.remres = (game.inkling+4*game.incom)*game.intime
+ game.inresor = game.state.remres
+ if game.inkling > 50:
+ game.state.inbase += 1
+ return False
+
+def dropin(iquad=None):
+ "Drop a feature on a random dot in the current quadrant."
+ while True:
+ w = randplace(QUADSIZE)
+ if game.quad[w.i][w.j] == IHDOT:
+ break
+ if iquad is not None:
+ game.quad[w.i][w.j] = iquad
+ return w
+
+def newcnd():
+ "Update our alert status."
+ game.condition = "green"
+ if game.energy < 1000.0:
+ game.condition = "yellow"
+ if game.state.galaxy[game.quadrant.i][game.quadrant.j].klingons or game.state.galaxy[game.quadrant.i][game.quadrant.j].romulans:
+ game.condition = "red"
+ if not game.alive:
+ game.condition="dead"
+
+def newkling():
+ "Drop new Klingon into current quadrant."
+ return enemy(IHK, loc=dropin(), power=randreal(300,450)+25.0*game.skill)
+
+def newqad():
+ "Set up a new state of quadrant, for when we enter or re-enter it."
+ game.justin = True
+ game.iplnet = None
+ game.neutz = game.inorbit = game.landed = False
+ game.ientesc = game.iseenit = False
+ # Create a blank quadrant
+ game.quad = fill2d(QUADSIZE, lambda i, j: IHDOT)
+ if game.iscate:
+ # Attempt to escape Super-commander, so tbeam back!
+ game.iscate = False
+ game.ientesc = True
+ q = game.state.galaxy[game.quadrant.i][game.quadrant.j]
+ # cope with supernova
+ if q.supernova:
+ return
+ game.klhere = q.klingons
+ game.irhere = q.romulans
+ # Position Starship
+ game.quad[game.sector.i][game.sector.j] = game.ship
+ game.enemies = []
+ if q.klingons:
+ # Position ordinary Klingons
+ for i in range(game.klhere):
+ newkling()
+ # If we need a commander, promote a Klingon
+ for cmdr in game.state.kcmdr:
+ if cmdr == game.quadrant:
+ e = game.enemies[game.klhere-1]
+ game.quad[e.kloc.i][e.kloc.j] = IHC
+ e.kpower = randreal(950,1350) + 50.0*game.skill
+ break
+ # If we need a super-commander, promote a Klingon
+ if game.quadrant == game.state.kscmdr:
+ e = game.enemies[0]
+ game.quad[e.kloc.i][e.kloc.j] = IHS
+ e.kpower = randreal(1175.0, 1575.0) + 125.0*game.skill
+ game.iscate = (game.state.remkl > 1)
+ # Put in Romulans if needed
+ for i in range(q.romulans):
+ enemy(IHR, loc=dropin(), power=randreal(400.0,850.0)+50.0*game.skill)
+ # If quadrant needs a starbase, put it in
+ if q.starbase:
+ game.base = dropin(IHB)
+ # If quadrant needs a planet, put it in
+ if q.planet:
+ game.iplnet = q.planet
+ if not q.planet.inhabited:
+ game.plnet = dropin(IHP)
+ else:
+ game.plnet = dropin(IHW)
+ # Check for condition
+ newcnd()
+ # Check for RNZ
+ if game.irhere > 0 and game.klhere == 0:
+ game.neutz = True
+ if not damaged(DRADIO):
+ skip(1)
+ prout(_("LT. Uhura- \"Captain, an urgent message."))
+ prout(_(" I'll put it on audio.\" CLICK"))
+ skip(1)
+ prout(_("INTRUDER! YOU HAVE VIOLATED THE ROMULAN NEUTRAL ZONE."))
+ prout(_("LEAVE AT ONCE, OR YOU WILL BE DESTROYED!"))
+ # Put in THING if needed
+ if thing == game.quadrant:
+ enemy(type=IHQUEST, loc=dropin(),
+ power=randreal(6000,6500.0)+250.0*game.skill)
+ if not damaged(DSRSENS):
+ skip(1)
+ prout(_("Mr. Spock- \"Captain, this is most unusual."))
+ prout(_(" Please examine your short-range scan.\""))
+ # Decide if quadrant needs a Tholian; lighten up if skill is low
+ if game.options & OPTION_THOLIAN:
+ if (game.skill < SKILL_GOOD and withprob(0.02)) or \
+ (game.skill == SKILL_GOOD and withprob(0.05)) or \
+ (game.skill > SKILL_GOOD and withprob(0.08)):
+ w = coord()
+ while True:
+ w.i = withprob(0.5) * (QUADSIZE-1)
+ w.j = withprob(0.5) * (QUADSIZE-1)
+ if game.quad[w.i][w.j] == IHDOT:
+ break
+ game.tholian = enemy(type=IHT, loc=w,
+ power=randrange(100, 500) + 25.0*game.skill)
+ # Reserve unoccupied corners
+ if game.quad[0][0]==IHDOT:
+ game.quad[0][0] = 'X'
+ if game.quad[0][QUADSIZE-1]==IHDOT:
+ game.quad[0][QUADSIZE-1] = 'X'
+ if game.quad[QUADSIZE-1][0]==IHDOT:
+ game.quad[QUADSIZE-1][0] = 'X'
+ if game.quad[QUADSIZE-1][QUADSIZE-1]==IHDOT:
+ game.quad[QUADSIZE-1][QUADSIZE-1] = 'X'
+ game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist))
+ # And finally the stars
+ for i in range(q.stars):
+ dropin(IHSTAR)
+ # Put in a few black holes
+ for i in range(1, 3+1):
+ if withprob(0.5):
+ dropin(IHBLANK)
+ # Take out X's in corners if Tholian present
+ if game.tholian:
+ if game.quad[0][0]=='X':
+ game.quad[0][0] = IHDOT
+ if game.quad[0][QUADSIZE-1]=='X':
+ game.quad[0][QUADSIZE-1] = IHDOT
+ if game.quad[QUADSIZE-1][0]=='X':
+ game.quad[QUADSIZE-1][0] = IHDOT
+ if game.quad[QUADSIZE-1][QUADSIZE-1]=='X':
+ game.quad[QUADSIZE-1][QUADSIZE-1] = IHDOT
+
+def setpassword():
+ "Set the self-destruct password."
+ if game.options & OPTION_PLAIN:
+ while True:
+ scanner.chew()
+ proutn(_("Please type in a secret password- "))
+ scanner.next()
+ game.passwd = scanner.token
+ if game.passwd != None:
+ break
+ else:
+ game.passwd = ""
+ for i in range(8):
+ game.passwd += chr(ord('a')+randrange(26))
+
+# Code from sst.c begins here
+
+commands = {
+ "SRSCAN": OPTION_TTY,
+ "STATUS": OPTION_TTY,
+ "REQUEST": OPTION_TTY,
+ "LRSCAN": OPTION_TTY,
+ "PHASERS": 0,
+ "TORPEDO": 0,
+ "PHOTONS": 0,
+ "MOVE": 0,
+ "SHIELDS": 0,
+ "DOCK": 0,
+ "DAMAGES": 0,
+ "CHART": 0,
+ "IMPULSE": 0,
+ "REST": 0,
+ "WARP": 0,
+ "SCORE": 0,
+ "SENSORS": OPTION_PLANETS,
+ "ORBIT": OPTION_PLANETS,
+ "TRANSPORT": OPTION_PLANETS,
+ "MINE": OPTION_PLANETS,
+ "CRYSTALS": OPTION_PLANETS,
+ "SHUTTLE": OPTION_PLANETS,
+ "PLANETS": OPTION_PLANETS,
+ "REPORT": 0,
+ "COMPUTER": 0,
+ "COMMANDS": 0,
+ "EMEXIT": 0,
+ "PROBE": OPTION_PROBE,
+ "SAVE": 0,
+ "FREEZE": 0, # Synonym for SAVE
+ "ABANDON": 0,
+ "DESTRUCT": 0,
+ "DEATHRAY": 0,
+ "DEBUG": 0,
+ "MAYDAY": 0,
+ "SOS": 0, # Synonym for MAYDAY
+ "CALL": 0, # Synonym for MAYDAY
+ "QUIT": 0,
+ "HELP": 0,
+}
+
+def listCommands():
+ "Generate a list of legal commands."
+ prout(_("LEGAL COMMANDS ARE:"))
+ emitted = 0
+ for key in commands:
+ if not commands[key] or (commands[key] & game.options):
+ proutn("%-12s " % key)
+ emitted += 1
+ if emitted % 5 == 4:
+ skip(1)
+ skip(1)
+
+def helpme():
+ "Browse on-line help."
+ key = scanner.next()
+ while True:
+ if key == "IHEOL":
+ setwnd(prompt_window)
+ proutn(_("Help on what command? "))
+ key = scanner.next()
+ setwnd(message_window)
+ if key == "IHEOL":
+ return
+ if scanner.token in commands or scanner.token == "ABBREV":
+ break
+ skip(1)
+ listCommands()
+ key = "IHEOL"
+ scanner.chew()
+ skip(1)
+ cmd = scanner.token.upper()
+ try:
+ fp = open(SSTDOC, "r")
+ except IOError:
+ try:
+ fp = open(DOC_NAME, "r")
+ 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
+ while True:
+ linebuf = fp.readline()
+ if linebuf == '':
+ prout(_("Spock- \"Captain, there is no information on that command.\""))
+ fp.close()
+ return
+ if linebuf[0] == '%' and linebuf[1] == '%' and linebuf[2] == ' ':
+ linebuf = linebuf[3:].strip()
+ if cmd == linebuf:
+ break
+ skip(1)
+ prout(_("Spock- \"Captain, I've found the following information:\""))
+ skip(1)
+ while linebuf in fp:
+ if "******" in linebuf:
+ break
+ proutn(linebuf)
+ fp.close()
+
+def makemoves():
+ "Command-interpretation loop."
+ clrscr()
+ setwnd(message_window)
+ while True: # command loop
+ drawmaps(1)
+ while True: # get a command
+ hitme = False
+ game.justin = False
+ game.optime = 0.0
+ scanner.chew()
+ setwnd(prompt_window)
+ clrscr()
+ proutn("COMMAND> ")
+ if scanner.next() == "IHEOL":
+ if game.options & OPTION_CURSES:
+ makechart()
+ continue
+ elif scanner.token == "":
+ continue
+ game.ididit = False
+ clrscr()
+ setwnd(message_window)
+ clrscr()
+ candidates = filter(lambda x: x.startswith(scanner.token.upper()),
+ commands)
+ if len(candidates) == 1:
+ cmd = candidates[0]
+ break
+ elif candidates and not (game.options & OPTION_PLAIN):
+ prout("Commands with prefix '%s': %s" % (scanner.token, " ".join(candidates)))
+ else:
+ listCommands()
+ continue
+ if cmd == "SRSCAN": # srscan
+ srscan()
+ elif cmd == "STATUS": # status
+ status()
+ elif cmd == "REQUEST": # status request
+ request()
+ elif cmd == "LRSCAN": # long range scan
+ lrscan(silent=False)
+ elif cmd == "PHASERS": # phasers
+ phasers()
+ if game.ididit:
+ hitme = True
+ elif cmd == "TORPEDO": # photon torpedos
+ photon()
+ if game.ididit:
+ hitme = True
+ elif cmd == "MOVE": # move under warp
+ warp(course=None, involuntary=False)
+ elif cmd == "SHIELDS": # shields
+ doshield(shraise=False)
+ if game.ididit:
+ hitme = True
+ game.shldchg = False
+ elif cmd == "DOCK": # dock at starbase
+ dock(True)
+ if game.ididit:
+ attack(torps_ok=False)
+ elif cmd == "DAMAGES": # damage reports
+ damagereport()
+ elif cmd == "CHART": # chart
+ makechart()
+ elif cmd == "IMPULSE": # impulse
+ impulse()
+ elif cmd == "REST": # rest
+ wait()
+ if game.ididit:
+ hitme = True
+ elif cmd == "WARP": # warp
+ setwarp()
+ elif cmd == "SCORE": # score
+ score()
+ elif cmd == "SENSORS": # sensors
+ sensor()
+ elif cmd == "ORBIT": # orbit
+ orbit()
+ if game.ididit:
+ hitme = True
+ elif cmd == "TRANSPORT": # transport "beam"
+ beam()
+ elif cmd == "MINE": # mine
+ mine()
+ if game.ididit:
+ hitme = True
+ elif cmd == "CRYSTALS": # crystals
+ usecrystals()
+ if game.ididit:
+ hitme = True
+ elif cmd == "SHUTTLE": # shuttle
+ shuttle()
+ if game.ididit:
+ hitme = True
+ elif cmd == "PLANETS": # Planet list
+ survey()
+ elif cmd == "REPORT": # Game Report
+ report()
+ elif cmd == "COMPUTER": # use COMPUTER!
+ eta()
+ elif cmd == "COMMANDS":
+ listCommands()
+ elif cmd == "EMEXIT": # Emergency exit
+ clrscr() # Hide screen
+ freeze(True) # forced save
+ raise SysExit,1 # And quick exit
+ elif cmd == "PROBE":
+ probe() # Launch probe
+ if game.ididit:
+ hitme = True
+ elif cmd == "ABANDON": # Abandon Ship
+ abandon()
+ elif cmd == "DESTRUCT": # Self Destruct
+ selfdestruct()
+ elif cmd == "SAVE": # Save Game
+ freeze(False)
+ clrscr()
+ if game.skill > SKILL_GOOD:
+ prout(_("WARNING--Saved games produce no plaques!"))
+ elif cmd == "DEATHRAY": # Try a desparation measure
+ deathray()
+ if game.ididit:
+ hitme = True
+ elif cmd == "DEBUGCMD": # What do we want for debug???
+ debugme()
+ elif cmd == "MAYDAY": # Call for help
+ mayday()
+ if game.ididit:
+ hitme = True
+ elif cmd == "QUIT":
+ game.alldone = True # quit the game
+ elif cmd == "HELP":
+ helpme() # get help
+ while True:
+ if game.alldone:
+ break # Game has ended
+ if game.optime != 0.0:
+ events()
+ if game.alldone:
+ break # Events did us in
+ if game.state.galaxy[game.quadrant.i][game.quadrant.j].supernova:
+ atover(False)
+ continue
+ if hitme and not game.justin:
+ attack(torps_ok=True)
+ if game.alldone:
+ break
+ if game.state.galaxy[game.quadrant.i][game.quadrant.j].supernova:
+ atover(False)
+ hitme = True
+ continue
+ break
+ if game.alldone:
+ break
+ if idebug:
+ prout("=== Ending")
+
+def cramen(type):
+ "Emit the name of an enemy or feature."
+ if type == IHR: s = _("Romulan")
+ elif type == IHK: s = _("Klingon")
+ elif type == IHC: s = _("Commander")
+ elif type == IHS: s = _("Super-commander")
+ elif type == IHSTAR: s = _("Star")
+ elif type == IHP: s = _("Planet")
+ elif type == IHB: s = _("Starbase")
+ elif type == IHBLANK: s = _("Black hole")
+ elif type == IHT: s = _("Tholian")
+ elif type == IHWEB: s = _("Tholian web")
+ elif type == IHQUEST: s = _("Stranger")
+ elif type == IHW: s = _("Inhabited World")
+ else: s = "Unknown??"
+ return s
+
+def crmena(stars, enemy, loctype, w):
+ "Emit the name of an enemy and his location."
+ buf = ""
+ if stars:
+ buf += "***"
+ buf += cramen(enemy) + _(" at ")
+ if loctype == "quadrant":
+ buf += _("Quadrant ")
+ elif loctype == "sector":
+ buf += _("Sector ")
+ return buf + `w`
+
+def crmshp():
+ "Emit our ship name."
+ return{IHE:_("Enterprise"),IHF:_("Faerie Queene")}.get(game.ship,"Ship???")
+
+def stars():
+ "Emit a line of stars"
+ prouts("******************************************************")
+ skip(1)
+
+def expran(avrage):
+ return -avrage*math.log(1e-7 + randreal())
+
+def randplace(size):
+ "Choose a random location."
+ w = coord()
+ w.i = randrange(size)
+ w.j = randrange(size)
+ return w
+
+class sstscanner:
+ def __init__(self):
+ self.type = None
+ self.token = None
+ self.real = 0.0
+ self.inqueue = []
+ def next(self):
+ # Get a token from the user
+ self.real = 0.0
+ self.token = ''
+ # Fill the token quue if nothing here
+ while not self.inqueue:
+ line = cgetline()
+ if curwnd==prompt_window:
+ clrscr()
+ setwnd(message_window)
+ clrscr()
+ if line == '':
+ return None
+ if not line:
+ continue
+ else:
+ 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 == "\n":
+ self.type = "IHEOL"
+ return "IHEOL"
+ try:
+ self.real = float(self.token)
+ self.type = "IHREAL"
+ return "IHREAL"
+ except ValueError:
+ pass
+ # Treat as alpha
+ self.token = self.token.lower()
+ self.type = "IHALPHA"
+ self.real = None
+ return "IHALPHA"
+ def append(self, tok):
+ self.inqueue.append(tok)
+ def push(self, tok):
+ self.inqueue.insert(0, tok)
+ def waiting(self):
+ return self.inqueue
+ def chew(self):
+ # Demand input for next scan
+ self.inqueue = []
+ 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)
+ def int(self):
+ # Round token value to nearest integer
+ return int(round(scanner.real))
+ def getcoord(self):
+ s = coord()
+ scanner.next()
+ if scanner.type != "IHREAL":
+ huh()
+ return None
+ s.i = scanner.int()-1
+ scanner.next()
+ if scanner.type != "IHREAL":
+ huh()
+ return None
+ s.j = scanner.int()-1
+ return s
+ def __repr__(str):
+ return "<sstcanner: token=%s, type=%s, queue=%s>" % (scanner.token, scanner.type, scanner.inqueue)
+
+def ja():
+ "Yes-or-no confirmation."
+ scanner.chew()
+ while True:
+ scanner.next()
+ if scanner.token == 'y':
+ return True
+ if scanner.token == 'n':
+ return False
+ scanner.chew()
+ proutn(_("Please answer with \"y\" or \"n\": "))
+
+def huh():
+ "Complain about unparseable input."
+ scanner.chew()
+ skip(1)
+ prout(_("Beg your pardon, Captain?"))
+
+def debugme():
+ "Access to the internals for debugging."
+ proutn("Reset levels? ")
+ if ja() == True:
+ if game.energy < game.inenrg:
+ game.energy = game.inenrg
+ game.shield = game.inshld
+ game.torps = game.intorps
+ game.lsupres = game.inlsr
+ proutn("Reset damage? ")
+ if ja() == True:
+ for i in range(NDEVICES):
+ if game.damage[i] > 0.0:
+ game.damage[i] = 0.0
+ proutn("Toggle debug flag? ")
+ if ja() == True:
+ idebug = not idebug
+ if idebug:
+ prout("Debug output ON")
+ else:
+ prout("Debug output OFF")
+ proutn("Cause selective damage? ")
+ if ja() == True:
+ for i in range(NDEVICES):
+ proutn("Kill %s?" % device[i])
+ scanner.chew()
+ key = scanner.next()
+ if key == "IHALPHA" and scanner.sees("y"):
+ game.damage[i] = 10.0
+ proutn("Examine/change events? ")
+ if ja() == True:
+ ev = event()
+ w = coord()
+ legends = {
+ FSNOVA: "Supernova ",
+ FTBEAM: "T Beam ",
+ FSNAP: "Snapshot ",
+ FBATTAK: "Base Attack ",
+ FCDBAS: "Base Destroy ",
+ FSCMOVE: "SC Move ",
+ FSCDBAS: "SC Base Destroy ",
+ FDSPROB: "Probe Move ",
+ FDISTR: "Distress Call ",
+ FENSLV: "Enslavement ",
+ FREPRO: "Klingon Build ",
+ }
+ for i in range(1, NEVENTS):
+ proutn(legends[i])
+ if is_scheduled(i):
+ proutn("%.2f" % (scheduled(i)-game.state.date))
+ if i == FENSLV or i == FREPRO:
+ ev = findevent(i)
+ proutn(" in %s" % ev.quadrant)
+ else:
+ proutn("never")
+ proutn("? ")
+ scanner.chew()
+ key = scanner.next()
+ if key == 'n':
+ unschedule(i)
+ scanner.chew()
+ elif key == "IHREAL":
+ ev = schedule(i, scanner.real)
+ if i == FENSLV or i == FREPRO:
+ scanner.chew()
+ proutn("In quadrant- ")
+ key = scanner.next()
+ # "IHEOL" says to leave coordinates as they are
+ if key != "IHEOL":
+ if key != "IHREAL":
+ prout("Event %d canceled, no x coordinate." % (i))
+ unschedule(i)
+ continue
+ w.i = int(round(scanner.real))
+ key = scanner.next()
+ if key != "IHREAL":
+ prout("Event %d canceled, no y coordinate." % (i))
+ unschedule(i)
+ continue
+ w.j = int(round(scanner.real))
+ ev.quadrant = w
+ scanner.chew()
+ proutn("Induce supernova here? ")
+ if ja() == True:
+ game.state.galaxy[game.quadrant.i][game.quadrant.j].supernova = True
+ atover(True)
+
+if __name__ == '__main__':
+ import getopt, socket
+ try:
+ global line, thing, game, idebug
+ game = None
+ thing = coord()
+ thing.angry = False
+ game = gamestate()
+ idebug = 0
+ game.options = OPTION_ALL &~ (OPTION_IOMODES | OPTION_PLAIN | OPTION_ALMY)
+ if os.getenv("TERM"):
+ game.options |= OPTION_CURSES
+ else:
+ game.options |= OPTION_TTY
+ seed = int(time.time())
+ (options, arguments) = getopt.getopt(sys.argv[1:], "r:s:tx")
+ for (switch, val) in options:
+ if switch == '-r':
+ try:
+ replayfp = open(val, "r")
+ except IOError:
+ sys.stderr.write("sst: can't open replay file %s\n" % val)
+ raise SystemExit, 1
+ try:
+ line = replayfp.readline().strip()
+ (leader, key, seed) = line.split()
+ seed = eval(seed)
+ sys.stderr.write("sst2k: seed set to %s\n" % seed)
+ line = replayfp.readline().strip()
+ arguments += line.split()[2:]
+ except ValueError:
+ sys.stderr.write("sst: replay file %s is ill-formed\n"% val)
+ raise SystemExit(1)
+ game.options |= OPTION_TTY
+ game.options &=~ OPTION_CURSES
+ elif switch == '-s':
+ seed = int(val)
+ elif switch == '-t':
+ game.options |= OPTION_TTY
+ game.options &=~ OPTION_CURSES
+ elif switch == '-x':
+ idebug = True
+ else:
+ sys.stderr.write("usage: sst [-t] [-x] [startcommand...].\n")
+ raise SystemExit, 1
+ # where to save the input in case of bugs
+ try:
+ logfp = open("/usr/tmp/sst-input.log", "w")
+ except IOError:
+ sys.stderr.write("sst: warning, can't open logfile\n")
+ 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)
+ try:
+ iostart()
+ while True: # Play a game
+ setwnd(fullscreen_window)
+ clrscr()
+ prelim()
+ setup()
+ if game.alldone:
+ score()
+ game.alldone = False
+ else:
+ makemoves()
+ skip(1)
+ stars()
+ skip(1)
+ if game.tourn and game.alldone:
+ proutn(_("Do you want your score recorded?"))
+ if ja() == True:
+ scanner.chew()
+ scanner.push("\n")
+ freeze(False)
+ scanner.chew()
+ proutn(_("Do you want to play again? "))
+ if not ja():
+ break
+ skip(1)
+ prout(_("May the Great Bird of the Galaxy roost upon your home planet."))
+ finally:
+ ioend()
+ raise SystemExit, 0
+ except KeyboardInterrupt:
+ if logfp:
+ logfp.close()
+ print ""