0ptr/nullptr/missions/mine.py

65 lines
1.8 KiB
Python
Raw Normal View History

from nullptr.missions.base import BaseMission, MissionParam
from nullptr.models.waypoint import Waypoint
from nullptr.models.survey import Survey
from nullptr.models.contract import Contract
2023-06-25 20:39:33 +00:00
from nullptr.util import *
class MiningMission(BaseMission):
@classmethod
def params(cls):
return {
'site': MissionParam(Waypoint, True),
2024-01-24 18:03:57 +00:00
'resources': MissionParam(list, True)
}
2024-01-24 18:03:57 +00:00
p
def start_state(self):
return 'travel-to'
def steps(self):
return {
2024-01-24 18:03:57 +00:00
**self.travel_steps('to', 'site', 'extract'),
'extract': (self.step_extract, {
'more': 'extract',
'full': 'unload'
}),
'unload': (self.step_unload, {
'more': 'unload',
'done': 'done'
})
}
def get_survey(self):
resource = self.st('resource')
site = self.rst(Waypoint,'site')
# todo optimize
for s in self.store.all(Survey):
2024-01-13 20:42:49 +00:00
if resource in s.deposits and site.symbol == s.waypoint:
return s
return None
def step_extract(self):
survey = self.get_survey()
print('using survey:', str(survey))
result = self.api.extract(self.ship, survey)
symbol = sg(result,'extraction.yield.symbol')
units = sg(result,'extraction.yield.units')
print('extracted:', units, symbol)
self.next_step = self.ship.cooldown
if self.ship.cargo_units < self.ship.cargo_capacity:
return 'more'
else:
return 'done'
def step_dispose(self):
contract = self.rst(Contract, 'contract')
typs = self.ship.nondeliverable_cargo(contract)
if len(typs) > 0:
self.api.jettison(self.ship, typs[0])
if len(typs) > 1:
return 'more'
elif self.ship.cargo_units > self.ship.cargo_capacity - 3:
return 'full'
else:
return 'done'