|
@@ -466,10 +466,50 @@ class CIMPortReport(object):
|
|
|
|
|
|
|
|
|
def port_burnt(port):
|
|
|
+ """ Is this port burned out? """
|
|
|
if port['equ']['pct'] <= 20 or port['fuel']['pct'] <= 20 or port['org']['pct'] <= 20:
|
|
|
return True
|
|
|
return False
|
|
|
|
|
|
+def flip(port):
|
|
|
+ return port.replace('S', 'W').replace('B', 'S').replace('W', 'B')
|
|
|
+
|
|
|
+def port_trading(port1, port2):
|
|
|
+ """ Are there possible trades at these ports? """
|
|
|
+ if port1 == port2:
|
|
|
+ return False
|
|
|
+ p1 = [ c for c in port1]
|
|
|
+ p2 = [ c for c in port2]
|
|
|
+
|
|
|
+ rem = False
|
|
|
+ for i in range(3):
|
|
|
+ if p1[i] == p2[i]:
|
|
|
+ p1[i] = 'X'
|
|
|
+ p2[i] = 'X'
|
|
|
+ rem = True
|
|
|
+ if rem:
|
|
|
+ j1 = "".join(p1).replace('X', '')
|
|
|
+ j2 = "".join(p2).replace('X', '')
|
|
|
+ if j1 == 'BS' and j2 == 'SB':
|
|
|
+ return True
|
|
|
+ if j1 == 'SB' and j2 == 'BS':
|
|
|
+ return True
|
|
|
+
|
|
|
+ rport1 = flip(port1)
|
|
|
+ c = 0
|
|
|
+ match = []
|
|
|
+ for i in range(3):
|
|
|
+ if rport1[i] == port2[i]:
|
|
|
+ match.append(port2[i])
|
|
|
+ c += 1
|
|
|
+ if c > 1:
|
|
|
+ f = flip(match.pop(0))
|
|
|
+ if f in match:
|
|
|
+ return True
|
|
|
+ return False
|
|
|
+ return False
|
|
|
+
|
|
|
+
|
|
|
class ScriptPort(object):
|
|
|
""" Performs the Port script.
|
|
|
|
|
@@ -750,7 +790,7 @@ class ScriptPort(object):
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
if hasattr(self.game, 'warpdata'):
|
|
|
|
|
|
possible = [ x for x in possible if self.this_sector in self.game.warpdata[x]]
|
|
@@ -763,12 +803,21 @@ class ScriptPort(object):
|
|
|
|
|
|
possible = [ x for x in possible if not port_burnt(self.game.portdata[x]) ]
|
|
|
log.msg("Possible:", possible)
|
|
|
- self.possible = possible
|
|
|
+
|
|
|
if len(possible) == 0:
|
|
|
self.state = 0
|
|
|
self.queue_game.put(self.r + self.nl + "I don't see any unburnt ports in [{0}].".format(self.warps) + self.nl)
|
|
|
self.deactivate()
|
|
|
return
|
|
|
+
|
|
|
+ possible = [ x for x in possible if port_trading(self.game.portdata[self.this_sector]['port'], self.game.portdata[x]['port'])]
|
|
|
+ self.possible = possible
|
|
|
+
|
|
|
+ if len(possible) == 0:
|
|
|
+ self.state = 0
|
|
|
+ self.queue_game.put(self.r + self.nl + "I don't see any possible port trades in [{0}].".format(self.warps) + self.nl)
|
|
|
+ self.deactivate()
|
|
|
+ return
|
|
|
elif len(possible) == 1:
|
|
|
|
|
|
self.sector2 = possible[0]
|
|
@@ -961,41 +1010,53 @@ class ProxyMenu(object):
|
|
|
|
|
|
if key == "T":
|
|
|
self.queue_game.put(self.c + key + self.r + self.nl)
|
|
|
-
|
|
|
- ok_trades = []
|
|
|
- best_trades = []
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- for sector, pd in self.game.portdata.items():
|
|
|
- if not port_burnt(pd):
|
|
|
- pc = pd['class']
|
|
|
-
|
|
|
-
|
|
|
- warps = self.game.warpdata[sector]
|
|
|
- for w in warps:
|
|
|
-
|
|
|
-
|
|
|
- if w in self.game.warpdata and sector in self.game.warpdata[w]:
|
|
|
-
|
|
|
- if w > sector and w in self.game.portdata and not port_burnt(self.game.portdata[w]):
|
|
|
-
|
|
|
- wc = self.game.portdata[w]['class']
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if pc in (1,5) and wc in (2,4):
|
|
|
- best_trades.append( "{0} -=- {1}".format(sector, w))
|
|
|
- elif pc in (2,4) and wc in (1,5):
|
|
|
- best_trades.append( "{0} -=- {1}".format(sector, w))
|
|
|
- self.queue_game.put("BEST TRADES:" + self.nl + self.nl.join(best_trades) + self.nl)
|
|
|
+
|
|
|
+ if not hasattr(self.game, 'portdata') or not hasattr(self.game, 'warpdata'):
|
|
|
+ self.queue_game.put("Missing portdata/warpdata." + self.nl)
|
|
|
+ else:
|
|
|
+
|
|
|
+ ok_trades = []
|
|
|
+ best_trades = []
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for sector, pd in self.game.portdata.items():
|
|
|
+ if not port_burnt(pd):
|
|
|
+ pc = pd['class']
|
|
|
+
|
|
|
+
|
|
|
+ if not sector in self.game.warpdata:
|
|
|
+ continue
|
|
|
+
|
|
|
+ warps = self.game.warpdata[sector]
|
|
|
+ for w in warps:
|
|
|
+
|
|
|
+
|
|
|
+ if w in self.game.warpdata and sector in self.game.warpdata[w]:
|
|
|
+
|
|
|
+ if w > sector and w in self.game.portdata and not port_burnt(self.game.portdata[w]):
|
|
|
+
|
|
|
+ wc = self.game.portdata[w]['class']
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if pc in (1,5) and wc in (2,4):
|
|
|
+ best_trades.append( "{0:5} -=- {1:5}".format(sector, w))
|
|
|
+ elif pc in (2,4) and wc in (1,5):
|
|
|
+ best_trades.append( "{0:5} -=- {1:5}".format(sector, w))
|
|
|
+ elif port_trading(pd['port'], self.game.portdata[w]['port']):
|
|
|
+ ok_trades.append( "{0:5} -=- {1:5}".format(sector,w))
|
|
|
+
|
|
|
+ self.queue_game.put("BEST TRADES:" + self.nl + self.nl.join(best_trades) + self.nl)
|
|
|
+ self.queue_game.put("OK TRADES:" + self.nl + self.nl.join(ok_trades) + self.nl)
|
|
|
+
|
|
|
|
|
|
elif key == "P":
|
|
|
self.queue_game.put(self.c + key + self.r + self.nl)
|