|
@@ -57,7 +57,9 @@ class GameData(object):
|
|
|
def special_ports(self):
|
|
|
""" Save the special class ports 0, 9 """
|
|
|
return {
|
|
|
- p: self.ports[p] for p in self.ports if 'class' in self.ports[p] and self.ports[p]["class"] in (0, 9)
|
|
|
+ p: self.ports[p]
|
|
|
+ for p in self.ports
|
|
|
+ if "class" in self.ports[p] and self.ports[p]["class"] in (0, 9)
|
|
|
}
|
|
|
|
|
|
def display(self):
|
|
@@ -288,8 +290,12 @@ class GameData(object):
|
|
|
return True
|
|
|
|
|
|
cargo_index = cargo_to_index[cargo]
|
|
|
- if port["port"] in ('Special', 'StarDock'):
|
|
|
- log.warn("port_buying( {0}, {1}): not buying (is {2})".format(sector, cargo, port['port']))
|
|
|
+ if port["port"] in ("Special", "StarDock"):
|
|
|
+ log.warn(
|
|
|
+ "port_buying( {0}, {1}): not buying (is {2})".format(
|
|
|
+ sector, cargo, port["port"]
|
|
|
+ )
|
|
|
+ )
|
|
|
return False
|
|
|
if port["port"][cargo_index] == "S":
|
|
|
log.warn("port_buying( {0}, {1}): not buying cargo".format(sector, cargo))
|
|
@@ -346,7 +352,7 @@ class GameData(object):
|
|
|
# Given the port settings, can we trade between these?
|
|
|
if port1 == port2:
|
|
|
return False
|
|
|
- if port1 in ('Special', 'StarDock') or port2 in ('Special', 'StarDock'):
|
|
|
+ if port1 in ("Special", "StarDock") or port2 in ("Special", "StarDock"):
|
|
|
return False
|
|
|
|
|
|
p1 = [c for c in port1]
|
|
@@ -445,6 +451,81 @@ class GameData(object):
|
|
|
GameData.port_show_part(warp, warp_port),
|
|
|
)
|
|
|
|
|
|
+ def find_nearest_tradepairs(self, sector: int, obj):
|
|
|
+ """ find nearest tradepair
|
|
|
+
|
|
|
+ When do we use good? When do we use ok?
|
|
|
+ """
|
|
|
+ searched = set()
|
|
|
+ if sector not in self.warps:
|
|
|
+ log.warn(":Sector {0} not in warps.".format(sector))
|
|
|
+ obj.target_sector = None
|
|
|
+ return None
|
|
|
+
|
|
|
+ # Start with the current sector
|
|
|
+ look = set((sector,))
|
|
|
+
|
|
|
+ while len(look) > 0:
|
|
|
+ log.warn("Searched [{0}]".format(searched))
|
|
|
+ log.warn("Checking [{0}]".format(look))
|
|
|
+ for s in look:
|
|
|
+ if s in self.ports:
|
|
|
+ # Ok, there's a port at least
|
|
|
+ sp = self.ports[s]
|
|
|
+ if sp["port"] in ("Special", "StarDock"):
|
|
|
+ continue
|
|
|
+ if self.port_burnt(sp):
|
|
|
+ continue
|
|
|
+ if "class" not in sp:
|
|
|
+ continue
|
|
|
+ sc = sp["class"]
|
|
|
+
|
|
|
+ log.warn("{0} has warps {1}".format(s, self.warps[s]))
|
|
|
+
|
|
|
+ # Ok, check for tradepairs.
|
|
|
+ for w in self.warps[s]:
|
|
|
+ if not w in self.warps:
|
|
|
+ continue
|
|
|
+ if not s in self.warps[w]:
|
|
|
+ continue
|
|
|
+ if not w in self.ports:
|
|
|
+ continue
|
|
|
+
|
|
|
+ # Ok, has possible port
|
|
|
+ cp = self.ports[w]
|
|
|
+ if cp["port"] in ("Special", "StarDock"):
|
|
|
+ continue
|
|
|
+ if self.port_burnt(cp):
|
|
|
+ continue
|
|
|
+ if "class" not in cp:
|
|
|
+ continue
|
|
|
+ cc = cp["class"]
|
|
|
+ log.warn("{0} {1} - {2} {3}".format(s, sc, w, cc))
|
|
|
+ if sc in (1, 5) and cc in (2, 4):
|
|
|
+ # Good!
|
|
|
+ log.warn("GOOD: {0}".format(s))
|
|
|
+ obj.target_sector = s
|
|
|
+ return s
|
|
|
+ if sc in (2, 4) and cc in (1, 5):
|
|
|
+ # Good!
|
|
|
+ log.warn("GOOD: {0}".format(s))
|
|
|
+ obj.target_sector = s
|
|
|
+ return s
|
|
|
+ # What about "OK" pairs?
|
|
|
+
|
|
|
+ # Ok, not found here.
|
|
|
+ searched.update(look)
|
|
|
+ step_from = look
|
|
|
+ look = set()
|
|
|
+ for s in step_from:
|
|
|
+ if s in self.warps:
|
|
|
+ look.update(self.warps[s])
|
|
|
+ # Look only contains warps we haven't searched
|
|
|
+ look = look.difference(searched)
|
|
|
+ yield
|
|
|
+ obj.target_sector = None
|
|
|
+ return None
|
|
|
+
|
|
|
def find_nearest_selling(
|
|
|
self, sector: int, selling: str, at_least: int = 100
|
|
|
) -> int:
|
|
@@ -474,7 +555,7 @@ class GameData(object):
|
|
|
if s in self.ports:
|
|
|
# Ok, possibly?
|
|
|
sp = self.ports[s]
|
|
|
- if sp['port'] in ('Special', 'StarDock'):
|
|
|
+ if sp["port"] in ("Special", "StarDock"):
|
|
|
continue
|
|
|
if sp["port"][s_pos] == "S":
|
|
|
# Ok, they are selling!
|