mining working again
This commit is contained in:
28
nullptr/missions/extraction.py
Normal file
28
nullptr/missions/extraction.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from nullptr.missions.base import BaseMission
|
||||
|
||||
class ExtractionMission(BaseMission):
|
||||
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)
|
||||
if amt > 0:
|
||||
self.api.transfer(self.ship, h, r, amt)
|
||||
return 'more'
|
||||
@@ -3,15 +3,16 @@ from nullptr.models.waypoint import Waypoint
|
||||
from nullptr.models.survey import Survey
|
||||
from nullptr.models.contract import Contract
|
||||
from nullptr.util import *
|
||||
from nullptr.missions.extraction import ExtractionMission
|
||||
|
||||
class MiningMission(BaseMission):
|
||||
class MiningMission(ExtractionMission):
|
||||
@classmethod
|
||||
def params(cls):
|
||||
return {
|
||||
'site': MissionParam(Waypoint, True),
|
||||
'resources': MissionParam(list, True)
|
||||
}
|
||||
p
|
||||
|
||||
def start_state(self):
|
||||
return 'travel-to'
|
||||
|
||||
@@ -20,7 +21,7 @@ class MiningMission(BaseMission):
|
||||
**self.travel_steps('to', 'site', 'extract'),
|
||||
'extract': (self.step_extract, {
|
||||
'more': 'extract',
|
||||
'full': 'unload'
|
||||
'done': 'unload'
|
||||
}),
|
||||
'unload': (self.step_unload, {
|
||||
'more': 'unload',
|
||||
@@ -29,36 +30,31 @@ class MiningMission(BaseMission):
|
||||
}
|
||||
|
||||
def get_survey(self):
|
||||
resource = self.st('resource')
|
||||
resources = self.st('resources')
|
||||
site = self.rst(Waypoint,'site')
|
||||
best_score = 0
|
||||
best_survey = None
|
||||
# todo optimize
|
||||
for s in self.store.all(Survey):
|
||||
if resource in s.deposits and site.symbol == s.waypoint:
|
||||
return s
|
||||
return None
|
||||
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()
|
||||
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:
|
||||
if self.ship.cargo_space() > 5:
|
||||
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'
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from nullptr.missions.base import BaseMission, MissionParam
|
||||
from nullptr.missions.base import MissionParam
|
||||
from nullptr.missions.extraction import ExtractionMission
|
||||
from nullptr.models.waypoint import Waypoint
|
||||
|
||||
class SiphonMission(BaseMission):
|
||||
class SiphonMission(ExtractionMission):
|
||||
def start_state(self):
|
||||
return 'travel-to'
|
||||
|
||||
@@ -18,32 +19,7 @@ class SiphonMission(BaseMission):
|
||||
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)
|
||||
if amt > 0:
|
||||
self.api.transfer(self.ship, h, r, amt)
|
||||
return 'more'
|
||||
|
||||
|
||||
def steps(self):
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user