working on startup
This commit is contained in:
parent
74ce884b05
commit
cf930fe24b
@ -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']
|
||||
|
@ -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)
|
||||
|
||||
|
@ -46,9 +46,12 @@ class General:
|
||||
ag = self.agent.symbol
|
||||
command = self.store.get('Ship', f'{ag}-1')
|
||||
probe = self.store.get('Ship', f'{ag}-2')
|
||||
if command.role is None:
|
||||
command.role = 'probe'
|
||||
if probe.role is None:
|
||||
probe.role = 'sitter'
|
||||
|
||||
|
||||
def phase_probes(self):
|
||||
# * probes on all markets
|
||||
pass
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
26
nullptr/roles/sitter.py
Normal file
26
nullptr/roles/sitter.py
Normal file
@ -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)
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user