rewrote hauling and highscores
This commit is contained in:
parent
3f7a416fdc
commit
b0ef68a721
@ -73,6 +73,13 @@ class Api:
|
||||
self.agent.update(mg(result, 'agent'))
|
||||
self.agent.token = token
|
||||
|
||||
def status(self):
|
||||
try:
|
||||
self.request('get', '')
|
||||
except ApiError:
|
||||
pass
|
||||
return self.last_result
|
||||
|
||||
def info(self):
|
||||
data = self.request('get', 'my/agent')
|
||||
self.agent.update(data)
|
||||
|
@ -132,9 +132,11 @@ class CentralCommand:
|
||||
def assign_hauler(self, s):
|
||||
w = self.find_gas(s)
|
||||
m = self.analyzer.best_sell_market(s.location.system, 'HYDROCARBON')
|
||||
resources = list(m.prices.keys())
|
||||
self.init_mission(s, 'haul')
|
||||
self.smipa(s, 'site', w)
|
||||
self.smipa(s, 'dest', m)
|
||||
self.smipa(s, 'resources', resources)
|
||||
|
||||
def assign_siphon(self, s):
|
||||
w = self.find_gas(s)
|
||||
|
@ -517,6 +517,18 @@ class Commander(CommandLine):
|
||||
pprint(self.ship)
|
||||
|
||||
######## Analysis #########
|
||||
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}')
|
||||
|
||||
def do_stats(self):
|
||||
total = 0
|
||||
for t in self.store.data:
|
||||
|
@ -20,48 +20,25 @@ class HaulMission(BaseMission):
|
||||
return False
|
||||
return True
|
||||
|
||||
def wait_cargo(self):
|
||||
dmkt = self.store.get('Marketplace', self.st('dest'))
|
||||
sellables = dmkt.prices.keys()
|
||||
for s in self.store.all("Ship"):
|
||||
if s.location != self.ship.location: continue
|
||||
if s.mission not in ['mine','siphon']: continue
|
||||
for r, a in s.cargo.items():
|
||||
if r not in sellables: continue
|
||||
return True
|
||||
return False
|
||||
|
||||
def step_load(self):
|
||||
cargo_space = self.ship.cargo_capacity - self.ship.cargo_units
|
||||
dmkt = self.store.get('Marketplace', self.st('dest'))
|
||||
sellables = dmkt.prices.keys()
|
||||
for s in self.store.all("Ship"):
|
||||
if s.location != self.ship.location: continue
|
||||
if s.mission not in ['mine','siphon']: continue
|
||||
for r, a in s.cargo.items():
|
||||
if r not in sellables: continue
|
||||
amount = min(cargo_space, a)
|
||||
pass
|
||||
|
||||
res = self.api.transfer(s, self.ship, r, amount)
|
||||
|
||||
return 'done' if amount == cargo_space else 'more'
|
||||
return 'more'
|
||||
def cargo_full(self):
|
||||
return self.ship.cargo_space() == 0
|
||||
|
||||
@classmethod
|
||||
def params(cls):
|
||||
return {
|
||||
'site': MissionParam(Waypoint, True),
|
||||
'dest': MissionParam(Waypoint, True),
|
||||
'resources': MissionParam(list, True)
|
||||
}
|
||||
|
||||
def steps(self):
|
||||
return {
|
||||
**self.travel_steps('to', 'site', 'wait-turn'),
|
||||
'wait-turn': (self.step_turn, 'load', self.wait_turn),
|
||||
'load': (self.step_load, {
|
||||
'more': 'load',
|
||||
'done': 'travel-back'
|
||||
}, self.wait_cargo),
|
||||
'load': (self.step_load, 'travel-back', self.cargo_full),
|
||||
**self.travel_steps('back', 'dest', 'dock-dest'),
|
||||
'dock-dest': (self.step_dock, 'unload'),
|
||||
'unload': (self.step_sell, {
|
||||
|
@ -11,15 +11,51 @@ class SiphonMission(BaseMission):
|
||||
'site': MissionParam(Waypoint, True),
|
||||
}
|
||||
|
||||
def steps(self):
|
||||
return {
|
||||
**self.travel_steps('to', 'site', 'siphon'),
|
||||
'siphon': (self.step_siphon, 'done', self.cargo_full)
|
||||
}
|
||||
|
||||
def cargo_full(self):
|
||||
return self.ship.cargo_capacity - self.ship.cargo_units > 5
|
||||
|
||||
def step_siphon(self):
|
||||
result = self.api.siphon(self.ship)
|
||||
self.next_step = self.ship.cooldown
|
||||
if self.ship.cargo_space() > 5:
|
||||
return 'more'
|
||||
else:
|
||||
return 'full'
|
||||
|
||||
def find_hauler(self, r):
|
||||
for s in self.store.all('Ship'):
|
||||
if s.mission != 'haul': continue
|
||||
if s.location != self.ship.location:
|
||||
continue
|
||||
if s.mission_status != 'load':
|
||||
continue
|
||||
if r not in s.mission_state['resources']: continue
|
||||
return s
|
||||
return None
|
||||
|
||||
def step_unload(self):
|
||||
if len(self.ship.cargo) == 0:
|
||||
return 'done'
|
||||
r = list(self.ship.cargo.keys())[0]
|
||||
amt = self.ship.cargo[r]
|
||||
h = self.find_hauler(r)
|
||||
if h is None:
|
||||
self.api.jettison(self.ship, r)
|
||||
else:
|
||||
space = h.cargo_space()
|
||||
amt = min(space, amt)
|
||||
self.api.transfer(self.ship, h, r, amt)
|
||||
return 'more'
|
||||
|
||||
def steps(self):
|
||||
return {
|
||||
**self.travel_steps('to', 'site', 'siphon'),
|
||||
'siphon': (self.step_siphon, {
|
||||
'more': 'siphon',
|
||||
'full': 'unload'
|
||||
}),
|
||||
'unload': (self.step_unload, {
|
||||
'more': 'unload',
|
||||
'done': 'done'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -123,6 +123,9 @@ class Ship(Base):
|
||||
garbage = [c for c in cargo if c not in deliveries]
|
||||
return garbage
|
||||
|
||||
def cargo_space(self):
|
||||
return self.cargo_capacity - self.cargo_units
|
||||
|
||||
def update_timers(self):
|
||||
if self.status == 'IN_TRANSIT' and self.arrival < time():
|
||||
self.status = 'IN_ORBIT'
|
||||
|
Loading…
Reference in New Issue
Block a user