0ptr/nullptr/missions/mine.py

60 lines
1.6 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 *
2024-01-25 18:57:49 +00:00
from nullptr.missions.extraction import ExtractionMission
2024-01-25 18:57:49 +00:00
class MiningMission(ExtractionMission):
@classmethod
def params(cls):
return {
'site': MissionParam(Waypoint, True),
2024-01-24 18:03:57 +00:00
'resources': MissionParam(list, True)
}
2024-01-25 18:57:49 +00:00
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',
2024-01-25 18:57:49 +00:00
'done': 'unload'
2024-01-24 18:03:57 +00:00
}),
'unload': (self.step_unload, {
'more': 'unload',
'done': 'done'
})
}
def get_survey(self):
2024-01-25 18:57:49 +00:00
resources = self.st('resources')
site = self.rst(Waypoint,'site')
2024-01-25 18:57:49 +00:00
best_score = 0
best_survey = None
# todo optimize
for s in self.store.all(Survey):
2024-01-25 18:57:49 +00:00
if site != s.waypoint:
continue
good = len([1 for r in s.deposits if r in resources])
total = len(s.deposits)
score = good / total
if score > best_score:
best_score = score
best_survey = s
return best_survey
def step_extract(self):
survey = self.get_survey()
result = self.api.extract(self.ship, survey)
symbol = sg(result,'extraction.yield.symbol')
units = sg(result,'extraction.yield.units')
self.next_step = self.ship.cooldown
2024-01-25 18:57:49 +00:00
if self.ship.cargo_space() > 5:
return 'more'
else:
return 'done'
2024-01-25 18:57:49 +00:00