Fly me to the moon!

This commit is contained in:
Richard Bronkhorst 2023-07-12 22:26:25 +02:00
parent 00db50687a
commit 3d3ceeab91
7 changed files with 29 additions and 19 deletions

View File

@ -83,9 +83,7 @@ class Analyzer:
for s in jg.systems:
if s in seen: continue
seen.add(s)
system = self.store.get(System, s)
if system is None: continue
dest.add(SearchNode(system, o))
dest.add(SearchNode(s, o))
if len(dest) == 0:
return None
return self.find_path(dest, to, depth-1, seen)

View File

@ -188,7 +188,7 @@ class BaseMission(Mission):
self.sts('traject', None)
return 'done'
hop = traject.pop(0)
if len(hop.split('-')) == 3:
if type(hop) == Waypoint:
self.api.navigate(self.ship, hop)
self.next_step = self.ship.arrival
else:
@ -205,17 +205,18 @@ class BaseMission(Mission):
loc = self.ship.location
loc_sys = loc.system
loc_jg = self.analyzer.get_jumpgate(loc_sys)
loc_jg_wp = self.store.get(Waypoint, loc_jg.symbol)
dest_sys = dest.system
dest_jg = self.analyzer.get_jumpgate(dest_sys)
if dest_sys == loc_sys:
result = [dest.symbol]
result = [dest]
self.sts('traject', result)
return
path = self.analyzer.find_path(loc_sys, dest_sys)
result = []
if loc.symbol != loc_jg.symbol:
result.append(loc_jg)
result += [s.symbol for s in path[1:]]
result.append(loc_jg_wp)
result += [s for s in path[1:]]
if dest_jg.symbol != dest.symbol:
result.append(dest)
self.sts('traject', result)

View File

@ -41,6 +41,12 @@ class Base:
def __eq__(self, other):
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):
if name is None:
@ -51,10 +57,15 @@ class Base:
val = interp(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)
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)
def __setattr__(self, name, value):
@ -87,6 +98,9 @@ class Base:
def __str__(self):
return self.f()
def __repr__(self):
return self.f()
def f(self, detail=1):
r = self.symbol
if detail > 1:

View File

@ -1,4 +1,5 @@
from .base import Base
from .system import System
from dataclasses import field
class Jumpgate(Base):
@ -6,9 +7,11 @@ class Jumpgate(Base):
self.range: int = 0
self.faction: str = ''
self.systems: list = []
self.system = self.get_system()
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('range', d, 'jumpRange')
@ -20,5 +23,5 @@ class Jumpgate(Base):
r = self.symbol
if detail > 1:
r += '\n'
r += '\n'.join(self.systems)
r += '\n'.join([s.symbol for s in self.systems])
return r

View File

@ -13,6 +13,7 @@ class Marketplace(Base):
self.prices:dict = {}
self.last_prices:int = 0
self.set_waypoint()
self.system = self.get_system()
def set_waypoint(self):
waypoint = self.store.get(Waypoint, self.symbol, create=True)

View File

@ -9,7 +9,7 @@ class Waypoint(Base):
self.type:str = 'unknown'
self.traits:list = []
self.faction:str = ''
self.set_system()
self.system = self.get_system()
def update(self, d):
self.seta('x', d)
@ -18,12 +18,6 @@ class Waypoint(Base):
self.seta('faction', d, 'faction.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
def ext(self):
return 'way'

View File

@ -160,7 +160,6 @@ class Store:
symbol = obj.symbol
obj.store = self
self.data[typ][symbol] = obj
print(type(obj).__name__, 'has?')
if hasattr(obj, 'system') and obj.system != None:
system_str = obj.system.symbol
if system_str not in self.system_members: