rewrote hauling and highscores

This commit is contained in:
Richard 2024-01-21 20:21:38 +01:00
parent 3f7a416fdc
commit b0ef68a721
6 changed files with 76 additions and 39 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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:

View File

@ -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)
res = self.api.transfer(s, self.ship, r, amount)
return 'done' if amount == cargo_space else 'more'
return 'more'
pass
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, {

View File

@ -10,16 +10,52 @@ class SiphonMission(BaseMission):
return {
'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'
})
}

View File

@ -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'