Parcourir la source

Terror: use OK trade pairs when you run out of good.

Steve Thielemann il y a 5 ans
Parent
commit
cc323e5b3f
1 fichiers modifiés avec 82 ajouts et 40 suppressions
  1. 82 40
      flexible.py

+ 82 - 40
flexible.py

@@ -1766,7 +1766,7 @@ class ScriptTerror(object):
         self.r = Style.RESET_ALL
         self.nl = "\n\r"
 
-        self.target_sector = self.proxy.find_next_good_trade_pair()   # Sector going to
+        self.target_sector = None
 
         # Activate
         self.prompt = game.buffer
@@ -1775,10 +1775,83 @@ class ScriptTerror(object):
         self.observer.connect("prompt", self.game_prompt)
         self.observer.connect("game-line", self.game_line)
 
+        self.state = 0
         self.defer = None
+        c = coiterate(self.find_next_good_trade_pair())
+        c.addCallback(lambda unknown: self.scary())
 
-        self.state = 1
-        self.queue_player.put("{0}\r".format(self.target_sector))
+    def scary(self):
+        if self.target_sector is None:
+            self.queue_game.put(Boxes.alert("Sorry! I don't see any ports to trade with.", base="red"))
+            self.deactivate()
+        else:
+            self.state = 1            
+            self.queue_player.put("{0}\r".format(self.target_sector))
+
+    def find_next_good_trade_pair(self):
+        """ Find the next GOOD trade pair sector. """
+
+        show_limit = 90
+        # Look for "GOOD" trades
+
+        for sector in sorted(self.game.gamedata.ports.keys()):
+            pd = self.game.gamedata.ports[sector]
+            if not GameData.port_burnt(pd):
+                pc = pd['class']
+
+                # Ok, let's look into it.
+                if not sector in self.game.gamedata.warps:
+                    continue
+
+                warps = self.game.gamedata.warps[sector]
+                for w in warps:
+                    # We can get there, and get back.
+                    if w in self.game.gamedata.warps and sector in self.game.gamedata.warps[w]:
+                        # Ok, we can get there -- and get back!
+                        if w > sector and w in self.game.gamedata.ports and not GameData.port_burnt(self.game.gamedata.ports[w]):
+                            wd = self.game.gamedata.ports[w]
+                            wc = wd['class']
+
+                            if pc in (1,5) and wc in (2,4):
+                                data = self.game.gamedata.port_trade_show(sector, w, show_limit)
+                                if data:
+                                    self.target_sector = sector
+                                    return sector
+                            elif pc in (2,4) and wc in (1,5):
+                                data = self.game.gamedata.port_trade_show(sector, w, show_limit)
+                                if data:
+                                    self.target_sector = sector
+                                    return sector
+            yield 
+
+        # Look for OK trades
+        for sector in sorted(self.game.gamedata.ports.keys()):
+            pd = self.game.gamedata.ports[sector]
+            if not GameData.port_burnt(pd):
+                pc = pd['class']
+
+                # Ok, let's look into it.
+                if not sector in self.game.gamedata.warps:
+                    continue
+
+                warps = self.game.gamedata.warps[sector]
+                for w in warps:
+                    # We can get there, and get back.
+                    if w in self.game.gamedata.warps and sector in self.game.gamedata.warps[w]:
+                        # Ok, we can get there -- and get back!
+                        if w > sector and w in self.game.gamedata.ports and not GameData.port_burnt(self.game.gamedata.ports[w]):
+                            wd = self.game.gamedata.ports[w]
+                            wc = wd['class']
+
+                            if GameData.port_trading(pd['port'], self.game.gamedata.ports[w]['port']):
+                                data = self.game.gamedata.port_trade_show(sector, w, show_limit)
+                                if data:
+                                    self.target_sector = sector
+                                    return sector
+            yield 
+
+        self.target_sector = None
+        
 
 
     def whenDone(self):
@@ -1807,9 +1880,12 @@ class ScriptTerror(object):
         log.info("journey_on( {0})".format(self.count))
         if self.count > 0:
             self.count -= 1
-            self.target_sector = self.proxy.find_next_good_trade_pair()   # Sector going to
-            self.state = 1
-            self.queue_player.put("{0}\r".format(self.target_sector))
+        
+            c = coiterate(self.find_next_good_trade_pair())
+            c.addCallback(lambda unknown: self.scary())            
+            # self.target_sector = self.proxy.find_next_good_trade_pair()   # Sector going to
+            # self.state = 1
+            # self.queue_player.put("{0}\r".format(self.target_sector))
         else:
             self.deactivate()
 
@@ -1946,40 +2022,6 @@ class ProxyMenu(object):
         self.queue_game.put("Loaded {0} sectors.".format(len(warpdata)) + self.nl)
         self.welcome_back()
 
-    def find_next_good_trade_pair(self):
-        """ Find the next GOOD trade pair sector. """
-
-        show_limit = 90
-
-        for sector in sorted(self.game.gamedata.ports.keys()):
-            pd = self.game.gamedata.ports[sector]
-            if not GameData.port_burnt(pd):
-                pc = pd['class']
-
-                # Ok, let's look into it.
-                if not sector in self.game.gamedata.warps:
-                    continue
-
-                warps = self.game.gamedata.warps[sector]
-                for w in warps:
-                    # We can get there, and get back.
-                    if w in self.game.gamedata.warps and sector in self.game.gamedata.warps[w]:
-                        # Ok, we can get there -- and get back!
-                        if w > sector and w in self.game.gamedata.ports and not GameData.port_burnt(self.game.gamedata.ports[w]):
-                            wd = self.game.gamedata.ports[w]
-                            wc = wd['class']
-
-                            if pc in (1,5) and wc in (2,4):
-                                data = self.game.gamedata.port_trade_show(sector, w, show_limit)
-                                if data:
-                                    return sector
-                            elif pc in (2,4) and wc in (1,5):
-                                data = self.game.gamedata.port_trade_show(sector, w, show_limit)
-                                if data:
-                                    return sector
-            # yield 
-        return None
-
     def make_trade_report(self):
         log.debug("make_trade_report()")
         ok_trades = []