mission and cli improvements
This commit is contained in:
parent
6118772a63
commit
b47fa44cb0
@ -32,7 +32,7 @@ class Api:
|
|||||||
try:
|
try:
|
||||||
return self.request_once(method, path, data, need_token, params)
|
return self.request_once(method, path, data, need_token, params)
|
||||||
except (ApiLimitError, requests.exceptions.Timeout):
|
except (ApiLimitError, requests.exceptions.Timeout):
|
||||||
print('oops, hit the limit. take a break')
|
# print('oops, hit the limit. take a break')
|
||||||
sleep(10)
|
sleep(10)
|
||||||
return self.request_once(method, path, data, need_token, params)
|
return self.request_once(method, path, data, need_token, params)
|
||||||
|
|
||||||
@ -90,8 +90,8 @@ class Api:
|
|||||||
def list_waypoints(self, system):
|
def list_waypoints(self, system):
|
||||||
data = self.request('get', f'systems/{system}/waypoints/')
|
data = self.request('get', f'systems/{system}/waypoints/')
|
||||||
tp = total_pages(self.last_meta)
|
tp = total_pages(self.last_meta)
|
||||||
for p in range(1, tp):
|
for p in range(tp):
|
||||||
data += self.request('get', f'systems/{system}/waypoints/', params={'page': p})
|
data += self.request('get', f'systems/{system}/waypoints/', params={'page': p+1})
|
||||||
# pprint(data)
|
# pprint(data)
|
||||||
return self.store.update_list(Waypoint, data)
|
return self.store.update_list(Waypoint, data)
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@ class AtlasBuilder:
|
|||||||
self.atlas = self.store.get(Atlas, 'ATLAS', create=True)
|
self.atlas = self.store.get(Atlas, 'ATLAS', create=True)
|
||||||
|
|
||||||
def find_work(self):
|
def find_work(self):
|
||||||
|
if not self.atlas.enabled:
|
||||||
|
return
|
||||||
first_page = self.atlas.total_pages == 0
|
first_page = self.atlas.total_pages == 0
|
||||||
pages_left = self.atlas.total_pages > self.atlas.seen_pages
|
pages_left = self.atlas.total_pages > self.atlas.seen_pages
|
||||||
|
|
||||||
@ -63,10 +65,10 @@ class AtlasBuilder:
|
|||||||
if 'UNCHARTED' in w.traits:
|
if 'UNCHARTED' in w.traits:
|
||||||
continue
|
continue
|
||||||
if 'MARKETPLACE' in w.traits:
|
if 'MARKETPLACE' in w.traits:
|
||||||
print(f'marketplace at {w}')
|
#print(f'marketplace at {w}')
|
||||||
self.sched(self.api.marketplace, w)
|
self.sched(self.api.marketplace, w)
|
||||||
if w.type == 'JUMP_GATE':
|
if w.type == 'JUMP_GATE':
|
||||||
print(f'jumpgate at {w}')
|
#print(f'jumpgate at {w}')
|
||||||
self.sched(self.api.jumps, w)
|
self.sched(self.api.jumps, w)
|
||||||
if 'SHIPYARD' in w.traits:
|
if 'SHIPYARD' in w.traits:
|
||||||
# todo
|
# todo
|
||||||
|
@ -10,6 +10,8 @@ from threading import Thread
|
|||||||
from nullptr.central_command import CentralCommand
|
from nullptr.central_command import CentralCommand
|
||||||
import readline
|
import readline
|
||||||
import os
|
import os
|
||||||
|
from copy import copy
|
||||||
|
|
||||||
|
|
||||||
class CommandError(Exception):
|
class CommandError(Exception):
|
||||||
pass
|
pass
|
||||||
@ -80,7 +82,9 @@ class Commander(CommandLine):
|
|||||||
print('=== contracts')
|
print('=== contracts')
|
||||||
self.do_contracts('r')
|
self.do_contracts('r')
|
||||||
ship = self.store.get(Ship, symbol.upper() + '-2')
|
ship = self.store.get(Ship, symbol.upper() + '-2')
|
||||||
api.list_waypoints(ship.location.system)
|
print("=== catalog initial system")
|
||||||
|
self.do_catalog(ship.location.system)
|
||||||
|
self.do_stats()
|
||||||
self.store.flush()
|
self.store.flush()
|
||||||
return agent
|
return agent
|
||||||
|
|
||||||
@ -93,7 +97,17 @@ class Commander(CommandLine):
|
|||||||
raise CommandError('multiple matches')
|
raise CommandError('multiple matches')
|
||||||
else:
|
else:
|
||||||
raise CommandError('not found')
|
raise CommandError('not found')
|
||||||
|
|
||||||
|
def resolve_system(self, system_str):
|
||||||
|
if type(system_str) == System:
|
||||||
|
return system_str
|
||||||
|
if system_str == '':
|
||||||
|
if not self.has_ship(): return
|
||||||
|
system = self.ship.location.system
|
||||||
|
else:
|
||||||
|
system = self.store.get(System, system_str)
|
||||||
|
return system
|
||||||
|
|
||||||
def after_cmd(self):
|
def after_cmd(self):
|
||||||
self.store.flush()
|
self.store.flush()
|
||||||
|
|
||||||
@ -179,7 +193,7 @@ class Commander(CommandLine):
|
|||||||
resource = delivery['trade_symbol']
|
resource = delivery['trade_symbol']
|
||||||
destination = delivery['destination']
|
destination = delivery['destination']
|
||||||
m = self.analyzer.find_closest_markets(resource, 'buy,exchange', destination)
|
m = self.analyzer.find_closest_markets(resource, 'buy,exchange', destination)
|
||||||
if len(m) is None:
|
if len(m) == 0:
|
||||||
print('no market found')
|
print('no market found')
|
||||||
return
|
return
|
||||||
markets = [ mkt[1] for mkt in m]
|
markets = [ mkt[1] for mkt in m]
|
||||||
@ -188,6 +202,16 @@ class Commander(CommandLine):
|
|||||||
self.centcom.set_mission_param(self.ship, 'hops', markets)
|
self.centcom.set_mission_param(self.ship, 'hops', markets)
|
||||||
self.print_mission()
|
self.print_mission()
|
||||||
|
|
||||||
|
def do_sprobe(self):
|
||||||
|
if not self.has_ship(): return
|
||||||
|
system = self.ship.location.system
|
||||||
|
m = self.store.all_members(system, 'Marketplace')
|
||||||
|
m = self.analyzer.solve_tsp(m)
|
||||||
|
hops = [w.symbol for w in m]
|
||||||
|
self.centcom.init_mission(self.ship, 'probe')
|
||||||
|
self.centcom.set_mission_param(self.ship, 'hops', hops)
|
||||||
|
self.print_mission()
|
||||||
|
|
||||||
def do_travel(self, dest):
|
def do_travel(self, dest):
|
||||||
dest = self.resolve('Waypoint', dest)
|
dest = self.resolve('Waypoint', dest)
|
||||||
self.centcom.init_mission(self.ship, 'travel')
|
self.centcom.init_mission(self.ship, 'travel')
|
||||||
@ -213,7 +237,17 @@ class Commander(CommandLine):
|
|||||||
|
|
||||||
def do_defrag(self):
|
def do_defrag(self):
|
||||||
self.store.defrag()
|
self.store.defrag()
|
||||||
|
|
||||||
|
def do_catalog(self, system_str=''):
|
||||||
|
system = self.resolve_system(system_str)
|
||||||
|
r = self.api.list_waypoints(system)
|
||||||
|
for w in r:
|
||||||
|
if 'MARKETPLACE' in w.traits:
|
||||||
|
self.api.marketplace(w)
|
||||||
|
if w.type == 'JUMP_GATE':
|
||||||
|
self.api.jumps(w)
|
||||||
|
|
||||||
|
|
||||||
def do_system(self, system_str):
|
def do_system(self, system_str):
|
||||||
system = self.store.get(System, system_str)
|
system = self.store.get(System, system_str)
|
||||||
r = self.api.list_waypoints(system)
|
r = self.api.list_waypoints(system)
|
||||||
@ -256,6 +290,11 @@ class Commander(CommandLine):
|
|||||||
continue
|
continue
|
||||||
print(f'{wname:4} {typ} {traits}')
|
print(f'{wname:4} {typ} {traits}')
|
||||||
|
|
||||||
|
def do_members(self):
|
||||||
|
if not self.has_ship(): return
|
||||||
|
system = self.ship.location.system
|
||||||
|
pprint(list(self.store.all_members(system)))
|
||||||
|
|
||||||
def do_wp(self, s=''):
|
def do_wp(self, s=''):
|
||||||
self.do_waypoints(s)
|
self.do_waypoints(s)
|
||||||
|
|
||||||
@ -263,8 +302,10 @@ class Commander(CommandLine):
|
|||||||
waypoint = self.store.get(Waypoint, waypoint_str.upper())
|
waypoint = self.store.get(Waypoint, waypoint_str.upper())
|
||||||
r = self.api.marketplace(waypoint)
|
r = self.api.marketplace(waypoint)
|
||||||
|
|
||||||
def do_atlas(self):
|
def do_atlas(self, state=None):
|
||||||
atlas = self.store.get(Atlas, 'ATLAS')
|
atlas = self.store.get(Atlas, 'ATLAS')
|
||||||
|
if state is not None:
|
||||||
|
atlas.enabled = True if state == 'on' else 'off'
|
||||||
pprint(atlas, 5)
|
pprint(atlas, 5)
|
||||||
|
|
||||||
def do_jumps(self, waypoint_str=None):
|
def do_jumps(self, waypoint_str=None):
|
||||||
@ -395,8 +436,27 @@ class Commander(CommandLine):
|
|||||||
else:
|
else:
|
||||||
waypoint = self.resolve('Waypoint', arg)
|
waypoint = self.resolve('Waypoint', arg)
|
||||||
r = self.api.marketplace(waypoint)
|
r = self.api.marketplace(waypoint)
|
||||||
pprint(r)
|
pprint(r, 3)
|
||||||
|
|
||||||
|
def do_prices(self, resource=None):
|
||||||
|
if not self.has_ship(): return
|
||||||
|
system = self.ship.location.system
|
||||||
|
prices = {}
|
||||||
|
for m in self.store.all_members(system, Marketplace):
|
||||||
|
for p in m.prices.values():
|
||||||
|
r = p['symbol']
|
||||||
|
if not r in prices:
|
||||||
|
prices[r] = []
|
||||||
|
prices[r].append({
|
||||||
|
'wp': m.symbol,
|
||||||
|
'buy': p['buy'],
|
||||||
|
'sell': p['sell']
|
||||||
|
})
|
||||||
|
if resource is not None:
|
||||||
|
pprint(prices[resource.upper()])
|
||||||
|
else:
|
||||||
|
pprint(prices)
|
||||||
|
|
||||||
def do_cargo(self):
|
def do_cargo(self):
|
||||||
if not self.has_ship(): return
|
if not self.has_ship(): return
|
||||||
print(f'== Cargo {self.ship.cargo_units}/{self.ship.cargo_capacity} ==')
|
print(f'== Cargo {self.ship.cargo_units}/{self.ship.cargo_capacity} ==')
|
||||||
|
@ -148,10 +148,10 @@ class BaseMission(Mission):
|
|||||||
self.next_step = self.ship.arrival
|
self.next_step = self.ship.arrival
|
||||||
|
|
||||||
def step_unload(self):
|
def step_unload(self):
|
||||||
contract = self.rst(Contract, 'contract')
|
|
||||||
delivery = self.st('delivery')
|
delivery = self.st('delivery')
|
||||||
if delivery == 'sell':
|
if delivery == 'sell':
|
||||||
return self.step_sell(False)
|
return self.step_sell(False)
|
||||||
|
contract = self.rst(Contract, 'contract')
|
||||||
typs = self.ship.deliverable_cargo(contract)
|
typs = self.ship.deliverable_cargo(contract)
|
||||||
if len(typs) == 0:
|
if len(typs) == 0:
|
||||||
return 'done'
|
return 'done'
|
||||||
@ -206,6 +206,7 @@ class BaseMission(Mission):
|
|||||||
dest = self.store.get(Waypoint, dest)
|
dest = self.store.get(Waypoint, dest)
|
||||||
loc = self.ship.location
|
loc = self.ship.location
|
||||||
loc_sys = loc.system
|
loc_sys = loc.system
|
||||||
|
|
||||||
loc_jg = self.analyzer.get_jumpgate(loc_sys)
|
loc_jg = self.analyzer.get_jumpgate(loc_sys)
|
||||||
loc_jg_wp = self.store.get(Waypoint, loc_jg.symbol)
|
loc_jg_wp = self.store.get(Waypoint, loc_jg.symbol)
|
||||||
dest_sys = dest.system
|
dest_sys = dest.system
|
||||||
|
@ -8,9 +8,12 @@ class Atlas(Base):
|
|||||||
def define(self):
|
def define(self):
|
||||||
self.total_pages = 0
|
self.total_pages = 0
|
||||||
self.seen_pages = 0
|
self.seen_pages = 0
|
||||||
|
self.enabled = False
|
||||||
|
|
||||||
def f(self, detail=1):
|
def f(self, detail=1):
|
||||||
r = super().f(detail)
|
r = super().f(detail)
|
||||||
if detail >2:
|
if detail >2:
|
||||||
|
if not self.enabled:
|
||||||
|
r += ' OFF'
|
||||||
r += f' {self.seen_pages}/{self.total_pages}'
|
r += f' {self.seen_pages}/{self.total_pages}'
|
||||||
return r
|
return r
|
||||||
|
@ -16,8 +16,8 @@ class Jumpgate(Base):
|
|||||||
return 'jmp'
|
return 'jmp'
|
||||||
|
|
||||||
def f(self, detail=1):
|
def f(self, detail=1):
|
||||||
r = self.symbol
|
r = super().f(detail)
|
||||||
if detail > 1:
|
if detail > 2:
|
||||||
r += '\n'
|
r += '\n'
|
||||||
r += '\n'.join([s.symbol for s in self.connections])
|
r += '\n'.join([s.symbol for s in self.connections])
|
||||||
return r
|
return r
|
||||||
|
@ -53,8 +53,8 @@ class Marketplace(Base):
|
|||||||
return '?'
|
return '?'
|
||||||
|
|
||||||
def f(self, detail=1):
|
def f(self, detail=1):
|
||||||
r = self.symbol
|
r = super().f(detail)
|
||||||
if detail > 1:
|
if detail > 2:
|
||||||
r += '\n'
|
r += '\n'
|
||||||
if len(self.imports) > 0:
|
if len(self.imports) > 0:
|
||||||
r += 'I: ' + ', '.join(self.imports) + '\n'
|
r += 'I: ' + ', '.join(self.imports) + '\n'
|
||||||
|
Loading…
Reference in New Issue
Block a user