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), 'resource': MissionParam(str, True), 'dest': MissionParam(Waypoint, True), 'delivery': MissionParam(str, True, 'deliver'), 'contract': MissionParam(Contract, False) } def start_state(self): return 'travel-to' def steps(self): return { **self.travel_steps('to', 'site', 'orbit1'), 'orbit1': (self.step_orbit, 'extract'), 'extract': (self.step_extract, { 'done': 'dock', 'more': 'extract' }), 'dock': (self.step_dock, 'sell'), 'sell': (self.step_sell, { 'more': 'sell', 'done': 'orbit2', }), 'orbit2': (self.step_orbit, 'jettison'), 'jettison': (self.step_dispose, { 'more': 'jettison', 'done': 'extract', 'full': 'travel-back' }), **self.travel_steps('back', 'dest', 'unload'), 'unload': (self.step_unload, { 'done': 'travel-to', 'more': 'unload' }), } 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'