|
@@ -1776,6 +1776,97 @@ class ScriptSpace(object):
|
|
|
log.info("We're here!")
|
|
|
self.deactivate()
|
|
|
|
|
|
+class ScriptSook(object):
|
|
|
+ """ Searches Unknown sectors using current location as starting point
|
|
|
+
|
|
|
+ TO-DO: (+ Done, - Undone)
|
|
|
+ - Grab current sector from sending "D"
|
|
|
+ - Grab all unknown sectors from sending "^U"
|
|
|
+ """
|
|
|
+ def __init__(self, game):
|
|
|
+ self.game = game
|
|
|
+ self.queue_game = game.queue_game
|
|
|
+ self.queue_player = game.queue_player
|
|
|
+ self.observer = game.observer
|
|
|
+ self.r = Style.RESET_ALL
|
|
|
+ self.nl = "\n\r"
|
|
|
+
|
|
|
+ self.startpoint = None # Since we don't know where we are!
|
|
|
+ self.unknown_verse = [] # This will contain all unknow sectors, since the first action is to load in all unknown sectors!
|
|
|
+ self.dense = [] # This will contain previous density scan values
|
|
|
+
|
|
|
+ # Activate
|
|
|
+ self.prompt = game.buffer
|
|
|
+ self.save = self.observer.save()
|
|
|
+ self.observer.connect('player', self.player)
|
|
|
+ self.observer.connect("prompt", self.game_prompt)
|
|
|
+ self.observer.connect("game-line", self.game_line)
|
|
|
+ self.state = 1
|
|
|
+ self.send2player("Sook!" + self.nl)
|
|
|
+ self.send2game("D")
|
|
|
+
|
|
|
+ def whenDone(self):
|
|
|
+ self.defer = defer.Deferred()
|
|
|
+ # Call this to chain something after we exit.
|
|
|
+ return self.defer
|
|
|
+
|
|
|
+ def deactivate(self, andExit=False):
|
|
|
+ self.state = 0
|
|
|
+ log.debug("ScriptSook.deactivate()")
|
|
|
+ assert(not self.save is None)
|
|
|
+ self.observer.load(self.save)
|
|
|
+ self.save = None
|
|
|
+ if self.defer:
|
|
|
+ if andExit:
|
|
|
+ self.defer.callback({'exit':True})
|
|
|
+ else:
|
|
|
+ self.defer.callback('done')
|
|
|
+ self.defer = None
|
|
|
+
|
|
|
+ def player(self, chunk: bytes):
|
|
|
+ # If we receive anything -- ABORT! ABORT!
|
|
|
+ self.deactivate(True)
|
|
|
+
|
|
|
+ def send2game(self, txt):
|
|
|
+ log.debug("ScriptSook.send2game({0})".format(txt))
|
|
|
+ self.queue_player.put(txt)
|
|
|
+
|
|
|
+ def send2player(self, txt):
|
|
|
+ log.debug("ScriptSook.send2player({0})".format(txt))
|
|
|
+ self.queue_game.put(txt)
|
|
|
+
|
|
|
+ def game_prompt(self, prompt: str):
|
|
|
+ log.debug("P {0} : {1}".format(self.state, prompt))
|
|
|
+ if self.state == 1:
|
|
|
+ # Recieved Init Sending "D" to grab current sector!
|
|
|
+ if re.match(r"Command \[TL=.* \(\?=Help\)\? :", prompt):
|
|
|
+ # Confirm we are at the Command Prompt, now to grab the sector ###
|
|
|
+ work = prompt.replace('Command [TL=', '').replace(']:', '').replace('] (?=Help)? :', '').replace('', '')
|
|
|
+ _, work = work.split('[')
|
|
|
+ log.debug("self.startpoint = {0}".format(work))
|
|
|
+ self.startpoint = work
|
|
|
+ self.send2game("^U") # Enter INTERROG and get all unknown sectors
|
|
|
+ self.state += 1
|
|
|
+ elif self.state == 3:
|
|
|
+ # Ok now we want to pass this onto ScriptExplore most likely somehow adding our hugh list to the stack of it... hmm
|
|
|
+ if re.match(r"Command \[TL=.* \(\?=Help\)\? :", prompt):
|
|
|
+ # Any ideas how to do that?
|
|
|
+ log.debug("Done?")
|
|
|
+
|
|
|
+ def game_line(self, line: str):
|
|
|
+ log.debug("L {0} : {1}".format(self.state, line))
|
|
|
+ if self.state == 2:
|
|
|
+ # Ok we have asked for all unknown sectors lets do something about that
|
|
|
+ if line == '':
|
|
|
+ self.send2game("Q") # Exits INTERROG
|
|
|
+ log.debug("self.unknown_verse = {0}".format(len(self.unknown_verse)))
|
|
|
+ self.state += 1
|
|
|
+ else:
|
|
|
+ if ':' not in line: # Ignore Command and : from us sending "^U"
|
|
|
+ work = line.split(' ')
|
|
|
+ for w in work:
|
|
|
+ if w.strip():
|
|
|
+ self.unknown_verse.append(int(w.strip()))
|
|
|
|
|
|
class ScriptTerror(object):
|
|
|
""" Terror script. """
|
|
@@ -2517,6 +2608,13 @@ class ProxyMenu(object):
|
|
|
space = ScriptSpace(self.game)
|
|
|
d = space.whenDone()
|
|
|
|
|
|
+ d.addCallback(self.deactivate_scripts_menu)
|
|
|
+ d.addErrback(self.deactivate_scripts_menu)
|
|
|
+ return
|
|
|
+ elif key == '@':
|
|
|
+ self.queue_game.put(self.c + key + self.r + self.nl)
|
|
|
+ dog = ScriptSook(self.game)
|
|
|
+ d = dog.whenDone()
|
|
|
d.addCallback(self.deactivate_scripts_menu)
|
|
|
d.addErrback(self.deactivate_scripts_menu)
|
|
|
return
|