0ptr/nullptr/missions/siphon.py

63 lines
1.5 KiB
Python
Raw Normal View History

2024-01-20 19:33:50 +00:00
from nullptr.missions.base import BaseMission, MissionParam
from nullptr.models.waypoint import Waypoint
class SiphonMission(BaseMission):
def start_state(self):
return 'travel-to'
@classmethod
def params(cls):
return {
'site': MissionParam(Waypoint, True),
}
2024-01-21 19:21:38 +00:00
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)
2024-01-24 18:03:57 +00:00
if amt > 0:
self.api.transfer(self.ship, h, r, amt)
2024-01-21 19:21:38 +00:00
return 'more'
2024-01-20 19:33:50 +00:00
def steps(self):
return {
**self.travel_steps('to', 'site', 'siphon'),
2024-01-21 19:21:38 +00:00
'siphon': (self.step_siphon, {
'more': 'siphon',
'full': 'unload'
}),
'unload': (self.step_unload, {
'more': 'unload',
'done': 'done'
})
2024-01-20 19:33:50 +00:00
}
2024-01-21 19:21:38 +00:00
2024-01-20 19:33:50 +00:00