Update atlas_builder.py, commander.py and eleven other files
This commit is contained in:
parent
97296e1859
commit
00db50687a
@ -26,7 +26,6 @@ class AtlasBuilder:
|
||||
|
||||
def all_specials(self, waypoints):
|
||||
for w in waypoints:
|
||||
print(w)
|
||||
if self.stop_auto:
|
||||
break
|
||||
if 'UNCHARTED' in w.traits:
|
||||
|
@ -50,12 +50,23 @@ class Commander(CommandLine):
|
||||
agents = self.store.all(Agent)
|
||||
agent = next(agents, None)
|
||||
if agent is None:
|
||||
symbol = input('agent name: ')
|
||||
agent = self.store.get(Agent, symbol, create=True)
|
||||
api = Api(self.store, agent)
|
||||
faction = input('faction: ')
|
||||
api.register(faction.upper().strip())
|
||||
self.store.flush()
|
||||
agent = self.agent_setup()
|
||||
return agent
|
||||
|
||||
def agent_setup(self):
|
||||
symbol = input('agent name: ')
|
||||
agent = self.store.get(Agent, symbol, create=True)
|
||||
api = Api(self.store, agent)
|
||||
self.api = api
|
||||
faction = input('faction: ')
|
||||
api.register(faction.upper().strip())
|
||||
print('=== agent:')
|
||||
print(agent)
|
||||
print('=== ships')
|
||||
self.do_ships('r')
|
||||
print('=== contracts')
|
||||
self.do_contracts('r')
|
||||
self.store.flush()
|
||||
return agent
|
||||
|
||||
def resolve(self, typ, arg):
|
||||
@ -194,6 +205,7 @@ class Commander(CommandLine):
|
||||
system = self.ship.location.system
|
||||
else:
|
||||
system = self.store.get(System, system_str)
|
||||
print(f'=== waypoints in {system}')
|
||||
r = self.store.all_members(system, 'Waypoint')
|
||||
for w in r:
|
||||
traits = []
|
||||
|
@ -8,9 +8,6 @@ class Agent(Base):
|
||||
def update(self, d):
|
||||
self.seta('credits', d)
|
||||
|
||||
def path(self):
|
||||
return f'{self.symbol}.{self.ext()}'
|
||||
|
||||
@classmethod
|
||||
def ext(self):
|
||||
return 'agt'
|
||||
|
@ -40,7 +40,7 @@ class Base:
|
||||
return hash((str(type(self)), self.symbol))
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.symbol == other.symbol and type(self) == type(other)
|
||||
return type(self) == type(other) and self.symbol == other.symbol
|
||||
|
||||
def seta(self, attr, d, name=None, interp=None):
|
||||
if name is None:
|
||||
|
@ -18,9 +18,6 @@ class Contract(Base):
|
||||
def ext(cls):
|
||||
return 'cnt'
|
||||
|
||||
def path(self):
|
||||
return f'contracts/{self.symbol}.{self.ext()}'
|
||||
|
||||
def is_expired(self):
|
||||
return time() > self.expires
|
||||
|
||||
|
@ -16,10 +16,6 @@ class Jumpgate(Base):
|
||||
def ext(self):
|
||||
return 'jmp'
|
||||
|
||||
def path(self):
|
||||
sector, system, _ = self.symbol.split('-')
|
||||
return f'atlas/{sector}/{system[0:1]}/{system}/{self.symbol}.{self.ext()}'
|
||||
|
||||
def f(self, detail=1):
|
||||
r = self.symbol
|
||||
if detail > 1:
|
||||
|
@ -50,10 +50,6 @@ class Marketplace(Base):
|
||||
if r in self.exchange:
|
||||
return 'X'
|
||||
return '?'
|
||||
|
||||
def path(self):
|
||||
sector, system, _ = self.symbol.split('-')
|
||||
return f'atlas/{sector}/{system[0:1]}/{system}/{self.symbol}.{self.ext()}'
|
||||
|
||||
def f(self, detail=1):
|
||||
r = self.symbol
|
||||
|
@ -21,11 +21,7 @@ class Ship(Base):
|
||||
@classmethod
|
||||
def ext(self):
|
||||
return 'shp'
|
||||
|
||||
def path(self):
|
||||
agent = self.symbol.split('-')[0]
|
||||
return f'{agent}/{self.symbol}.{self.ext()}'
|
||||
|
||||
|
||||
def update(self, d):
|
||||
self.seta('status', d, 'nav.status')
|
||||
getter = self.store.getter(Waypoint, create=True)
|
||||
|
@ -17,12 +17,7 @@ class Survey(Base):
|
||||
@classmethod
|
||||
def ext(cls):
|
||||
return 'svy'
|
||||
|
||||
def path(self):
|
||||
sector, system, waypoint, signature = self.symbol.split('-')
|
||||
return f'atlas/{sector}/{system[0:1]}/{system}/{self.symbol}.{self.ext()}'
|
||||
|
||||
|
||||
|
||||
def is_expired(self):
|
||||
return time() > self.expires or self.exhausted
|
||||
|
||||
|
@ -17,10 +17,6 @@ class System(Base):
|
||||
def ext(self):
|
||||
return 'stm'
|
||||
|
||||
def path(self):
|
||||
sector, symbol = self.symbol.split('-')
|
||||
return f'atlas/{sector}/{symbol[0:1]}/{self.symbol}.{self.ext()}'
|
||||
|
||||
def distance(self, other):
|
||||
return int(sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2))
|
||||
|
||||
|
@ -28,6 +28,3 @@ class Waypoint(Base):
|
||||
def ext(self):
|
||||
return 'way'
|
||||
|
||||
def path(self):
|
||||
sector, system, _ = self.symbol.split('-')
|
||||
return f'atlas/{sector}/{system[0:1]}/{system}/{self.symbol}.{self.ext()}'
|
||||
|
@ -99,7 +99,7 @@ class Store:
|
||||
self.fil.seek(0)
|
||||
offset = 0
|
||||
while (hdr := ChunkHeader.parse(self.fil)):
|
||||
print(hdr)
|
||||
# print(hdr)
|
||||
if not hdr.in_use:
|
||||
self.fil.seek(hdr.size, 1)
|
||||
continue
|
||||
@ -150,7 +150,7 @@ class Store:
|
||||
|
||||
if obj.file_offset is None:
|
||||
obj.file_offset, hdr = self.allocate_chunk(osize)
|
||||
print(type(obj).__name__, hdr)
|
||||
# print(type(obj).__name__, hdr)
|
||||
self.fil.write(data)
|
||||
slack = b'\x00' * (hdr.size - hdr.used)
|
||||
self.fil.write(slack)
|
||||
@ -160,7 +160,8 @@ class Store:
|
||||
symbol = obj.symbol
|
||||
obj.store = self
|
||||
self.data[typ][symbol] = obj
|
||||
if hasattr(typ, 'system'):
|
||||
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:
|
||||
self.system_members[system_str] = set()
|
||||
@ -215,10 +216,10 @@ class Store:
|
||||
|
||||
if type(system) == System:
|
||||
system = system.symbol
|
||||
|
||||
if 'system' not in self.system_members:
|
||||
|
||||
if system not in self.system_members:
|
||||
return
|
||||
print('typ', typ)
|
||||
|
||||
for m in self.system_members[system]:
|
||||
if typ is None or type(m) == typ:
|
||||
yield m
|
||||
|
@ -53,7 +53,7 @@ def pretty(d, ident=0, detail=2):
|
||||
return d.f(detail)
|
||||
r = ''
|
||||
idt = ' ' * ident
|
||||
if type(d) == list:
|
||||
if type(d) in [list, set]:
|
||||
r += 'lst'
|
||||
for i in d:
|
||||
r += '\n' + idt + pretty(i, ident + 1, detail)
|
||||
|
Loading…
Reference in New Issue
Block a user