Update commander.py and mission.py
This commit is contained in:
		
							parent
							
								
									ddd693a66e
								
							
						
					
					
						commit
						7c3eaa825f
					
				@ -126,7 +126,7 @@ class Commander(CommandLine):
 | 
				
			|||||||
    self.set_mission('mine')
 | 
					    self.set_mission('mine')
 | 
				
			||||||
    self.centcom.set_mission_param(self.ship, 'site', site)
 | 
					    self.centcom.set_mission_param(self.ship, 'site', site)
 | 
				
			||||||
    self.centcom.set_mission_param(self.ship, 'resource', resource)
 | 
					    self.centcom.set_mission_param(self.ship, 'resource', resource)
 | 
				
			||||||
    self.centcom.set_mission_param(self.ship, 'destination', destination)
 | 
					    self.centcom.set_mission_param(self.ship, 'dest', destination)
 | 
				
			||||||
    self.centcom.set_mission_param(self.ship, 'contract', contract.symbol)
 | 
					    self.centcom.set_mission_param(self.ship, 'contract', contract.symbol)
 | 
				
			||||||
    self.print_mission()
 | 
					    self.print_mission()
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
@ -148,10 +148,16 @@ class Commander(CommandLine):
 | 
				
			|||||||
    self.set_mission('haul')
 | 
					    self.set_mission('haul')
 | 
				
			||||||
    self.centcom.set_mission_param(self.ship, 'site', site.symbol)
 | 
					    self.centcom.set_mission_param(self.ship, 'site', site.symbol)
 | 
				
			||||||
    self.centcom.set_mission_param(self.ship, 'resource', resource)
 | 
					    self.centcom.set_mission_param(self.ship, 'resource', resource)
 | 
				
			||||||
    self.centcom.set_mission_param(self.ship, 'destination', destination)
 | 
					    self.centcom.set_mission_param(self.ship, 'dest', destination)
 | 
				
			||||||
    self.centcom.set_mission_param(self.ship, 'contract', contract.symbol)
 | 
					    self.centcom.set_mission_param(self.ship, 'contract', contract.symbol)
 | 
				
			||||||
    self.print_mission()
 | 
					    self.print_mission()
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					  def do_travel(self, dest):
 | 
				
			||||||
 | 
					    dest = self.resolve('Waypoint', dest)
 | 
				
			||||||
 | 
					    self.set_mission('travel')
 | 
				
			||||||
 | 
					    self.centcom.set_mission_param(self.ship, 'dest', dest.symbol)
 | 
				
			||||||
 | 
					    self.print_mission()
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
  def do_register(self, faction):
 | 
					  def do_register(self, faction):
 | 
				
			||||||
    self.api.register(faction.upper())
 | 
					    self.api.register(faction.upper())
 | 
				
			||||||
    site = self.ship.location_str
 | 
					    site = self.ship.location_str
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,7 @@ from nullptr.models.survey import Survey
 | 
				
			|||||||
from nullptr.models.ship import Ship
 | 
					from nullptr.models.ship import Ship
 | 
				
			||||||
from nullptr.analyzer import Analyzer
 | 
					from nullptr.analyzer import Analyzer
 | 
				
			||||||
from time import time
 | 
					from time import time
 | 
				
			||||||
 | 
					from functools import partial
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
from nullptr.util import *
 | 
					from nullptr.util import *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -172,16 +173,15 @@ class BaseMission(Mission):
 | 
				
			|||||||
    resource = self.st('resource')
 | 
					    resource = self.st('resource')
 | 
				
			||||||
    self.api.buy(self.ship, resource, cargo_space)
 | 
					    self.api.buy(self.ship, resource, cargo_space)
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  def travel(self, nm):
 | 
					  def step_travel(self):
 | 
				
			||||||
    dest = self.rst(Waypoint, nm)
 | 
					 | 
				
			||||||
    traject = self.st('traject')
 | 
					    traject = self.st('traject')
 | 
				
			||||||
 | 
					    if traject is None or traject == []:
 | 
				
			||||||
 | 
					      return 'done'
 | 
				
			||||||
 | 
					    dest = self.store.get(Waypoint, traject[-1])
 | 
				
			||||||
    loc = self.ship.location()
 | 
					    loc = self.ship.location()
 | 
				
			||||||
    if dest == loc:
 | 
					    if dest == loc:
 | 
				
			||||||
      self.sts('traject', None)
 | 
					      self.sts('traject', None)
 | 
				
			||||||
      return 'done'
 | 
					      return 'done'
 | 
				
			||||||
    elif traject is None:
 | 
					 | 
				
			||||||
      print(f'calculating path to {dest}')
 | 
					 | 
				
			||||||
      traject = self.calculate_traject(dest)
 | 
					 | 
				
			||||||
    hop = traject.pop(0)
 | 
					    hop = traject.pop(0)
 | 
				
			||||||
    if len(hop.split('-')) == 3:
 | 
					    if len(hop.split('-')) == 3:
 | 
				
			||||||
      self.api.navigate(self.ship, hop)
 | 
					      self.api.navigate(self.ship, hop)
 | 
				
			||||||
@ -194,7 +194,9 @@ class BaseMission(Mission):
 | 
				
			|||||||
    self.sts('traject', traject)
 | 
					    self.sts('traject', traject)
 | 
				
			||||||
    return 'more'
 | 
					    return 'more'
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  def calculate_traject(self, dest):
 | 
					  def step_calculate_traject(self, dest):
 | 
				
			||||||
 | 
					    if type(dest) == str:
 | 
				
			||||||
 | 
					      dest = self.store.get(Waypoint, dest)
 | 
				
			||||||
    loc = self.ship.location()
 | 
					    loc = self.ship.location()
 | 
				
			||||||
    loc_sys = self.store.get(System, loc.system())
 | 
					    loc_sys = self.store.get(System, loc.system())
 | 
				
			||||||
    loc_jg = self.analyzer.get_jumpgate(loc_sys)
 | 
					    loc_jg = self.analyzer.get_jumpgate(loc_sys)
 | 
				
			||||||
@ -202,47 +204,59 @@ class BaseMission(Mission):
 | 
				
			|||||||
    dest_jg = self.analyzer.get_jumpgate(dest_sys)
 | 
					    dest_jg = self.analyzer.get_jumpgate(dest_sys)
 | 
				
			||||||
    path = self.analyzer.find_path(loc_sys, dest_sys)
 | 
					    path = self.analyzer.find_path(loc_sys, dest_sys)
 | 
				
			||||||
    result = []
 | 
					    result = []
 | 
				
			||||||
    print(loc.symbol, loc_jg.symbol)
 | 
					 | 
				
			||||||
    if loc.symbol != loc_jg.symbol:
 | 
					    if loc.symbol != loc_jg.symbol:
 | 
				
			||||||
      result.append(loc_jg.symbol)
 | 
					      result.append(loc_jg.symbol)
 | 
				
			||||||
    result += [s.symbol for s in path[1:]]
 | 
					    result += [s.symbol for s in path[1:]]
 | 
				
			||||||
    if dest_jg.symbol != dest.symbol:
 | 
					    if dest_jg.symbol != dest.symbol:
 | 
				
			||||||
      result.append(dest.symbol)
 | 
					      result.append(dest.symbol)
 | 
				
			||||||
 | 
					    self.sts('traject', result)
 | 
				
			||||||
    print(result)
 | 
					    print(result)
 | 
				
			||||||
    return result
 | 
					    return result
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
  def step_travel_site(self):
 | 
					 | 
				
			||||||
    return self.travel('site')
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  def step_travel_dest(self):
 | 
					 | 
				
			||||||
    return self.travel('destination')
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
  def step_dock(self):
 | 
					  def step_dock(self):
 | 
				
			||||||
    self.api.dock(self.ship)
 | 
					    self.api.dock(self.ship)
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
  def step_refuel(self):
 | 
					  def step_refuel(self):
 | 
				
			||||||
    if self.ship.fuel_current < 100:
 | 
					    if self.ship.fuel_current < 100:
 | 
				
			||||||
 | 
					      try:
 | 
				
			||||||
        self.api.refuel(self.ship)
 | 
					        self.api.refuel(self.ship)
 | 
				
			||||||
 | 
					      except Exception as e:
 | 
				
			||||||
 | 
					        pass
 | 
				
			||||||
       
 | 
					       
 | 
				
			||||||
  def step_orbit(self):
 | 
					  def step_orbit(self):
 | 
				
			||||||
    self.api.orbit(self.ship)
 | 
					    self.api.orbit(self.ship)
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					  def travel_steps(self, nm, destination, next_step):
 | 
				
			||||||
 | 
					    destination = self.st(destination)
 | 
				
			||||||
 | 
					    calc = partial(self.step_calculate_traject, destination)
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      f'travel-{nm}': (self.step_orbit, f'calc-trav-{nm}'),
 | 
				
			||||||
 | 
					      f'calc-trav-{nm}': (calc, f'go-{nm}'),
 | 
				
			||||||
 | 
					      f'go-{nm}': (self.step_travel, {
 | 
				
			||||||
 | 
					        'done': f'dock-{nm}',
 | 
				
			||||||
 | 
					        'more': f'go-{nm}'
 | 
				
			||||||
 | 
					      }),
 | 
				
			||||||
 | 
					      f'dock-{nm}': (self.step_dock, f'refuel-{nm}'),
 | 
				
			||||||
 | 
					      f'refuel-{nm}': (self.step_refuel, next_step)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
class MiningMission(BaseMission): 
 | 
					class MiningMission(BaseMission): 
 | 
				
			||||||
  @classmethod
 | 
					  @classmethod
 | 
				
			||||||
  def params(cls):
 | 
					  def params(cls):
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      'site': MissionParam(Waypoint, True),
 | 
					      'site': MissionParam(Waypoint, True),
 | 
				
			||||||
      'resource': MissionParam(str, True),
 | 
					      'resource': MissionParam(str, True),
 | 
				
			||||||
      'destination': MissionParam(Waypoint, True),
 | 
					      'dest': MissionParam(Waypoint, True),
 | 
				
			||||||
      'delivery': MissionParam(str, True, 'deliver'),
 | 
					      'delivery': MissionParam(str, True, 'deliver'),
 | 
				
			||||||
      'contract': MissionParam(Contract, False)
 | 
					      'contract': MissionParam(Contract, False)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  def start_state(self):
 | 
					  def start_state(self):
 | 
				
			||||||
    return 'go_site'
 | 
					    return 'travel-to'
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
  def steps(self):
 | 
					  def steps(self):
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
 | 
					      **self.travel_steps('to', 'site', 'extract'),
 | 
				
			||||||
      'extract': (self.step_extract, {
 | 
					      'extract': (self.step_extract, {
 | 
				
			||||||
        'done': 'dock',
 | 
					        'done': 'dock',
 | 
				
			||||||
        'more': 'extract'
 | 
					        'more': 'extract'
 | 
				
			||||||
@ -256,17 +270,13 @@ class MiningMission(BaseMission):
 | 
				
			|||||||
      'jettison': (self.step_dispose, {
 | 
					      'jettison': (self.step_dispose, {
 | 
				
			||||||
        'more': 'jettison',
 | 
					        'more': 'jettison',
 | 
				
			||||||
        'done': 'extract',
 | 
					        'done': 'extract',
 | 
				
			||||||
        'full': 'go_dest'
 | 
					        'full': 'travel-back'
 | 
				
			||||||
      }),
 | 
					      }),
 | 
				
			||||||
      'go_dest': (self.step_go_dest, 'dock_dest'),
 | 
					      **self.travel_steps('back', 'dest', 'unload'),
 | 
				
			||||||
      'dock_dest': (self.step_dock, 'unload'),
 | 
					 | 
				
			||||||
      'unload': (self.step_unload, {
 | 
					      'unload': (self.step_unload, {
 | 
				
			||||||
        'done': 'refuel',
 | 
					        'done': 'travel-to',
 | 
				
			||||||
        'more': 'unload'
 | 
					        'more': 'unload'
 | 
				
			||||||
      }),
 | 
					      }),
 | 
				
			||||||
      'refuel': (self.step_refuel, 'orbit_dest'),
 | 
					 | 
				
			||||||
      'orbit_dest': (self.step_orbit, 'go_site'),
 | 
					 | 
				
			||||||
      'go_site': (self.step_go_site, 'extract')
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  def get_survey(self):
 | 
					  def get_survey(self):
 | 
				
			||||||
@ -319,56 +329,38 @@ class SurveyMission(BaseMission):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class HaulMission(BaseMission):
 | 
					class HaulMission(BaseMission):
 | 
				
			||||||
  def start_state(self):
 | 
					  def start_state(self):
 | 
				
			||||||
    return 'orbit2'
 | 
					    return 'travel-to'
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  @classmethod
 | 
					  @classmethod
 | 
				
			||||||
  def params(cls):
 | 
					  def params(cls):
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      'site': MissionParam(Waypoint, True),
 | 
					      'site': MissionParam(Waypoint, True),
 | 
				
			||||||
      'resource': MissionParam(str, True),
 | 
					      'resource': MissionParam(str, True),
 | 
				
			||||||
      'destination': MissionParam(Waypoint, True),
 | 
					      'dest': MissionParam(Waypoint, True),
 | 
				
			||||||
      'delivery': MissionParam(str, True, 'deliver'),
 | 
					      'delivery': MissionParam(str, True, 'deliver'),
 | 
				
			||||||
      'contract': MissionParam(Contract, False)
 | 
					      'contract': MissionParam(Contract, False)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  def steps(self):
 | 
					  def steps(self):
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      'travel': (self.step_travel_site, {
 | 
					      **self.travel_steps('to', 'site', 'load'),
 | 
				
			||||||
        'more': 'travel',
 | 
					      'load': (self.step_load, 'travel-back'),
 | 
				
			||||||
        'done': 'dock'
 | 
					      **self.travel_steps('back', 'dest', 'load'),
 | 
				
			||||||
      }),
 | 
					      'unload': (self.step_unload, 'travel-to'),
 | 
				
			||||||
      'dock': (self.step_dock, 'refuel'),
 | 
					 | 
				
			||||||
      'refuel': (self.step_unload, 'load'),
 | 
					 | 
				
			||||||
      'load': (self.step_load, 'orbit'),
 | 
					 | 
				
			||||||
      'orbit': (self.step_orbit, 'travel_back'),
 | 
					 | 
				
			||||||
      'travel_back': (self.step_travel_dest, {
 | 
					 | 
				
			||||||
        'more': 'travel_back',
 | 
					 | 
				
			||||||
        'done': 'dock2'
 | 
					 | 
				
			||||||
      }),
 | 
					 | 
				
			||||||
      'dock2': (self.step_dock, 'unload'),
 | 
					 | 
				
			||||||
      'unload': (self.step_unload, 'refuel2'),
 | 
					 | 
				
			||||||
      'refuel2': (self.step_refuel, 'orbit2'),
 | 
					 | 
				
			||||||
      'orbit2': (self.step_orbit, 'travel')
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TravelMission(BaseMission):
 | 
					class TravelMission(BaseMission):
 | 
				
			||||||
  def start_state(self):
 | 
					  def start_state(self):
 | 
				
			||||||
    return 'orbit'
 | 
					    return 'travel-to'
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  @classmethod
 | 
					  @classmethod
 | 
				
			||||||
  def params(cls):
 | 
					  def params(cls):
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      'destination': MissionParam(Waypoint, True)
 | 
					      'dest': MissionParam(Waypoint, True)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  def steps(self):
 | 
					  def steps(self):
 | 
				
			||||||
    return {
 | 
					    return self.travel_steps('to', 'dest', 'done')
 | 
				
			||||||
      'orbit': (self.step_orbit, 'travel'),
 | 
					 | 
				
			||||||
      'travel': (self.step_travel_dest, {
 | 
					 | 
				
			||||||
        'more': 'travel',
 | 
					 | 
				
			||||||
        'done': 'done'
 | 
					 | 
				
			||||||
      })
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
def create_mission(mtype, ship, store, api):
 | 
					def create_mission(mtype, ship, store, api):
 | 
				
			||||||
  types = {
 | 
					  types = {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user