small improvementss

This commit is contained in:
Richard 2024-02-01 18:51:27 +01:00
parent b5b736df63
commit 02f206d078
7 changed files with 61 additions and 24 deletions

View File

@ -191,7 +191,7 @@ class Analyzer:
dist = swp.distance(dwp) dist = swp.distance(dwp)
dist = max(dist, 0.0001) dist = max(dist, 0.0001)
score = margin / dist score = margin / dist
if margin < 0: if margin < 2:
continue continue
o = TradeOption(resource, swp, dwp, source['buy'], margin, dist, score) o = TradeOption(resource, swp, dwp, source['buy'], margin, dist, score)
if best is None or best.score < o.score: if best is None or best.score < o.score:

View File

@ -28,6 +28,8 @@ class Commander(CommandLine):
self.agent = self.select_agent() self.agent = self.select_agent()
self.api = Api(self.store, self.agent) self.api = Api(self.store, self.agent)
self.centcom = CentralCommand(self.store, self.api) self.centcom = CentralCommand(self.store, self.api)
self.api.info()
self.do_create_crews()
self.analyzer = Analyzer(self.store) self.analyzer = Analyzer(self.store)
self.ship = None self.ship = None
@ -141,7 +143,7 @@ class Commander(CommandLine):
print(agent) print(agent)
print('=== ships') print('=== ships')
self.do_ships('r') self.do_ships('r')
self.do_create_crews()
print('=== contracts') print('=== contracts')
self.do_contracts('r') self.do_contracts('r')
ship = self.store.get(Ship, symbol.upper() + '-2') ship = self.store.get(Ship, symbol.upper() + '-2')
@ -209,14 +211,11 @@ class Commander(CommandLine):
r = self.api.list_waypoints(system) r = self.api.list_waypoints(system)
pprint(r) pprint(r)
def do_waypoints(self, system_str=''): def do_waypoints(self, grep=''):
loc = None loc = None
if system_str == '': ship = self.has_ship()
ship = self.has_ship() loc = ship.location
loc = ship.location system = loc.system
system = loc.system
else:
system = self.store.get(System, system_str)
print(f'=== waypoints in {system}') 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:
@ -226,19 +225,22 @@ class Commander(CommandLine):
typ = w.type[0] typ = w.type[0]
if typ not in ['F','J'] and len(traits) == 0: if typ not in ['F','J'] and len(traits) == 0:
continue continue
output = ''
if loc: if loc:
dist = loc.distance(w) dist = loc.distance(w)
print(f'{wname:4} {typ} {dist:6} {traits}') output = f'{wname:4} {typ} {dist:6} {traits}'
else: else:
print(f'{wname:4} {typ} {traits}') output = f'{wname:4} {typ} {traits}'
if grep == '' or grep.lower() in output.lower():
print(output)
def do_members(self): def do_members(self):
ship = self.has_ship() ship = self.has_ship()
system = ship.location.system system = ship.location.system
pprint(list(self.store.all_members(system))) pprint(list(self.store.all_members(system)))
def do_wp(self, s=''): def do_wp(self, grep=''):
self.do_waypoints(s) self.do_waypoints(grep)
######## Specials ######### ######## Specials #########
def do_market(self, arg=''): def do_market(self, arg=''):

View File

@ -6,6 +6,7 @@ from nullptr.missions.probe import ProbeMission
from nullptr.missions.idle import IdleMission from nullptr.missions.idle import IdleMission
from nullptr.missions.siphon import SiphonMission from nullptr.missions.siphon import SiphonMission
from nullptr.missions.haul import HaulMission from nullptr.missions.haul import HaulMission
from nullptr.missions.sit import SitMission
def get_mission_class( mtype): def get_mission_class( mtype):
types = { types = {
@ -17,6 +18,7 @@ def get_mission_class( mtype):
'idle': IdleMission, 'idle': IdleMission,
'siphon': SiphonMission, 'siphon': SiphonMission,
'haul': HaulMission, 'haul': HaulMission,
'sit': SitMission,
} }
if mtype not in types: if mtype not in types:

View File

@ -175,6 +175,9 @@ class BaseMission(Mission):
self.sts('balance', balance) self.sts('balance', balance)
return balance return balance
def step_pass(self):
pass
def step_go_dest(self): def step_go_dest(self):
destination = self.rst(Waypoint, 'destination') destination = self.rst(Waypoint, 'destination')
if self.ship.location() == destination: if self.ship.location() == destination:

23
nullptr/missions/sit.py Normal file
View File

@ -0,0 +1,23 @@
from nullptr.missions.base import BaseMission, MissionParam
from nullptr.models.waypoint import Waypoint
class SitMission(BaseMission):
def start_state(self):
return 'travel-to'
@classmethod
def params(cls):
return {
'dest': MissionParam(Waypoint, True)
}
def steps(self):
return {
**self.travel_steps('to', 'dest', 'sit'),
'sit': (self.step_pass, 'done', self.wait_forever)
}
def wait_forever(self):
return 0

View File

@ -33,7 +33,7 @@ class MarketEntry:
self.volume = volume self.volume = volume
self.supply = supply self.supply = supply
self.activity = activity self.activity = activity
self.history.append((int(time()), buy, sell, volume, supply, activity)) #self.history.append((int(time()), buy, sell, volume, supply, activity))
class Marketplace(Base): class Marketplace(Base):

View File

@ -174,15 +174,15 @@ class Store:
return hdr return hdr
def purge(self, obj): def purge(self, obj):
if obj._file_offset is None: if obj._file_offset is not None:
return self.fil.seek(obj._file_offset)
self.fil.seek(obj._file_offset) hdr = ChunkHeader.parse(self.fil)
hdr = ChunkHeader.parse(self.fil) hdr.in_use = False
hdr.in_use = False self.fil.seek(obj._file_offset)
self.fil.seek(obj._file_offset) hdr.write(self.fil)
hdr.write(self.fil)
if type(obj) in self.data and obj.symbol in self.data[type(obj)]: if type(obj) in self.data and obj.symbol in self.data[type(obj)]:
del self.data[type(obj)][obj.symbol] del self.data[type(obj)][obj.symbol]
self.remove_from_members(obj)
if obj in self.dirty_objects: if obj in self.dirty_objects:
self.dirty_objects.remove(obj) self.dirty_objects.remove(obj)
obj._file_offset = None obj._file_offset = None
@ -215,6 +215,13 @@ class Store:
slack = b'\x00' * (hdr.size - hdr.used) slack = b'\x00' * (hdr.size - hdr.used)
self.fil.write(slack) self.fil.write(slack)
def remove_from_members(self, obj):
if type(obj).__name__ in ['Waypoint','Marketplace', 'Jumpgate', 'Survey']:
system_str = obj.system.symbol
if system_str not in self.system_members:
return
self.system_members[system_str].remove(obj)
def hold(self, obj): def hold(self, obj):
typ = type(obj) typ = type(obj)
symbol = obj.symbol symbol = obj.symbol
@ -316,7 +323,7 @@ class Store:
for obj in copy(self.dirty_objects): for obj in copy(self.dirty_objects):
it += 1 it += 1
if obj.symbol not in self.data[type(obj)] or self.data[type(obj)][obj.symbol] != obj: if obj.symbol not in self.data[type(obj)] or self.data[type(obj)][obj.symbol] != obj:
print(f"Dirty object not in data {type(obj)} {obj.symbol} {obj}") # print(f"Dirty object not in data {type(obj)} {obj.symbol} {obj}")
continue continue
self.store(obj) self.store(obj)
self.fil.flush() self.fil.flush()
@ -334,6 +341,6 @@ class Store:
os.rename(nm, nm + '.bak') os.rename(nm, nm + '.bak')
self.fil = open_file(nm) self.fil = open_file(nm)
for t in self.data: for t in self.data:
for o in self.all(t): for o in self.data[t].values():
o._file_offset = None o._file_offset = None
self.store(o) self.store(o)