diff --git a/nullptr/analyzer.py b/nullptr/analyzer.py index 2b148cd..9a966a9 100644 --- a/nullptr/analyzer.py +++ b/nullptr/analyzer.py @@ -165,7 +165,7 @@ def prices(c, system): def find_trade(c, system): max_traders = 3 - prices = prices(system) + pcs= prices(c, system) occupied_routes = dict() for s in c.store.all('Ship'): if s.mission != 'trade': @@ -176,7 +176,7 @@ def find_trade(c, system): else: occupied_routes[k] = 1 best = None - for resource, markets in prices.items(): + for resource, markets in pcs.items(): source = sorted(markets, key=lambda x: x['buy'])[0] dest = sorted(markets, key=lambda x: x['sell'])[-1] swp = source['wp'] diff --git a/nullptr/commander.py b/nullptr/commander.py index de653a2..88066b2 100644 --- a/nullptr/commander.py +++ b/nullptr/commander.py @@ -139,7 +139,7 @@ class Commander(CommandLine): symbol = input('agent name: ') agent = self.store.get(Agent, symbol, create=True) self.agent = agent - api = Api(self.store, agent) + api = Api(self.c, agent) self.api = api faction = input('faction or token: ') if len(faction) > 50: @@ -571,3 +571,9 @@ class Commander(CommandLine): w = self.resolve('Waypoint', waypoint_str) p = find_nav_path(self.c, ship.location, w, ship.fuel_capacity) pprint(p) + + def do_list(self, klass): + ship = self.has_ship() + for o in self.store.all_members(klass, ship.location.system): + print(o) + diff --git a/nullptr/general.py b/nullptr/general.py index e1b9709..4ad4f39 100644 --- a/nullptr/general.py +++ b/nullptr/general.py @@ -46,8 +46,11 @@ class General: ag = self.agent.symbol command = self.store.get('Ship', f'{ag}-1') probe = self.store.get('Ship', f'{ag}-2') - command.role = 'probe' - probe.role = 'sitter' + if command.role is None: + command.role = 'probe' + if probe.role is None: + probe.role = 'sitter' + def phase_probes(self): # * probes on all markets diff --git a/nullptr/missions/base.py b/nullptr/missions/base.py index 51f8aed..5bb4313 100644 --- a/nullptr/missions/base.py +++ b/nullptr/missions/base.py @@ -322,7 +322,8 @@ class BaseMission(Mission): if self.ship.fuel_capacity == 0: steps = { - f'travel-{nm}': (calc, f'go-{nm}'), + f'travel-{nm}': (calc, f'orbit-{nm}'), + f'orbit-{nm}': (self.step_orbit, f'go-{nm}'), f'go-{nm}': (self.step_travel, f'nav-{nm}'), f'nav-{nm}': (self.step_navigate_traject, { 'done': next_step, diff --git a/nullptr/missions/trade.py b/nullptr/missions/trade.py index 3310bd2..8655b45 100644 --- a/nullptr/missions/trade.py +++ b/nullptr/missions/trade.py @@ -13,7 +13,7 @@ class TradeMission(BaseMission): cargo_space = self.ship.cargo_capacity - self.ship.cargo_units smkt = self.store.get('Marketplace', self.st('site')) dmkt = self.store.get('Marketplace', self.st('dest')) - resource = find_deal(smkt, dmkt) + resource = find_deal(self.c, smkt, dmkt) if resource is None: return 'done' price = smkt.buy_price(resource) diff --git a/nullptr/roles/__init__.py b/nullptr/roles/__init__.py index 6a8a709..1dcd54c 100644 --- a/nullptr/roles/__init__.py +++ b/nullptr/roles/__init__.py @@ -4,6 +4,7 @@ from nullptr.roles.siphon import assign_siphon from nullptr.roles.hauler import assign_hauler from nullptr.roles.surveyor import assign_surveyor from nullptr.roles.miner import assign_miner +from nullptr.roles.sitter import assign_sitter def assign_mission(c, s): if s.role == 'trader': @@ -18,3 +19,5 @@ def assign_mission(c, s): assign_surveyor(c, s) elif s.role == 'miner': assign_miner(c, s) + elif s.role == 'sitter': + assign_sitter(c, s) diff --git a/nullptr/roles/sitter.py b/nullptr/roles/sitter.py new file mode 100644 index 0000000..aa37b4b --- /dev/null +++ b/nullptr/roles/sitter.py @@ -0,0 +1,26 @@ +from nullptr.analyzer import Point + +def assign_sitter_at(c, s, w): + c.captain.init_mission(s, 'sit') + c.captain.smipa(s, 'dest', w.symbol) + +def assign_sitter(c, s): + system = s.location.system + ships = c.store.all('Ship') + markets = c.store.all_members(system, 'Marketplace') + origin = Point(0, 0) + markets = sorted(markets, key=lambda m: m.waypoint.distance(origin)) + shipyards = c.store.all_members(system, 'Shipyard') + occupied = [s.mission_state['dest'] for s in ships if s.mission=='sit'] + probe_shipyard = [y for y in shipyards if 'SHIP_PROBE' in y.types][0] + print('oc', occupied) + print('proya', probe_shipyard) + + if probe_shipyard.symbol not in occupied: + return assign_sitter_at(c, s, probe_shipyard) + for y in shipyards: + if y.symbol not in occupied: + return assign_sitter_at(c, s, y) + for m in markets: + if m.symbol not in occupied: + return assign_sitter_at(c, s, m) \ No newline at end of file diff --git a/nullptr/store.py b/nullptr/store.py index cfd9afb..07b4fba 100644 --- a/nullptr/store.py +++ b/nullptr/store.py @@ -227,7 +227,7 @@ class Store: symbol = obj.symbol obj.store = self self.data[typ][symbol] = obj - if type(obj).__name__ in ['Waypoint','Marketplace', 'Jumpgate', 'Survey']: + if type(obj).__name__ in ['Waypoint','Marketplace', 'Jumpgate', 'Survey', 'Shipyard']: system_str = obj.system.symbol if system_str not in self.system_members: self.system_members[system_str] = set()