Fly me to the moon!
This commit is contained in:
parent
00db50687a
commit
3d3ceeab91
@ -83,9 +83,7 @@ class Analyzer:
|
|||||||
for s in jg.systems:
|
for s in jg.systems:
|
||||||
if s in seen: continue
|
if s in seen: continue
|
||||||
seen.add(s)
|
seen.add(s)
|
||||||
system = self.store.get(System, s)
|
dest.add(SearchNode(s, o))
|
||||||
if system is None: continue
|
|
||||||
dest.add(SearchNode(system, o))
|
|
||||||
if len(dest) == 0:
|
if len(dest) == 0:
|
||||||
return None
|
return None
|
||||||
return self.find_path(dest, to, depth-1, seen)
|
return self.find_path(dest, to, depth-1, seen)
|
||||||
|
@ -188,7 +188,7 @@ class BaseMission(Mission):
|
|||||||
self.sts('traject', None)
|
self.sts('traject', None)
|
||||||
return 'done'
|
return 'done'
|
||||||
hop = traject.pop(0)
|
hop = traject.pop(0)
|
||||||
if len(hop.split('-')) == 3:
|
if type(hop) == Waypoint:
|
||||||
self.api.navigate(self.ship, hop)
|
self.api.navigate(self.ship, hop)
|
||||||
self.next_step = self.ship.arrival
|
self.next_step = self.ship.arrival
|
||||||
else:
|
else:
|
||||||
@ -205,17 +205,18 @@ class BaseMission(Mission):
|
|||||||
loc = self.ship.location
|
loc = self.ship.location
|
||||||
loc_sys = loc.system
|
loc_sys = loc.system
|
||||||
loc_jg = self.analyzer.get_jumpgate(loc_sys)
|
loc_jg = self.analyzer.get_jumpgate(loc_sys)
|
||||||
|
loc_jg_wp = self.store.get(Waypoint, loc_jg.symbol)
|
||||||
dest_sys = dest.system
|
dest_sys = dest.system
|
||||||
dest_jg = self.analyzer.get_jumpgate(dest_sys)
|
dest_jg = self.analyzer.get_jumpgate(dest_sys)
|
||||||
if dest_sys == loc_sys:
|
if dest_sys == loc_sys:
|
||||||
result = [dest.symbol]
|
result = [dest]
|
||||||
self.sts('traject', result)
|
self.sts('traject', result)
|
||||||
return
|
return
|
||||||
path = self.analyzer.find_path(loc_sys, dest_sys)
|
path = self.analyzer.find_path(loc_sys, dest_sys)
|
||||||
result = []
|
result = []
|
||||||
if loc.symbol != loc_jg.symbol:
|
if loc.symbol != loc_jg.symbol:
|
||||||
result.append(loc_jg)
|
result.append(loc_jg_wp)
|
||||||
result += [s.symbol for s in path[1:]]
|
result += [s for s in path[1:]]
|
||||||
if dest_jg.symbol != dest.symbol:
|
if dest_jg.symbol != dest.symbol:
|
||||||
result.append(dest)
|
result.append(dest)
|
||||||
self.sts('traject', result)
|
self.sts('traject', result)
|
||||||
|
@ -41,6 +41,12 @@ class Base:
|
|||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return type(self) == type(other) and self.symbol == other.symbol
|
return type(self) == type(other) and self.symbol == other.symbol
|
||||||
|
|
||||||
|
def get_system(self):
|
||||||
|
parts = self.symbol.split('-')
|
||||||
|
system_str = f'{parts[0]}-{parts[1]}'
|
||||||
|
system = self.store.get('System', system_str, create=True)
|
||||||
|
return system
|
||||||
|
|
||||||
def seta(self, attr, d, name=None, interp=None):
|
def seta(self, attr, d, name=None, interp=None):
|
||||||
if name is None:
|
if name is None:
|
||||||
@ -51,10 +57,15 @@ class Base:
|
|||||||
val = interp(val)
|
val = interp(val)
|
||||||
setattr(self, attr, val)
|
setattr(self, attr, val)
|
||||||
|
|
||||||
def setlst(self, attr, d, name, member):
|
def setlst(self, attr, d, name, member, interp=None):
|
||||||
val = sg(d, name)
|
val = sg(d, name)
|
||||||
if val is not None:
|
if val is not None:
|
||||||
lst = [sg(x, member) for x in val]
|
lst = []
|
||||||
|
for x in val:
|
||||||
|
val = sg(x, member)
|
||||||
|
if interp is not None:
|
||||||
|
val = interp(val)
|
||||||
|
lst.append(val)
|
||||||
setattr(self, attr, lst)
|
setattr(self, attr, lst)
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
@ -87,6 +98,9 @@ class Base:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.f()
|
return self.f()
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return self.f()
|
||||||
|
|
||||||
def f(self, detail=1):
|
def f(self, detail=1):
|
||||||
r = self.symbol
|
r = self.symbol
|
||||||
if detail > 1:
|
if detail > 1:
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from .base import Base
|
from .base import Base
|
||||||
|
from .system import System
|
||||||
from dataclasses import field
|
from dataclasses import field
|
||||||
|
|
||||||
class Jumpgate(Base):
|
class Jumpgate(Base):
|
||||||
@ -6,9 +7,11 @@ class Jumpgate(Base):
|
|||||||
self.range: int = 0
|
self.range: int = 0
|
||||||
self.faction: str = ''
|
self.faction: str = ''
|
||||||
self.systems: list = []
|
self.systems: list = []
|
||||||
|
self.system = self.get_system()
|
||||||
|
|
||||||
def update(self, d):
|
def update(self, d):
|
||||||
self.setlst('systems', d, 'connectedSystems', 'symbol')
|
getter = self.store.getter(System, create=True)
|
||||||
|
self.setlst('systems', d, 'connectedSystems', 'symbol', interp=getter)
|
||||||
self.seta('faction', d, 'factionSymbol')
|
self.seta('faction', d, 'factionSymbol')
|
||||||
self.seta('range', d, 'jumpRange')
|
self.seta('range', d, 'jumpRange')
|
||||||
|
|
||||||
@ -20,5 +23,5 @@ class Jumpgate(Base):
|
|||||||
r = self.symbol
|
r = self.symbol
|
||||||
if detail > 1:
|
if detail > 1:
|
||||||
r += '\n'
|
r += '\n'
|
||||||
r += '\n'.join(self.systems)
|
r += '\n'.join([s.symbol for s in self.systems])
|
||||||
return r
|
return r
|
||||||
|
@ -13,6 +13,7 @@ class Marketplace(Base):
|
|||||||
self.prices:dict = {}
|
self.prices:dict = {}
|
||||||
self.last_prices:int = 0
|
self.last_prices:int = 0
|
||||||
self.set_waypoint()
|
self.set_waypoint()
|
||||||
|
self.system = self.get_system()
|
||||||
|
|
||||||
def set_waypoint(self):
|
def set_waypoint(self):
|
||||||
waypoint = self.store.get(Waypoint, self.symbol, create=True)
|
waypoint = self.store.get(Waypoint, self.symbol, create=True)
|
||||||
|
@ -9,7 +9,7 @@ class Waypoint(Base):
|
|||||||
self.type:str = 'unknown'
|
self.type:str = 'unknown'
|
||||||
self.traits:list = []
|
self.traits:list = []
|
||||||
self.faction:str = ''
|
self.faction:str = ''
|
||||||
self.set_system()
|
self.system = self.get_system()
|
||||||
|
|
||||||
def update(self, d):
|
def update(self, d):
|
||||||
self.seta('x', d)
|
self.seta('x', d)
|
||||||
@ -18,12 +18,6 @@ class Waypoint(Base):
|
|||||||
self.seta('faction', d, 'faction.symbol')
|
self.seta('faction', d, 'faction.symbol')
|
||||||
self.setlst('traits', d, 'traits', 'symbol')
|
self.setlst('traits', d, 'traits', 'symbol')
|
||||||
|
|
||||||
def set_system(self):
|
|
||||||
parts = self.symbol.split('-')
|
|
||||||
system_str = f'{parts[0]}-{parts[1]}'
|
|
||||||
system = self.store.get(System, system_str, create=True)
|
|
||||||
self.system = system
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def ext(self):
|
def ext(self):
|
||||||
return 'way'
|
return 'way'
|
||||||
|
@ -160,7 +160,6 @@ class Store:
|
|||||||
symbol = obj.symbol
|
symbol = obj.symbol
|
||||||
obj.store = self
|
obj.store = self
|
||||||
self.data[typ][symbol] = obj
|
self.data[typ][symbol] = obj
|
||||||
print(type(obj).__name__, 'has?')
|
|
||||||
if hasattr(obj, 'system') and obj.system != None:
|
if hasattr(obj, 'system') and obj.system != None:
|
||||||
system_str = obj.system.symbol
|
system_str = obj.system.symbol
|
||||||
if system_str not in self.system_members:
|
if system_str not in self.system_members:
|
||||||
|
Loading…
Reference in New Issue
Block a user