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