Parcourir la source

Add support for Display_Percent option.

Anything >= this % is displayed.
If unknown, it is displayed.
Steve Thielemann il y a 5 ans
Parent
commit
482e7d41bf
2 fichiers modifiés avec 55 ajouts et 13 suppressions
  1. 34 6
      flexible.py
  2. 21 7
      galaxy.py

+ 34 - 6
flexible.py

@@ -1333,7 +1333,8 @@ class ScriptExplore(object):
             for c in self.clear:
                 sector = c['sector']
                 if sector != self.highsector:
-                    self.stacksector.append(sector)
+                    if sector not in self.stacksector:
+                        self.stacksector.append(sector)
             
             # Or simply not add it in the first place ...
             # Remove the sector we are just about to go to, we use discard so if the sector does not exist we don't throw a error!
@@ -1405,7 +1406,8 @@ class ScriptExplore(object):
                     log.info("STOPHERE")
                     # Ok, let's stop here!
                     # Re-save the sector we were trying to get to.  (we didn't make it there)
-                    self.stacksector.append(self.highsector)
+                    if self.highsector not in self.stacksector:
+                        self.stacksector.append(self.highsector)
                     self.state = 20
                 else:
                     if self.go_on:
@@ -1414,7 +1416,8 @@ class ScriptExplore(object):
                         self.state = 15
                     else:
                         log.warn("Our way is blocked...")
-                        self.stacksector.append(self.highsector)
+                        if self.highsector not in self.stacksector:
+                            self.stacksector.append(self.highsector)
                         self.state = 20
 
             else:
@@ -1821,6 +1824,25 @@ class ProxyMenu(object):
 
         show_best = self.game.gamedata.get_config('Display_Best', 'Y').upper()[0] == 'Y'
         show_ok = self.game.gamedata.get_config('Display_Ok', 'N').upper()[0] == 'Y'
+        show_limit = self.game.gamedata.get_config('Display_Percent', '90')
+
+        update_config = False
+
+        try:
+            show_limit = int(show_limit)
+        except ValueError:
+            show_limit = 90
+            update_config = True
+
+        if show_limit < 0:
+            show_limit = 0
+            update_config = True
+        elif show_limit > 100:
+            show_limit = 100
+            update_config = True
+
+        if update_config:
+            self.game.gamedata.set_config('Trade_Percent', self.percent)
 
         # for sector, pd in self.game.gamedata.ports.items():
         for sector in sorted(self.game.gamedata.ports.keys()):
@@ -1853,14 +1875,20 @@ class ProxyMenu(object):
                             # 8: "BBB",
 
                             if pc in (1,5) and wc in (2,4):
-                                best_trades.append(self.game.gamedata.port_trade_show(sector, w))
+                                data = self.game.gamedata.port_trade_show(sector, w, show_limit)
+                                if data:
+                                    best_trades.append(data)
                                 # best_trades.append( "{0:5} -=- {1:5}".format(sector, w))
                             elif pc in (2,4) and wc in (1,5):
-                                best_trades.append(self.game.gamedata.port_trade_show(sector, w))
+                                data = self.game.gamedata.port_trade_show(sector, w, show_limit)
+                                if data:
+                                    best_trades.append(data)                                    
                                 # best_trades.append( "{0:5} -=- {1:5}".format(sector, w))
                             elif GameData.port_trading(pd['port'], self.game.gamedata.ports[w]['port']):
                                 # ok_trades.append( "{0:5} -=- {1:5}".format(sector,w))
-                                ok_trades.append(self.game.gamedata.port_trade_show(sector, w))
+                                data = self.game.gamedata.port_trade_show(sector, w, show_limit)
+                                if data:
+                                    ok_trades.append(data)
             yield
 
         if show_best:

+ 21 - 7
galaxy.py

@@ -342,15 +342,29 @@ class GameData(object):
             sector, sector_port["port"], GameData.port_pct(sector_port)
         )
 
-    def port_trade_show(self, sector: int, warp: int):
+    def port_above(self, port: dict, limit: int) -> bool:
+        if all(x in port for x in ["fuel", "org", "equ"]):
+            if all(
+                x in port and port[x]["pct"] >= limit for x in ["fuel", "org", "equ"]
+            ):
+                return True
+            else:
+                return False
+        # Port is unknown, we'll assume it is above the limit.
+        return True
+
+    def port_trade_show(self, sector: int, warp: int, limit: int = 90):
         sector_port = self.ports[sector]
         warp_port = self.ports[warp]
-        # sector_pct = GameData.port_pct(sector_port)
-        # warp_pct = GameData.port_pct(warp_port)
-        return "{0} \xae\xcd\xaf {1}".format(
-            GameData.port_show_part(sector, sector_port),
-            GameData.port_show_part(warp, warp_port),
-        )
+
+        if self.port_above(sector_port, limit) and self.port_above(warp_port, limit):
+            # sector_pct = GameData.port_pct(sector_port)
+            # warp_pct = GameData.port_pct(warp_port)
+            return "{0} \xae\xcd\xaf {1}".format(
+                GameData.port_show_part(sector, sector_port),
+                GameData.port_show_part(warp, warp_port),
+            )
+        return None
 
     @staticmethod
     def port_show(sector: int, sector_port: dict, warp: int, warp_port: dict):