2023-06-11 18:51:03 +00:00
|
|
|
from nullptr.command_line import CommandLine
|
|
|
|
from nullptr.store import Store
|
2024-02-09 14:52:30 +00:00
|
|
|
from nullptr.analyzer import *
|
|
|
|
from nullptr.context import Context
|
2023-06-11 18:51:03 +00:00
|
|
|
import argparse
|
2024-01-09 19:07:27 +00:00
|
|
|
from nullptr.models import *
|
2023-06-11 18:51:03 +00:00
|
|
|
from nullptr.api import Api
|
|
|
|
from .util import *
|
2023-06-12 12:41:27 +00:00
|
|
|
from time import sleep, time
|
2023-06-11 18:51:03 +00:00
|
|
|
from threading import Thread
|
2024-02-09 14:52:30 +00:00
|
|
|
from nullptr.captain import Captain
|
|
|
|
from nullptr.general import General
|
2023-12-25 07:05:18 +00:00
|
|
|
import readline
|
|
|
|
import os
|
2024-01-02 05:35:26 +00:00
|
|
|
from copy import copy
|
2024-01-09 19:07:27 +00:00
|
|
|
|
2023-07-16 16:48:45 +00:00
|
|
|
|
2024-02-09 14:52:30 +00:00
|
|
|
class CommandError(AppError):
|
2023-06-16 12:41:11 +00:00
|
|
|
pass
|
|
|
|
|
2023-06-11 18:51:03 +00:00
|
|
|
class Commander(CommandLine):
|
2024-02-11 13:37:46 +00:00
|
|
|
def __init__(self, data_dir='data', auto=False):
|
2024-01-04 20:34:31 +00:00
|
|
|
store_file = os.path.join(data_dir, 'store.npt')
|
|
|
|
hist_file = os.path.join(data_dir, 'cmd.hst')
|
2024-01-13 20:42:49 +00:00
|
|
|
self.cred_file = os.path.join(data_dir, 'creds.txt')
|
2023-12-25 07:05:18 +00:00
|
|
|
self.hist_file = hist_file
|
|
|
|
if os.path.isfile(hist_file):
|
|
|
|
readline.read_history_file(hist_file)
|
2024-01-27 14:05:33 +00:00
|
|
|
self.store = Store(store_file, True)
|
2024-02-09 14:52:30 +00:00
|
|
|
self.c = Context(self.store)
|
2023-06-15 19:10:33 +00:00
|
|
|
self.agent = self.select_agent()
|
2024-02-09 14:52:30 +00:00
|
|
|
self.c.api = self.api = Api(self.c, self.agent)
|
|
|
|
self.c.general = self.general = General(self.c)
|
|
|
|
self.c.captain = self.captain = Captain(self.c)
|
|
|
|
|
|
|
|
self.general.setup()
|
|
|
|
self.captain.setup()
|
|
|
|
|
2024-02-01 17:51:27 +00:00
|
|
|
self.api.info()
|
2024-02-09 14:52:30 +00:00
|
|
|
|
2023-06-15 20:37:33 +00:00
|
|
|
self.ship = None
|
2023-06-12 21:13:40 +00:00
|
|
|
|
2024-02-09 14:52:30 +00:00
|
|
|
self.stop_auto = False
|
2024-02-11 13:37:46 +00:00
|
|
|
if auto:
|
|
|
|
self.do_auto()
|
2023-06-11 18:51:03 +00:00
|
|
|
super().__init__()
|
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
######## INFRA #########
|
2023-12-25 06:53:38 +00:00
|
|
|
def handle_eof(self):
|
|
|
|
self.store.close()
|
2023-12-25 07:05:18 +00:00
|
|
|
readline.write_history_file(self.hist_file)
|
2023-12-25 06:53:38 +00:00
|
|
|
print("Goodbye!")
|
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
def do_pp(self):
|
|
|
|
pprint(self.api.last_result)
|
|
|
|
|
2023-06-15 20:37:33 +00:00
|
|
|
def prompt(self):
|
|
|
|
if self.ship:
|
|
|
|
return f'{self.ship.symbol}> '
|
|
|
|
else:
|
|
|
|
return '> '
|
2024-01-09 19:07:27 +00:00
|
|
|
|
|
|
|
def after_cmd(self):
|
|
|
|
self.store.flush()
|
|
|
|
|
|
|
|
def do_auto(self):
|
2024-02-09 14:52:30 +00:00
|
|
|
self.captain.run_interactive()
|
2024-01-16 18:13:10 +00:00
|
|
|
|
|
|
|
def do_log(self, level):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
ship._log_level = int(level)
|
2024-01-16 18:13:10 +00:00
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
######## Resolvers #########
|
2023-06-13 07:27:13 +00:00
|
|
|
def ask_obj(self, typ, prompt):
|
|
|
|
obj = None
|
|
|
|
while obj is None:
|
2023-06-18 17:15:51 +00:00
|
|
|
symbol = input(prompt).strip()
|
2023-06-13 07:27:13 +00:00
|
|
|
obj = self.store.get(typ, symbol.upper())
|
|
|
|
if obj is None:
|
|
|
|
print('not found')
|
|
|
|
return obj
|
2024-01-09 19:07:27 +00:00
|
|
|
|
|
|
|
def has_ship(self):
|
|
|
|
if self.ship is not None:
|
2024-01-24 18:03:57 +00:00
|
|
|
return self.ship
|
2024-01-09 19:07:27 +00:00
|
|
|
else:
|
2024-01-24 18:03:57 +00:00
|
|
|
raise CommandError('set a ship')
|
2024-01-09 19:07:27 +00:00
|
|
|
|
2023-06-15 19:10:33 +00:00
|
|
|
def select_agent(self):
|
|
|
|
agents = self.store.all(Agent)
|
|
|
|
agent = next(agents, None)
|
|
|
|
if agent is None:
|
2023-07-11 20:09:57 +00:00
|
|
|
agent = self.agent_setup()
|
|
|
|
return agent
|
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
def resolve(self, typ, arg):
|
|
|
|
arg = arg.upper()
|
|
|
|
matches = [c for c in self.store.all(typ) if c.symbol.startswith(arg)]
|
|
|
|
if len(matches) == 1:
|
|
|
|
return matches[0]
|
|
|
|
elif len(matches) > 1:
|
|
|
|
raise CommandError('multiple matches')
|
|
|
|
else:
|
2024-01-15 18:39:08 +00:00
|
|
|
raise CommandError(f'{arg} not found')
|
2024-01-09 19:07:27 +00:00
|
|
|
|
|
|
|
def resolve_system(self, system_str):
|
|
|
|
if type(system_str) == System:
|
|
|
|
return system_str
|
|
|
|
if system_str == '':
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
system = ship.location.system
|
2024-01-09 19:07:27 +00:00
|
|
|
else:
|
|
|
|
system = self.store.get(System, system_str)
|
|
|
|
return system
|
|
|
|
|
2024-01-15 18:39:08 +00:00
|
|
|
def resolve_waypoint(self, w):
|
|
|
|
if type(w) == Waypoint:
|
|
|
|
return w
|
|
|
|
if w == '':
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
return ship.location
|
2024-01-15 18:39:08 +00:00
|
|
|
p = w.split('-')
|
|
|
|
if len(p) == 1:
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
s = ship.location.system
|
2024-01-15 18:39:08 +00:00
|
|
|
w = f'{s}-{w}'
|
2024-01-16 18:13:10 +00:00
|
|
|
r = self.store.get(Waypoint, w)
|
|
|
|
if r is None:
|
|
|
|
raise CommandError(f'{w} not found')
|
|
|
|
return r
|
2024-01-15 18:39:08 +00:00
|
|
|
|
2024-01-20 19:33:50 +00:00
|
|
|
def resolve_ship(self, arg):
|
|
|
|
symbol = f'{self.agent.symbol}-{arg}'
|
|
|
|
ship = self.store.get('Ship', symbol)
|
|
|
|
if ship is None:
|
|
|
|
raise CommandError(f'ship {arg} not found')
|
|
|
|
return ship
|
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
######## First run #########
|
2023-07-11 20:09:57 +00:00
|
|
|
def agent_setup(self):
|
|
|
|
symbol = input('agent name: ')
|
|
|
|
agent = self.store.get(Agent, symbol, create=True)
|
2023-07-16 19:01:00 +00:00
|
|
|
self.agent = agent
|
2024-02-10 18:29:11 +00:00
|
|
|
api = Api(self.c, agent)
|
2023-07-11 20:09:57 +00:00
|
|
|
self.api = api
|
2023-12-28 18:49:00 +00:00
|
|
|
faction = input('faction or token: ')
|
|
|
|
if len(faction) > 50:
|
|
|
|
self.agent.token = faction
|
|
|
|
else:
|
2024-01-13 20:42:49 +00:00
|
|
|
self.do_register(faction)
|
2023-07-11 20:09:57 +00:00
|
|
|
print('=== agent:')
|
|
|
|
print(agent)
|
|
|
|
print('=== ships')
|
|
|
|
self.do_ships('r')
|
2024-02-01 17:51:27 +00:00
|
|
|
|
2023-07-11 20:09:57 +00:00
|
|
|
print('=== contracts')
|
|
|
|
self.do_contracts('r')
|
2023-07-16 19:01:00 +00:00
|
|
|
ship = self.store.get(Ship, symbol.upper() + '-2')
|
2024-01-02 05:35:26 +00:00
|
|
|
print("=== catalog initial system")
|
|
|
|
self.do_catalog(ship.location.system)
|
|
|
|
self.do_stats()
|
2023-07-11 20:09:57 +00:00
|
|
|
self.store.flush()
|
2023-06-15 19:10:33 +00:00
|
|
|
return agent
|
2023-06-16 12:41:11 +00:00
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
def do_token(self):
|
|
|
|
print(self.agent.token)
|
2024-01-02 05:35:26 +00:00
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
def do_register(self, faction):
|
|
|
|
self.api.register(faction.upper())
|
2024-01-13 20:42:49 +00:00
|
|
|
with open(self.cred_file, 'w') as f:
|
|
|
|
f.write(self.api.agent.symbol)
|
|
|
|
f.write('\n')
|
|
|
|
f.write(self.api.agent.token)
|
2024-01-09 19:07:27 +00:00
|
|
|
pprint(self.api.agent)
|
|
|
|
|
2024-01-27 14:05:33 +00:00
|
|
|
def do_reset(self, really):
|
|
|
|
if really != 'yes':
|
|
|
|
print('really? type: reset yes')
|
|
|
|
self.api.list_ships()
|
|
|
|
for s in self.store.all('Ship'):
|
|
|
|
self.dump(s, 'all')
|
2024-02-09 14:52:30 +00:00
|
|
|
self.captain.init_mission(s, 'none')
|
2024-01-27 14:05:33 +00:00
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
######## Fleet #########
|
2023-06-16 21:05:47 +00:00
|
|
|
def do_info(self, arg=''):
|
|
|
|
if arg.startswith('r'):
|
|
|
|
self.api.info()
|
|
|
|
pprint(self.agent, 100)
|
2023-06-18 17:15:51 +00:00
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
def do_ships(self, arg=''):
|
|
|
|
if arg.startswith('r'):
|
|
|
|
r = self.api.list_ships()
|
|
|
|
else:
|
|
|
|
r = sorted(list(self.store.all('Ship')))
|
|
|
|
pprint(r)
|
|
|
|
|
|
|
|
def do_ship(self, arg=''):
|
|
|
|
if arg != '':
|
2024-01-20 19:33:50 +00:00
|
|
|
ship = self.resolve_ship(arg)
|
|
|
|
|
|
|
|
self.ship = ship
|
2024-01-09 19:07:27 +00:00
|
|
|
pprint(self.ship, 5)
|
|
|
|
|
|
|
|
######## Atlas #########
|
2023-06-11 18:51:03 +00:00
|
|
|
def do_systems(self, page=1):
|
|
|
|
r = self.api.list_systems(int(page))
|
|
|
|
pprint(self.api.last_meta)
|
2023-06-15 20:37:33 +00:00
|
|
|
|
2024-01-02 05:35:26 +00:00
|
|
|
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)
|
2024-02-03 20:20:04 +00:00
|
|
|
if 'SHIPYARD' in w.traits:
|
|
|
|
self.api.shipyard(w)
|
2024-01-02 05:35:26 +00:00
|
|
|
|
2023-07-16 16:48:45 +00:00
|
|
|
def do_system(self, system_str):
|
|
|
|
system = self.store.get(System, system_str)
|
|
|
|
r = self.api.list_waypoints(system)
|
|
|
|
pprint(r)
|
2023-06-18 05:23:01 +00:00
|
|
|
|
2024-02-01 17:51:27 +00:00
|
|
|
def do_waypoints(self, grep=''):
|
2024-01-04 20:34:31 +00:00
|
|
|
loc = None
|
2024-02-01 17:51:27 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
loc = ship.location
|
|
|
|
system = loc.system
|
2023-07-11 20:09:57 +00:00
|
|
|
print(f'=== waypoints in {system}')
|
2023-06-15 20:37:33 +00:00
|
|
|
r = self.store.all_members(system, 'Waypoint')
|
|
|
|
for w in r:
|
2023-12-28 18:49:00 +00:00
|
|
|
|
|
|
|
wname = w.symbol.split('-')[2]
|
2024-01-13 10:27:32 +00:00
|
|
|
traits = ", ".join(w.itraits())
|
2023-12-28 18:49:00 +00:00
|
|
|
typ = w.type[0]
|
|
|
|
if typ not in ['F','J'] and len(traits) == 0:
|
|
|
|
continue
|
2024-02-01 17:51:27 +00:00
|
|
|
output = ''
|
2024-01-04 20:34:31 +00:00
|
|
|
if loc:
|
|
|
|
dist = loc.distance(w)
|
2024-02-01 17:51:27 +00:00
|
|
|
output = f'{wname:4} {typ} {dist:6} {traits}'
|
2024-01-04 20:34:31 +00:00
|
|
|
else:
|
2024-02-01 17:51:27 +00:00
|
|
|
output = f'{wname:4} {typ} {traits}'
|
|
|
|
if grep == '' or grep.lower() in output.lower():
|
|
|
|
print(output)
|
2023-06-17 18:23:24 +00:00
|
|
|
|
2024-01-02 05:35:26 +00:00
|
|
|
def do_members(self):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
system = ship.location.system
|
2024-01-02 05:35:26 +00:00
|
|
|
pprint(list(self.store.all_members(system)))
|
|
|
|
|
2024-02-01 17:51:27 +00:00
|
|
|
def do_wp(self, grep=''):
|
|
|
|
self.do_waypoints(grep)
|
2024-01-09 19:07:27 +00:00
|
|
|
|
|
|
|
######## Specials #########
|
|
|
|
def do_market(self, arg=''):
|
2024-01-16 18:13:10 +00:00
|
|
|
waypoint = self.resolve_waypoint(arg)
|
2024-01-09 19:07:27 +00:00
|
|
|
r = self.api.marketplace(waypoint)
|
|
|
|
pprint(r, 3)
|
|
|
|
|
2024-01-02 05:35:26 +00:00
|
|
|
def do_atlas(self, state=None):
|
2023-12-28 18:49:00 +00:00
|
|
|
atlas = self.store.get(Atlas, 'ATLAS')
|
2024-01-02 05:35:26 +00:00
|
|
|
if state is not None:
|
|
|
|
atlas.enabled = True if state == 'on' else 'off'
|
2023-12-28 18:49:00 +00:00
|
|
|
pprint(atlas, 5)
|
|
|
|
|
2023-06-17 12:59:52 +00:00
|
|
|
def do_jumps(self, waypoint_str=None):
|
|
|
|
if waypoint_str is None:
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
waypoint = ship.location
|
2023-06-17 12:59:52 +00:00
|
|
|
else:
|
|
|
|
waypoint = self.store.get(Waypoint, waypoint_str.upper())
|
2023-06-12 08:51:01 +00:00
|
|
|
r = self.api.jumps(waypoint)
|
2024-02-03 20:20:04 +00:00
|
|
|
pprint(r, 5)
|
2023-06-12 12:32:58 +00:00
|
|
|
|
2024-01-15 18:39:08 +00:00
|
|
|
def do_shipyard(self, w=''):
|
|
|
|
location = self.resolve_waypoint(w)
|
|
|
|
if location is None:
|
|
|
|
raise CommandError(f'waypoint {w} not found')
|
2024-02-03 20:20:04 +00:00
|
|
|
sy = self.api.shipyard(location)
|
|
|
|
pprint(sy, 5)
|
2024-01-09 19:07:27 +00:00
|
|
|
|
|
|
|
######## Commerce #########
|
|
|
|
def do_refuel(self, source='market'):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
2024-01-09 19:07:27 +00:00
|
|
|
from_cargo = source != 'market'
|
2024-01-24 18:03:57 +00:00
|
|
|
r = self.api.refuel(ship, from_cargo=from_cargo)
|
2023-06-15 19:10:33 +00:00
|
|
|
pprint(r)
|
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
def do_cargo(self):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
print(f'== Cargo {ship.cargo_units}/{ship.cargo_capacity} ==')
|
|
|
|
for c, units in ship.cargo.items():
|
2024-01-09 19:07:27 +00:00
|
|
|
print(f'{units:4d} {c}')
|
|
|
|
|
|
|
|
def do_buy(self, resource, amt=None):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
2024-01-09 19:07:27 +00:00
|
|
|
if amt is None:
|
2024-01-24 18:03:57 +00:00
|
|
|
amt = ship.cargo_capacity - ship.cargo_units
|
|
|
|
self.api.buy(ship, resource.upper(), amt)
|
2024-01-09 19:07:27 +00:00
|
|
|
self.do_cargo()
|
|
|
|
|
|
|
|
def do_sell(self, resource, amt=None):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
self.api.sell(ship, resource.upper(), amt)
|
2024-01-09 19:07:27 +00:00
|
|
|
self.do_cargo()
|
2024-01-27 14:05:33 +00:00
|
|
|
|
|
|
|
def dump(self, ship, resource):
|
|
|
|
if resource == 'all':
|
|
|
|
for r in ship.cargo.keys():
|
|
|
|
self.api.jettison(ship, r)
|
|
|
|
else:
|
|
|
|
self.api.jettison(ship, resource.upper())
|
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
def do_dump(self, resource):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
2024-01-27 14:05:33 +00:00
|
|
|
self.dump(ship, resource)
|
2024-01-09 19:07:27 +00:00
|
|
|
self.do_cargo()
|
|
|
|
|
2024-01-20 19:33:50 +00:00
|
|
|
def do_transfer(self, resource, dship, amount=None):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
2024-01-20 19:33:50 +00:00
|
|
|
resource = resource.upper()
|
2024-01-24 18:03:57 +00:00
|
|
|
avail = ship.get_cargo(resource)
|
2024-01-20 19:33:50 +00:00
|
|
|
if amount is None: amount = avail
|
|
|
|
amount = int(amount)
|
|
|
|
if avail < amount:
|
|
|
|
raise CommandError('resource not in cargo')
|
|
|
|
dship = self.resolve_ship(dship)
|
2024-01-24 18:03:57 +00:00
|
|
|
self.api.transfer(ship, dship, resource, amount)
|
2024-01-20 19:33:50 +00:00
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
|
|
|
|
def do_purchase(self, ship_type):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
location = ship.location
|
2024-01-09 19:07:27 +00:00
|
|
|
ship_type = ship_type.upper()
|
|
|
|
if not ship_type.startswith('SHIP'):
|
|
|
|
ship_type = 'SHIP_' + ship_type
|
|
|
|
s = self.api.purchase(ship_type, location)
|
|
|
|
pprint(s)
|
|
|
|
|
|
|
|
######## Mining #########
|
|
|
|
def do_siphon(self):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
data = self.api.siphon(ship)
|
2024-01-09 19:07:27 +00:00
|
|
|
|
|
|
|
def do_survey(self):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
r = self.api.survey(ship)
|
2024-01-09 19:07:27 +00:00
|
|
|
pprint(r)
|
|
|
|
|
|
|
|
def do_surveys(self):
|
|
|
|
pprint(list(self.store.all('Survey')))
|
|
|
|
|
|
|
|
def do_extract(self, survey_str=''):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
2024-01-09 19:07:27 +00:00
|
|
|
survey = None
|
|
|
|
if survey_str != '':
|
|
|
|
survey = self.resolve('Survey', survey_str)
|
2024-01-24 18:03:57 +00:00
|
|
|
result = self.api.extract(ship, survey)
|
2024-01-09 19:07:27 +00:00
|
|
|
|
|
|
|
symbol = mg(result,'extraction.yield.symbol')
|
|
|
|
units = mg(result,'extraction.yield.units')
|
|
|
|
print(units, symbol)
|
|
|
|
|
|
|
|
|
|
|
|
######## Missions #########
|
|
|
|
def print_mission(self):
|
|
|
|
print(f'mission: {self.ship.mission} ({self.ship.mission_status})')
|
|
|
|
pprint(self.ship.mission_state)
|
|
|
|
|
|
|
|
def do_role(self, role):
|
2024-01-24 18:03:57 +00:00
|
|
|
roles = [None, 'trader', 'probe', 'siphon', 'hauler', 'surveyor', 'miner']
|
|
|
|
ship = self.has_ship()
|
2024-01-09 19:07:27 +00:00
|
|
|
if role == 'none':
|
|
|
|
role = None
|
|
|
|
if role not in roles:
|
|
|
|
print(f'role {role} not found. Choose from {roles}')
|
|
|
|
return
|
2024-01-24 18:03:57 +00:00
|
|
|
ship.role = role
|
2024-01-09 19:07:27 +00:00
|
|
|
|
|
|
|
def do_mission(self, arg=''):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
2024-01-09 19:07:27 +00:00
|
|
|
if arg:
|
2024-02-09 14:52:30 +00:00
|
|
|
self.captain.init_mission(ship, arg)
|
2024-01-09 19:07:27 +00:00
|
|
|
self.print_mission()
|
|
|
|
|
|
|
|
def do_mrestart(self, status='init'):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
2024-02-09 14:52:30 +00:00
|
|
|
self.captain.restart_mission(ship, status)
|
2024-01-09 19:07:27 +00:00
|
|
|
self.print_mission()
|
2024-01-16 18:13:10 +00:00
|
|
|
|
|
|
|
def do_mstep(self):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
2024-02-09 14:52:30 +00:00
|
|
|
self.captain.single_step(ship)
|
2024-01-16 18:13:10 +00:00
|
|
|
self.print_mission()
|
2024-01-09 19:07:27 +00:00
|
|
|
|
|
|
|
def do_mreset(self):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
ship.mission_state = {}
|
2024-01-09 19:07:27 +00:00
|
|
|
|
|
|
|
def do_mset(self, nm, val):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
2024-02-09 14:52:30 +00:00
|
|
|
self.captain.set_mission_param(ship, nm, val)
|
2024-01-24 18:03:57 +00:00
|
|
|
|
|
|
|
def do_crew(self, arg):
|
|
|
|
ship = self.has_ship()
|
|
|
|
crew = self.resolve('Crew', arg)
|
|
|
|
ship.crew = crew
|
|
|
|
pprint(ship)
|
2024-02-11 13:37:46 +00:00
|
|
|
|
|
|
|
def do_phase(self, phase):
|
|
|
|
self.agent.phase = phase
|
2024-01-24 18:03:57 +00:00
|
|
|
|
|
|
|
######## Crews #########
|
|
|
|
def do_create_crews(self):
|
2024-02-09 14:52:30 +00:00
|
|
|
crews = self.captain.create_default_crews()
|
2024-01-24 18:03:57 +00:00
|
|
|
for c in crews:
|
|
|
|
print(f'{c.symbol:15s} {c.site}')
|
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
######## Contracts #########
|
|
|
|
def active_contract(self):
|
|
|
|
for c in self.store.all('Contract'):
|
|
|
|
if c.accepted and not c.fulfilled: return c
|
|
|
|
raise CommandError('no active contract')
|
|
|
|
|
2023-06-16 11:03:19 +00:00
|
|
|
def do_contracts(self, arg=''):
|
|
|
|
if arg.startswith('r'):
|
|
|
|
r = self.api.list_contracts()
|
|
|
|
else:
|
|
|
|
r = list(self.store.all('Contract'))
|
|
|
|
pprint(r)
|
2023-06-18 19:56:49 +00:00
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
def do_negotiate(self):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
r = self.api.negotiate(ship)
|
2024-01-09 19:07:27 +00:00
|
|
|
pprint(r)
|
|
|
|
|
|
|
|
def do_accept(self, c):
|
|
|
|
contract = self.resolve('Contract', c)
|
|
|
|
r = self.api.accept_contract(contract)
|
|
|
|
pprint(r)
|
|
|
|
|
2023-06-18 19:56:49 +00:00
|
|
|
def do_deliver(self):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
site = ship.location
|
2023-06-18 19:56:49 +00:00
|
|
|
contract = self.active_contract()
|
|
|
|
delivery = contract.unfinished_delivery()
|
|
|
|
if delivery is None:
|
|
|
|
raise CommandError('no delivery')
|
|
|
|
resource = delivery['trade_symbol']
|
2024-01-24 18:03:57 +00:00
|
|
|
self.api.deliver(ship, resource, contract)
|
2023-06-18 19:56:49 +00:00
|
|
|
pprint(contract)
|
2023-06-19 08:36:30 +00:00
|
|
|
|
|
|
|
def do_fulfill(self):
|
|
|
|
contract = self.active_contract()
|
|
|
|
self.api.fulfill(contract)
|
2023-06-16 11:03:19 +00:00
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
######## Travel #########
|
|
|
|
def do_travel(self, dest):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
2024-01-09 19:07:27 +00:00
|
|
|
dest = self.resolve('Waypoint', dest)
|
2024-02-09 14:52:30 +00:00
|
|
|
self.captain.init_mission(ship, 'travel')
|
|
|
|
self.captain.set_mission_param(ship, 'dest', dest)
|
2024-01-09 19:07:27 +00:00
|
|
|
self.print_mission()
|
2023-06-15 20:37:33 +00:00
|
|
|
|
|
|
|
def do_go(self, arg):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
system = ship.location.system
|
2023-06-15 20:37:33 +00:00
|
|
|
symbol = f'{system}-{arg}'
|
2023-06-16 12:41:11 +00:00
|
|
|
dest = self.resolve('Waypoint', symbol)
|
2024-01-24 18:03:57 +00:00
|
|
|
self.api.navigate(ship, dest)
|
|
|
|
pprint(ship)
|
2023-06-15 20:37:33 +00:00
|
|
|
|
|
|
|
def do_dock(self):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
self.api.dock(ship)
|
|
|
|
pprint(ship)
|
2023-06-15 20:37:33 +00:00
|
|
|
|
|
|
|
def do_orbit(self):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
self.api.orbit(ship)
|
|
|
|
pprint(ship)
|
2023-06-15 20:37:33 +00:00
|
|
|
|
2023-12-28 18:49:00 +00:00
|
|
|
def do_speed(self, speed):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
2023-12-28 18:49:00 +00:00
|
|
|
speed = speed.upper()
|
|
|
|
speeds = ['DRIFT', 'STEALTH','CRUISE','BURN']
|
|
|
|
if speed not in speeds:
|
|
|
|
print('please choose from:', speeds)
|
2024-01-24 18:03:57 +00:00
|
|
|
self.api.flight_mode(ship, speed)
|
2023-06-17 12:59:52 +00:00
|
|
|
|
2023-12-28 18:49:00 +00:00
|
|
|
def do_jump(self, waypoint_str):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
2023-12-28 18:49:00 +00:00
|
|
|
w = self.resolve('Waypoint', waypoint_str)
|
2024-01-24 18:03:57 +00:00
|
|
|
self.api.jump(ship, w)
|
|
|
|
pprint(ship)
|
2023-06-16 21:05:47 +00:00
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
######## Analysis #########
|
2024-01-21 19:21:38 +00:00
|
|
|
def do_server(self):
|
|
|
|
data = self.api.status()
|
|
|
|
pprint(data)
|
|
|
|
|
|
|
|
def do_highscore(self):
|
|
|
|
data = self.api.status()
|
|
|
|
leaders = mg(data, 'leaderboards.mostCredits')
|
|
|
|
for l in leaders:
|
|
|
|
a = mg(l,'agentSymbol')
|
|
|
|
c = mg(l, 'credits')
|
|
|
|
print(f'{a:15s} {c}')
|
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
def do_stats(self):
|
|
|
|
total = 0
|
|
|
|
for t in self.store.data:
|
|
|
|
num = len(self.store.data[t])
|
|
|
|
nam = t.__name__
|
|
|
|
total += num
|
|
|
|
print(f'{num:5d} {nam}')
|
|
|
|
print(f'{total:5d} total')
|
2023-06-17 21:07:53 +00:00
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
def do_defrag(self):
|
|
|
|
self.store.defrag()
|
|
|
|
|
2024-01-09 19:39:11 +00:00
|
|
|
def do_obj(self, oid):
|
|
|
|
if not '.' in oid:
|
|
|
|
print('Usage: obj SYMBOL.ext')
|
|
|
|
return
|
|
|
|
symbol, ext = oid.split('.')
|
|
|
|
symbol = symbol.upper()
|
|
|
|
if not ext in self.store.extensions:
|
2024-01-27 14:05:33 +00:00
|
|
|
raise CommandError('unknown extension')
|
2024-01-09 19:39:11 +00:00
|
|
|
typ = self.store.extensions[ext]
|
|
|
|
obj = self.store.get(typ, symbol)
|
|
|
|
if obj is None:
|
2024-01-27 14:05:33 +00:00
|
|
|
raise CommandError('object not found')
|
2024-01-09 19:39:11 +00:00
|
|
|
pprint(obj.__getstate__())
|
|
|
|
print('=== store ===')
|
|
|
|
h = self.store.get_header(obj)
|
|
|
|
if h:
|
|
|
|
pprint(h, 3)
|
|
|
|
else:
|
|
|
|
print('Not stored')
|
|
|
|
print('Dirty: ', obj in self.store.dirty_objects)
|
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
def do_query(self, resource):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
location = ship.location
|
2024-01-09 19:07:27 +00:00
|
|
|
resource = resource.upper()
|
|
|
|
print('Found markets:')
|
2024-02-09 14:52:30 +00:00
|
|
|
for typ, m, d, plen in find_closest_markets(self.c, resource, 'buy,exchange',location):
|
2024-01-09 19:07:27 +00:00
|
|
|
price = '?'
|
|
|
|
if resource in m.prices:
|
|
|
|
price = m.prices[resource]['buy']
|
|
|
|
print(m, typ[0], f'{plen-1:3} hops {price}')
|
|
|
|
|
|
|
|
def do_findtrade(self):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
system = ship.location.system
|
2024-02-09 14:52:30 +00:00
|
|
|
t = find_trade(self.c, system)
|
2024-01-09 19:07:27 +00:00
|
|
|
pprint(t)
|
2023-06-17 21:07:53 +00:00
|
|
|
|
2024-01-09 19:07:27 +00:00
|
|
|
def do_prices(self, resource=None):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
|
|
|
system = ship.location.system
|
2024-02-09 14:52:30 +00:00
|
|
|
prices = prices(self.c, system)
|
2024-01-09 19:07:27 +00:00
|
|
|
if resource is not None:
|
2024-01-15 18:39:08 +00:00
|
|
|
prices = {resource: prices[resource.upper()]}
|
|
|
|
|
|
|
|
for res, p in prices.items():
|
|
|
|
print('==' + res)
|
|
|
|
for m in p:
|
2024-01-20 19:33:50 +00:00
|
|
|
print(f"{m['wp'].symbol:12s} {m['category']} {m['volume']:5d} {m['buy']:5d} {m['sell']:5d}")
|
2024-01-13 10:27:32 +00:00
|
|
|
|
|
|
|
def do_path(self, waypoint_str):
|
2024-01-24 18:03:57 +00:00
|
|
|
ship = self.has_ship()
|
2024-01-13 10:27:32 +00:00
|
|
|
w = self.resolve('Waypoint', waypoint_str)
|
2024-02-09 14:52:30 +00:00
|
|
|
p = find_nav_path(self.c, ship.location, w, ship.fuel_capacity)
|
2024-01-13 10:27:32 +00:00
|
|
|
pprint(p)
|
2024-02-10 18:29:11 +00:00
|
|
|
|
|
|
|
def do_list(self, klass):
|
|
|
|
ship = self.has_ship()
|
|
|
|
for o in self.store.all_members(klass, ship.location.system):
|
|
|
|
print(o)
|
|
|
|
|