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 from nullptr.util import * class MiningMission(BaseMission): @classmethod def params(cls): return { 'site': MissionParam(Waypoint, True), 'resources': MissionParam(list, True) } p def start_state(self): return 'travel-to' def steps(self): return { **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): 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'