|
@@ -156,7 +156,7 @@ class PlayerInput(object):
|
|
|
assert self.deferred is None
|
|
|
d = defer.Deferred()
|
|
|
self.deferred = d
|
|
|
- log.debug("Return deferred ...", self.deferred)
|
|
|
+ log.debug("Return deferred ...")
|
|
|
return d
|
|
|
|
|
|
def get_input(self, chunk):
|
|
@@ -553,6 +553,7 @@ class ScriptPort(object):
|
|
|
def deactivate(self):
|
|
|
self.state = 0
|
|
|
log.debug("ScriptPort.deactivate ({0})".format(self.times_left))
|
|
|
+ self.queue_game.put(self.nl + Boxes.alert("Trading Script deactivating...", width=50))
|
|
|
assert(not self.save is None)
|
|
|
self.observer.load(self.save)
|
|
|
self.save = None
|
|
@@ -616,12 +617,6 @@ class ScriptPort(object):
|
|
|
self.sector2)
|
|
|
))
|
|
|
|
|
|
- # The code is smart enough now, that this can't happen. :( Drat!
|
|
|
- if self.game.gamedata.ports[self.this_sector]['port'] == self.game.gamedata.ports[self.sector2]['port']:
|
|
|
- self.queue_game.put("Hey dummy! Look out the window! These ports are the same class!" + nl)
|
|
|
- self.deactivate()
|
|
|
- return
|
|
|
-
|
|
|
pi = PlayerInput(self.game)
|
|
|
def got_need2(*_):
|
|
|
if pi.keep['count'].strip() == '':
|
|
@@ -639,26 +634,25 @@ class ScriptPort(object):
|
|
|
elif self.state == 6:
|
|
|
if re.match(r"Command \[TL=.* \(\?=Help\)\? :", prompt):
|
|
|
if self.fixable:
|
|
|
- self.queue_game.put("Ok! Let's fix this by going to the other sector..." + self.nl)
|
|
|
+ # self.queue_game.put("Ok! Let's fix this by going to the other sector..." + self.nl)
|
|
|
+ self.queue_game.put(self.nl + Boxes.alert("Ok, FINE. We'll trade with the other port.", base="green", style=0))
|
|
|
log.debug("Fixing...")
|
|
|
- if self.this_sector == self.sector1:
|
|
|
- self.this_sector = self.sector2
|
|
|
- self.queue_player.put("{0}\r".format(self.sector2))
|
|
|
- self.state = 5
|
|
|
- self.trade()
|
|
|
- else:
|
|
|
- self.this_sector = self.sector1
|
|
|
- self.queue_player.put("{0}\r".format(self.sector1))
|
|
|
- self.state = 5
|
|
|
- self.trade()
|
|
|
+
|
|
|
+ # Swap this and other sector
|
|
|
+ self.this_sector, self.other_sector = (self.other_sector, self.this_sector)
|
|
|
+
|
|
|
+ self.queue_player.put("{0}\r".format(self.sector2))
|
|
|
+ self.state = 5
|
|
|
+ self.trade()
|
|
|
+
|
|
|
elif self.state == 7:
|
|
|
if re.match(r"Command \[TL=.* \(\?=Help\)\? :", prompt):
|
|
|
# Done
|
|
|
- if self.this_sector == self.sector1:
|
|
|
- self.this_sector = self.sector2
|
|
|
- self.queue_player.put("{0}\r".format(self.sector2))
|
|
|
- self.state = 10
|
|
|
- else:
|
|
|
+
|
|
|
+ # Swap this and other sector
|
|
|
+ self.this_sector, self.other_sector = (self.other_sector, self.this_sector)
|
|
|
+
|
|
|
+ if self.this_sector == self.sector2:
|
|
|
self.times_left -= 1
|
|
|
if self.times_left <= 0:
|
|
|
# Ok, exit out
|
|
@@ -672,9 +666,10 @@ class ScriptPort(object):
|
|
|
self.queue_game.put(self.r + self.nl + "We don't seem to be making any money here. I'm stopping!" + self.nl)
|
|
|
self.deactivate()
|
|
|
return
|
|
|
- self.this_sector = self.sector1
|
|
|
- self.queue_player.put("{0}\r".format(self.sector1))
|
|
|
- self.state = 10
|
|
|
+
|
|
|
+ self.queue_player.put("{0}\r".format(self.this_sector))
|
|
|
+ self.state = 10
|
|
|
+
|
|
|
elif re.match(r'Your offer \[\d+\] \?', prompt):
|
|
|
if self.fix_offer:
|
|
|
# Make real offer / WHAT?@?!
|
|
@@ -732,11 +727,11 @@ class ScriptPort(object):
|
|
|
self.queue_player.put("\r")
|
|
|
elif re.match(r"Command \[TL=.* \(\?=Help\)\? :", prompt):
|
|
|
# Done
|
|
|
- if self.this_sector == self.sector1:
|
|
|
- self.this_sector = self.sector2
|
|
|
- self.queue_player.put("{0}\r".format(self.sector2))
|
|
|
- self.state = 10
|
|
|
- else:
|
|
|
+
|
|
|
+ # Swap this and other sector
|
|
|
+ self.this_sector, self.other_sector = (self.other_sector, self.this_sector)
|
|
|
+
|
|
|
+ if self.this_sector == self.sector2:
|
|
|
self.times_left -= 1
|
|
|
if self.times_left <= 0:
|
|
|
# Ok, exit out
|
|
@@ -747,12 +742,21 @@ class ScriptPort(object):
|
|
|
else:
|
|
|
if self.credits <= self.last_credits:
|
|
|
log.warn("We don't seem to be making any money here...")
|
|
|
+ self.queue_game.put(self.r + self.nl + "We don't seem to be making any money here. I'm stopping!" + self.nl)
|
|
|
self.deactivate()
|
|
|
return
|
|
|
- self.this_sector = self.sector1
|
|
|
- self.queue_player.put("{0}\r".format(self.sector1))
|
|
|
- self.state = 10
|
|
|
|
|
|
+ self.queue_player.put("{0}\r".format(self.this_sector))
|
|
|
+ self.state = 10
|
|
|
+
|
|
|
+ elif self.state == 99:
|
|
|
+ # This is a good place to deactivate at.
|
|
|
+ if re.match(r"Command \[TL=.* \(\?=Help\)\? :", prompt):
|
|
|
+ if hasattr(self, 'message'):
|
|
|
+ if self.message is not None:
|
|
|
+ self.queue_game.put(self.message)
|
|
|
+ self.message = None
|
|
|
+ self.deactivate()
|
|
|
|
|
|
|
|
|
|
|
@@ -762,10 +766,14 @@ class ScriptPort(object):
|
|
|
self.queue_player.put("pt") # Port Trade
|
|
|
|
|
|
self.this_port = self.game.gamedata.ports[self.this_sector]
|
|
|
+ # I think other_sector will alway be correct, but leaving this
|
|
|
+ # for now. FUTURE: TODO: REMOVE
|
|
|
if self.this_sector == self.sector1:
|
|
|
- self.other_port = self.game.gamedata.ports[self.sector2]
|
|
|
+ self.other_sector = self.sector2
|
|
|
else:
|
|
|
- self.other_port = self.game.gamedata.ports[self.sector1]
|
|
|
+ self.other_sector = self.sector1
|
|
|
+
|
|
|
+ self.other_port = self.game.gamedata.ports[self.other_sector]
|
|
|
|
|
|
# Ok, perform some calculations
|
|
|
self.tpc = self.this_port['class']
|
|
@@ -832,7 +840,7 @@ class ScriptPort(object):
|
|
|
return
|
|
|
|
|
|
possible = [ x for x in self.warps if x in self.game.gamedata.ports ]
|
|
|
- log.debug("Possible:", possible)
|
|
|
+ log.debug("Possible: {0}".format(possible))
|
|
|
|
|
|
# BUG: Sometimes links to another sector, don't link back!
|
|
|
# This causes the game to plot a course / autopilot.
|
|
@@ -849,7 +857,7 @@ class ScriptPort(object):
|
|
|
return
|
|
|
|
|
|
possible = [ x for x in possible if not GameData.port_burnt(self.game.gamedata.ports[x]) ]
|
|
|
- log.debug("Possible:", possible)
|
|
|
+ log.debug("Possible: {0}".format(possible))
|
|
|
|
|
|
if len(possible) == 0:
|
|
|
self.state = 0
|
|
@@ -901,20 +909,13 @@ class ScriptPort(object):
|
|
|
if parts[-1] != '0' and parts[2] != '0' and parts[1] != 'Buying':
|
|
|
log.warn("We have a problem -- they aren't buying what we have in stock!")
|
|
|
stuff = line[0] # F O or E.
|
|
|
- if stuff == 'F':
|
|
|
- spos = 0
|
|
|
- elif stuff == 'O':
|
|
|
- spos = 1
|
|
|
- else:
|
|
|
- spos = 2
|
|
|
- other = self.other_port['port']
|
|
|
- if other[spos] == 'B':
|
|
|
- self.fixable = 1
|
|
|
+ if self.game.gamedata.port_buying(self.other_sector, stuff):
|
|
|
+ self.fixable = True
|
|
|
|
|
|
if "You don't have anything they want" in line:
|
|
|
# Neither! DRAT!
|
|
|
if not self.fixable:
|
|
|
- self.deactivate()
|
|
|
+ self.state = 99
|
|
|
return
|
|
|
if "We're not interested." in line:
|
|
|
log.warn("Try, try again. :(")
|