Update analyzer.py and commander.py
This commit is contained in:
parent
27bd054e8b
commit
5fbce54285
@ -44,14 +44,21 @@ class Analyzer:
|
||||
location = self.store.get(Waypoint, location)
|
||||
mkts = self.find_markets(resource, sellbuy)
|
||||
candidates = []
|
||||
origin = self.store.get(System, location.system())
|
||||
for typ, m in mkts:
|
||||
system = self.store.get(System, m.system())
|
||||
origin = self.store.get(System, location.system())
|
||||
d = origin.distance(system)
|
||||
candidates.append((typ, m, d))
|
||||
possibles = sorted(candidates, key=lambda m: m[2])
|
||||
possibles = possibles[:10]
|
||||
results = []
|
||||
for typ,m,d in possibles:
|
||||
system = self.store.get(System, m.system())
|
||||
p = self.find_path(origin, system)
|
||||
if p is None: continue
|
||||
candidates.append((typ, m, len(p)))
|
||||
result = sorted(candidates, key=lambda m: m[2])
|
||||
return result[:10]
|
||||
results.append((typ,m,d,len(p)))
|
||||
return results
|
||||
|
||||
|
||||
|
||||
def get_jumpgate(self, system):
|
||||
|
@ -138,12 +138,13 @@ class Commander(CommandLine):
|
||||
raise CommandError('no delivery')
|
||||
resource = delivery['trade_symbol']
|
||||
destination = delivery['destination']
|
||||
m = self.analyzer.find_closest_market(resource, 'buy', destination)
|
||||
if m is None:
|
||||
m = self.analyzer.find_closest_market(resource, 'exchange', destination)
|
||||
if m is None:
|
||||
m = self.analyzer.find_closest_markets(resource, 'buy', destination)
|
||||
if len(m) is None:
|
||||
m = self.analyzer.find_closest_markets(resource, 'exchange', destination)
|
||||
if len(m) is None:
|
||||
print('no market found')
|
||||
return
|
||||
_, m, _, _ = m[0]
|
||||
site = self.store.get(Waypoint, m.symbol)
|
||||
self.set_mission('haul')
|
||||
self.centcom.set_mission_param(self.ship, 'site', site.symbol)
|
||||
@ -222,7 +223,7 @@ class Commander(CommandLine):
|
||||
location = self.ship.location()
|
||||
resource = input('what resource?').upper()
|
||||
print('Found markets:')
|
||||
for typ, m, plen in self.analyzer.find_closest_markets(resource, 'buy,exchange',location):
|
||||
for typ, m, d, plen in self.analyzer.find_closest_markets(resource, 'buy,exchange',location):
|
||||
print(m, typ[0], f'{plen-1} hops')
|
||||
|
||||
def do_path(self):
|
||||
|
Loading…
Reference in New Issue
Block a user