OPTION_COLOR = 0x04000000 # enable color display (ESR, 2010)
OPTION_DOTFILL = 0x08000000 # fix dotfill glitch in chart (ESR, 2019)
+option_names = {
+ "ALL": OPTION_ALL,
+ "TTY": OPTION_TTY,
+ "IOMODES": OPTION_IOMODES,
+ "PLANETS": OPTION_PLANETS,
+ "THOLIAN": OPTION_THOLIAN,
+ "THINGY": OPTION_THINGY,
+ "PROBE": OPTION_PROBE,
+ "SHOWME": OPTION_SHOWME,
+ "RAMMING": OPTION_RAMMING,
+ "MVBADDY": OPTION_MVBADDY,
+ "BLKHOLE": OPTION_BLKHOLE,
+ "BASE": OPTION_BASE,
+ "WORLDS": OPTION_WORLDS,
+ "AUTOSCAN": OPTION_AUTOSCAN,
+ "CAPTURE": OPTION_CAPTURE,
+ "CLOAK": OPTION_CLOAK,
+ "PLAIN": OPTION_PLAIN,
+ "ALMY": OPTION_ALMY,
+ "COLOR": OPTION_COLOR,
+ "DOTFILL": OPTION_DOTFILL,
+ }
+
# Define devices
DSRSENS = 0
DLRSENS = 1
scanner.chew()
iprompt = True
key = scanner.nexttok()
- if key != "IHREAL":
- huh()
- raise TrekError
- xi = int(round(scanner.real))-1
- key = scanner.nexttok()
- if key != "IHREAL":
- huh()
+ scanner.push(scanner.token) # Something IHREAL or IHALPHA awaits us
+ first = scanner.getcoord()
+ if first is None:
raise TrekError
- xj = int(round(scanner.real))-1
- key = scanner.nexttok()
- if key == "IHREAL":
- # both quadrant and sector specified
- xk = int(round(scanner.real))-1
- key = scanner.nexttok()
- if key != "IHREAL":
- huh()
+ scanner.nexttok()
+ if scanner.type == "IHEOL":
+ second = None
+ else:
+ scanner.push(scanner.token)
+ second = scanner.getcoord()
+ if second is None:
raise TrekError
- xl = int(round(scanner.real))-1
- dquad.i = xi
- dquad.j = xj
- dsect.i = xk
- dsect.j = xl
+ scanner.chew()
+ if second is not None:
+ dquad.i = first.i
+ dquad.j = first.j
+ dsect.i = second.i
+ dsect.j = second.j
else:
# only one pair of numbers was specified
if isprobe:
# only quadrant specified -- go to center of dest quad
- dquad.i = xi
- dquad.j = xj
- dsect.j = dsect.i = 4 # preserves 1-origin behavior
+ dquad.i = first.i
+ dquad.j = first.j
+ dsect.j = dsect.i = (QUADSIZE/2)-1 # preserves 1-origin behavior
else:
# only sector specified
- dsect.i = xi
- dsect.j = xj
+ dsect.i = first.i
+ dsect.j = first.j
itemp = "normal"
if not dquad.valid_quadrant() or not dsect.valid_sector():
huh()
skip(1)
return
+# This is new in SST2K.
+
+def goptions():
+ mode = scanner.nexttok()
+ if mode == "IHEOL":
+ active = []
+ for k, v in option_names.items():
+ if (v & game.options) and k != "ALL":
+ active.append(k)
+ active.sort()
+ prout(str(" ".join(active)))
+ elif scanner.token in {"set", "clear"}:
+ mode = scanner.token
+ changemask = 0
+ while True:
+ scanner.nexttok()
+ if scanner.type == "IHEOL":
+ break
+ if scanner.token.upper() in option_names:
+ changemask |= option_names[scanner.token.upper()]
+ else:
+ prout(_("No such option as ") + scanner.token)
+ if mode == "set":
+ if (not (game.options & OPTION_CURSES)) and (changemask & OPTION_CURSES):
+ iostart()
+ game.options |= changemask
+ elif mode == "clear":
+ if (game.options & OPTION_CURSES) and (not (changemask & OPTION_CURSES)):
+ ioend()
+ game.options &=~ changemask
+ prout(_("Acknowledged, Captain."))
+ else:
+ huh()
+ scanner.chew()
+ skip(1)
+
# Code from setup.c begins here
def prelim():
("PROBE", OPTION_PROBE),
("SAVE", 0),
("FREEZE", 0), # Synonym for SAVE
+ ("OPTIONS", 0),
("ABANDON", 0),
+ # No abbreviations accepted after this point
("DESTRUCT", 0),
("DEATHRAY", 0),
("CAPTURE", OPTION_CAPTURE),
("QUIT", 0),
("HELP", 0),
("SCORE", 0),
- ("CURSES", 0),
+ ("CURSES", 0),
("", 0),
]
elif cmd == "CURSES":
game.options |= (OPTION_CURSES | OPTION_COLOR)
iostart()
+ elif cmd == "OPTIONS":
+ goptions()
while True:
if game.alldone:
break # Game has ended
# Get a token from the user
self.real = 0.0
self.token = ''
- # Fill the token quue if nothing here
+ # Fill the token queue if nothing here
while not self.inqueue:
sline = cgetline()
if curwnd==prompt_window:
game.options |= OPTION_TTY
seed = int(time.time())
(options, arguments) = getopt.getopt(sys.argv[1:], "cr:s:txV")
- replay = False
for (switch, val) in options:
if switch == '-r':
# pylint: disable=raise-missing-from
seed = eval(seed)
line = replayfp.readline().strip()
arguments += line.split()[2:]
- replay = True
except ValueError:
sys.stderr.write("sst: replay file %s is ill-formed\n"% val)
raise SystemExit(1)
sys.exit(1)
if logfp:
logfp.write("# seed %s\n" % seed)
- logfp.write("# options %s\n" % " ".join(arguments))
+ logfp.write("# arguments %s\n" % " ".join(arguments))
logfp.write("# SST2K version %s\n" % version)
logfp.write("# recorded by %s@%s on %s\n" % \
(getpass.getuser(),socket.getfqdn(),time.ctime()))
game.alldone = False
else:
makemoves()
- if replay:
+ if replayfp:
break
skip(1)
stars()