|  | @@ -9,6 +9,7 @@ from twisted.internet.defer import gatherResults
 | 
	
		
			
				|  |  |  from itertools import cycle
 | 
	
		
			
				|  |  |  import pendulum
 | 
	
		
			
				|  |  |  from pprint import pformat
 | 
	
		
			
				|  |  | +from galaxy import GameData, PORT_CLASSES, CLASSES_PORT
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  class SpinningCursor(object):
 | 
	
		
			
				|  |  |      """ Spinner class, that handles every so many clicks 
 | 
	
	
		
			
				|  | @@ -156,7 +157,7 @@ class PlayerInput(object):
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def get_input(self, chunk):
 | 
	
		
			
				|  |  |          """ Data from player (in bytes) """
 | 
	
		
			
				|  |  | -        chunk = chunk.decode("utf-8", "ignore")
 | 
	
		
			
				|  |  | +        chunk = chunk.decode("latin-1", "ignore")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          for ch in chunk:
 | 
	
		
			
				|  |  |              if ch == "\b":
 | 
	
	
		
			
				|  | @@ -219,17 +220,6 @@ class PlayerInput(object):
 | 
	
		
			
				|  |  |          return line
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -PORT_CLASSES = {
 | 
	
		
			
				|  |  | -    1: "BBS",
 | 
	
		
			
				|  |  | -    2: "BSB",
 | 
	
		
			
				|  |  | -    3: "SBB",
 | 
	
		
			
				|  |  | -    4: "SSB",
 | 
	
		
			
				|  |  | -    5: "SBS",
 | 
	
		
			
				|  |  | -    6: "BSS",
 | 
	
		
			
				|  |  | -    7: "SSS",
 | 
	
		
			
				|  |  | -    8: "BBB",
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  | -CLASSES_PORT = {v: k for k, v in PORT_CLASSES.items()}
 | 
	
		
			
				|  |  |  import re
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  # The CIMWarpReport -- is only needed if the json file gets damaged in some way.
 | 
	
	
		
			
				|  | @@ -318,7 +308,7 @@ class CIMWarpReport(object):
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def player(self, chunk):
 | 
	
		
			
				|  |  |          """ Data from player (in bytes). """
 | 
	
		
			
				|  |  | -        chunk = chunk.decode("utf-8", "ignore")
 | 
	
		
			
				|  |  | +        chunk = chunk.decode("latin-1", "ignore")
 | 
	
		
			
				|  |  |          key = chunk.upper()
 | 
	
		
			
				|  |  |          log.msg("CIMWarpReport.player({0}) : I AM stopping...".format(key))
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -473,7 +463,7 @@ class CIMPortReport(object):
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def player(self, chunk):
 | 
	
		
			
				|  |  |          """ Data from player (in bytes). """
 | 
	
		
			
				|  |  | -        chunk = chunk.decode("utf-8", "ignore")
 | 
	
		
			
				|  |  | +        chunk = chunk.decode("latin-1", "ignore")
 | 
	
		
			
				|  |  |          key = chunk.upper()
 | 
	
		
			
				|  |  |          log.msg("CIMPortReport.player({0}) : I AM stopping...".format(key))
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -496,55 +486,6 @@ class CIMPortReport(object):
 | 
	
		
			
				|  |  |              self.observer.load(self.save)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -def port_burnt(port):
 | 
	
		
			
				|  |  | -    """ Is this port burned out? """
 | 
	
		
			
				|  |  | -    if all( x in port for x in ['fuel', 'org', 'equ']):
 | 
	
		
			
				|  |  | -        if all( 'pct' in port[x] for x in ['fuel', 'org', 'equ']):
 | 
	
		
			
				|  |  | -            if port['equ']['pct'] <= 20 or port['fuel']['pct'] <= 20 or port['org']['pct'] <= 20:
 | 
	
		
			
				|  |  | -                return True
 | 
	
		
			
				|  |  | -            return False
 | 
	
		
			
				|  |  | -    # Since we don't have any port information, hope for the best, assume it isn't burnt.
 | 
	
		
			
				|  |  | -    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]
 | 
	
		
			
				|  |  | -    # Any that are the same?  Remove them.
 | 
	
		
			
				|  |  | -    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
 | 
	
		
			
				|  |  | -    # Matching 2 of them.
 | 
	
		
			
				|  |  | -    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. 
 | 
	
		
			
				|  |  |      
 | 
	
	
		
			
				|  | @@ -629,10 +570,10 @@ class ScriptPort(object):
 | 
	
		
			
				|  |  |                  if self.sector2 is None:
 | 
	
		
			
				|  |  |                      # Ok, we need to prompt for this.
 | 
	
		
			
				|  |  |                      self.queue_game.put(self.r + self.nl + 
 | 
	
		
			
				|  |  | -                        "Which sector to trade with? {0}".format(port_show_part(self.this_sector, self.game.gamedata.ports[self.this_sector])) +
 | 
	
		
			
				|  |  | +                        "Which sector to trade with? {0}".format(GameData.port_show_part(self.this_sector, self.game.gamedata.ports[self.this_sector])) +
 | 
	
		
			
				|  |  |                          self.nl + Fore.CYAN)
 | 
	
		
			
				|  |  |                      for i, p in enumerate(self.possible):
 | 
	
		
			
				|  |  | -                        self.queue_game.put(" " + str(i + 1) + " : " + port_show_part(p, self.game.gamedata.ports[p]) + self.nl)
 | 
	
		
			
				|  |  | +                        self.queue_game.put(" " + str(i + 1) + " : " + GameData.port_show_part(p, self.game.gamedata.ports[p]) + self.nl)
 | 
	
		
			
				|  |  |                      
 | 
	
		
			
				|  |  |                      pi = PlayerInput(self.game)
 | 
	
		
			
				|  |  |                      def got_need1(*_):
 | 
	
	
		
			
				|  | @@ -667,7 +608,7 @@ class ScriptPort(object):
 | 
	
		
			
				|  |  |                          )
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                      self.queue_game.put(self.r + self.nl + "Trading {0}".format(
 | 
	
		
			
				|  |  | -                        port_show(self.this_sector, 
 | 
	
		
			
				|  |  | +                        GameData.port_show(self.this_sector, 
 | 
	
		
			
				|  |  |                              self.game.gamedata.ports[self.this_sector],
 | 
	
		
			
				|  |  |                              self.sector2, 
 | 
	
		
			
				|  |  |                              self.game.gamedata.ports[self.sector2])
 | 
	
	
		
			
				|  | @@ -881,7 +822,7 @@ class ScriptPort(object):
 | 
	
		
			
				|  |  |                      else:
 | 
	
		
			
				|  |  |                          # Ok, we are in the portdata
 | 
	
		
			
				|  |  |                          pd = self.game.gamedata.ports[self.this_sector]
 | 
	
		
			
				|  |  | -                        if port_burnt(pd):
 | 
	
		
			
				|  |  | +                        if GameData.port_burnt(pd):
 | 
	
		
			
				|  |  |                              log.msg("Current sector {0} port is burnt (<= 20%).".format(self.this_sector))
 | 
	
		
			
				|  |  |                              self.queue_game.put(self.r + self.nl + "Current sector port is burnt out. <= 20%." + self.nl)
 | 
	
		
			
				|  |  |                              self.deactivate()
 | 
	
	
		
			
				|  | @@ -904,7 +845,7 @@ class ScriptPort(object):
 | 
	
		
			
				|  |  |                          self.deactivate()
 | 
	
		
			
				|  |  |                          return
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    possible = [ x for x in possible if not port_burnt(self.game.gamedata.ports[x]) ]
 | 
	
		
			
				|  |  | +                    possible = [ x for x in possible if not GameData.port_burnt(self.game.gamedata.ports[x]) ]
 | 
	
		
			
				|  |  |                      log.msg("Possible:", possible)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                      if len(possible) == 0:
 | 
	
	
		
			
				|  | @@ -997,8 +938,13 @@ class ScriptPort(object):
 | 
	
		
			
				|  |  |                  self.state = 5
 | 
	
		
			
				|  |  |                  self.trade()    
 | 
	
		
			
				|  |  |              if "WHAT?!@!? you must be crazy!" in line:
 | 
	
		
			
				|  |  | +                log.msg("fix offer")
 | 
	
		
			
				|  |  |                  self.fix_offer = 1
 | 
	
		
			
				|  |  |              if "So, you think I'm as stupid as you look?" in line:
 | 
	
		
			
				|  |  | +                log.msg("fix offer")                
 | 
	
		
			
				|  |  | +                self.fix_offer = 1
 | 
	
		
			
				|  |  | +            if "Quit playing around, you're wasting my time!" in line:
 | 
	
		
			
				|  |  | +                log.msg("fix offer")                
 | 
	
		
			
				|  |  |                  self.fix_offer = 1
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          elif self.state == 8:
 | 
	
	
		
			
				|  | @@ -1030,35 +976,6 @@ class ScriptPort(object):
 | 
	
		
			
				|  |  |          #     self.deactivate()
 | 
	
		
			
				|  |  |          #     return
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -def color_pct(pct: int):
 | 
	
		
			
				|  |  | -    if pct > 50:
 | 
	
		
			
				|  |  | -        # green
 | 
	
		
			
				|  |  | -        return "{0}{1:3}{2}".format( Fore.GREEN, pct, Style.RESET_ALL)
 | 
	
		
			
				|  |  | -    elif pct > 25:
 | 
	
		
			
				|  |  | -        return "{0}{1:3}{2}".format( merge(Fore.YELLOW + Style.BRIGHT), pct, Style.RESET_ALL)
 | 
	
		
			
				|  |  | -    else:
 | 
	
		
			
				|  |  | -        return "{0:3}".format(pct)
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -def port_pct(port: dict):
 | 
	
		
			
				|  |  | -    # Make sure these exist in the port data given.
 | 
	
		
			
				|  |  | -    if all( x in port for x in ['fuel', 'org', 'equ']):
 | 
	
		
			
				|  |  | -        return "{0},{1},{2}%".format(
 | 
	
		
			
				|  |  | -            color_pct(port['fuel']['pct']),
 | 
	
		
			
				|  |  | -            color_pct(port['org']['pct']),
 | 
	
		
			
				|  |  | -            color_pct(port['equ']['pct']))
 | 
	
		
			
				|  |  | -    else:
 | 
	
		
			
				|  |  | -        return "---,---,---%"
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -def port_show_part(sector: int, sector_port: dict):
 | 
	
		
			
				|  |  | -    return "{0:5} ({1}) {2}".format(sector, sector_port['port'], port_pct(sector_port))
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -def port_show(sector: int, sector_port: dict, warp: int, warp_port: dict):
 | 
	
		
			
				|  |  | -    sector_pct = port_pct(sector_port)
 | 
	
		
			
				|  |  | -    warp_pct = port_pct(warp_port)
 | 
	
		
			
				|  |  | -    return "{0} -=- {1}".format(
 | 
	
		
			
				|  |  | -        port_show_part(sector, sector_port),
 | 
	
		
			
				|  |  | -        port_show_part(warp, warp_port)
 | 
	
		
			
				|  |  | -    )
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  class ProxyMenu(object):
 | 
	
		
			
				|  |  |      """ Display ProxyMenu 
 | 
	
	
		
			
				|  | @@ -1168,7 +1085,7 @@ class ProxyMenu(object):
 | 
	
		
			
				|  |  |          # for sector, pd in self.game.gamedata.ports.items():
 | 
	
		
			
				|  |  |          for sector in sorted(self.game.gamedata.ports.keys()):
 | 
	
		
			
				|  |  |              pd = self.game.gamedata.ports[sector]
 | 
	
		
			
				|  |  | -            if not port_burnt(pd):
 | 
	
		
			
				|  |  | +            if not GameData.port_burnt(pd):
 | 
	
		
			
				|  |  |                  pc = pd['class']
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  # Ok, let's look into it.
 | 
	
	
		
			
				|  | @@ -1181,7 +1098,7 @@ class ProxyMenu(object):
 | 
	
		
			
				|  |  |                      # (We can get back from it)
 | 
	
		
			
				|  |  |                      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 port_burnt(self.game.gamedata.ports[w]):
 | 
	
		
			
				|  |  | +                        if w > sector and w in self.game.gamedata.ports and not GameData.port_burnt(self.game.gamedata.ports[w]):
 | 
	
		
			
				|  |  |                              # it is > and has a port.
 | 
	
		
			
				|  |  |                              wd = self.game.gamedata.ports[w]
 | 
	
		
			
				|  |  |                              wc = wd['class']
 | 
	
	
		
			
				|  | @@ -1196,14 +1113,14 @@ class ProxyMenu(object):
 | 
	
		
			
				|  |  |                              # 8: "BBB",
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                              if pc in (1,5) and wc in (2,4):
 | 
	
		
			
				|  |  | -                                best_trades.append(port_show(sector, pd, w, wd))
 | 
	
		
			
				|  |  | +                                best_trades.append(self.game.gamedata.port_trade_show(sector, w))
 | 
	
		
			
				|  |  |                                  # best_trades.append( "{0:5} -=- {1:5}".format(sector, w))
 | 
	
		
			
				|  |  |                              elif pc in (2,4) and wc in (1,5):
 | 
	
		
			
				|  |  | -                                best_trades.append(port_show(sector, pd, w, wd))
 | 
	
		
			
				|  |  | +                                best_trades.append(self.game.gamedata.port_trade_show(sector, w))
 | 
	
		
			
				|  |  |                                  # best_trades.append( "{0:5} -=- {1:5}".format(sector, w))
 | 
	
		
			
				|  |  | -                            elif port_trading(pd['port'], self.game.gamedata.ports[w]['port']):
 | 
	
		
			
				|  |  | +                            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(port_show(sector, pd, w, wd))
 | 
	
		
			
				|  |  | +                                ok_trades.append(GameData.port_show(sector, pd, w, wd))
 | 
	
		
			
				|  |  |              yield
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          self.trade_report.append("Best Trades: (org/equ)")
 | 
	
	
		
			
				|  | @@ -1221,7 +1138,7 @@ class ProxyMenu(object):
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def player(self, chunk: bytes):
 | 
	
		
			
				|  |  |          """ Data from player (in bytes). """
 | 
	
		
			
				|  |  | -        chunk = chunk.decode("utf-8", "ignore")
 | 
	
		
			
				|  |  | +        chunk = chunk.decode("latin-1", "ignore")
 | 
	
		
			
				|  |  |          key = chunk.upper()
 | 
	
		
			
				|  |  |          log.msg("ProxyMenu.player({0})".format(key))
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -1373,7 +1290,7 @@ class ProxyMenu(object):
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def scripts_player(self, chunk: bytes):
 | 
	
		
			
				|  |  |          """ Data from player (in bytes). """
 | 
	
		
			
				|  |  | -        chunk = chunk.decode("utf-8", "ignore")
 | 
	
		
			
				|  |  | +        chunk = chunk.decode("latin-1", "ignore")
 | 
	
		
			
				|  |  |          key = chunk.upper()
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  |          if key == '1':
 |