small improvementss
This commit is contained in:
parent
b5b736df63
commit
02f206d078
@ -191,7 +191,7 @@ class Analyzer:
|
||||
dist = swp.distance(dwp)
|
||||
dist = max(dist, 0.0001)
|
||||
score = margin / dist
|
||||
if margin < 0:
|
||||
if margin < 2:
|
||||
continue
|
||||
o = TradeOption(resource, swp, dwp, source['buy'], margin, dist, score)
|
||||
if best is None or best.score < o.score:
|
||||
|
@ -28,6 +28,8 @@ class Commander(CommandLine):
|
||||
self.agent = self.select_agent()
|
||||
self.api = Api(self.store, self.agent)
|
||||
self.centcom = CentralCommand(self.store, self.api)
|
||||
self.api.info()
|
||||
self.do_create_crews()
|
||||
self.analyzer = Analyzer(self.store)
|
||||
self.ship = None
|
||||
|
||||
@ -141,7 +143,7 @@ class Commander(CommandLine):
|
||||
print(agent)
|
||||
print('=== ships')
|
||||
self.do_ships('r')
|
||||
self.do_create_crews()
|
||||
|
||||
print('=== contracts')
|
||||
self.do_contracts('r')
|
||||
ship = self.store.get(Ship, symbol.upper() + '-2')
|
||||
@ -209,14 +211,11 @@ class Commander(CommandLine):
|
||||
r = self.api.list_waypoints(system)
|
||||
pprint(r)
|
||||
|
||||
def do_waypoints(self, system_str=''):
|
||||
def do_waypoints(self, grep=''):
|
||||
loc = None
|
||||
if system_str == '':
|
||||
ship = self.has_ship()
|
||||
loc = ship.location
|
||||
system = loc.system
|
||||
else:
|
||||
system = self.store.get(System, system_str)
|
||||
ship = self.has_ship()
|
||||
loc = ship.location
|
||||
system = loc.system
|
||||
print(f'=== waypoints in {system}')
|
||||
r = self.store.all_members(system, 'Waypoint')
|
||||
for w in r:
|
||||
@ -226,19 +225,22 @@ class Commander(CommandLine):
|
||||
typ = w.type[0]
|
||||
if typ not in ['F','J'] and len(traits) == 0:
|
||||
continue
|
||||
output = ''
|
||||
if loc:
|
||||
dist = loc.distance(w)
|
||||
print(f'{wname:4} {typ} {dist:6} {traits}')
|
||||
output = f'{wname:4} {typ} {dist:6} {traits}'
|
||||
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):
|
||||
ship = self.has_ship()
|
||||
system = ship.location.system
|
||||
pprint(list(self.store.all_members(system)))
|
||||
|
||||
def do_wp(self, s=''):
|
||||
self.do_waypoints(s)
|
||||
def do_wp(self, grep=''):
|
||||
self.do_waypoints(grep)
|
||||
|
||||
######## Specials #########
|
||||
def do_market(self, arg=''):
|
||||
|
@ -6,6 +6,7 @@ from nullptr.missions.probe import ProbeMission
|
||||
from nullptr.missions.idle import IdleMission
|
||||
from nullptr.missions.siphon import SiphonMission
|
||||
from nullptr.missions.haul import HaulMission
|
||||
from nullptr.missions.sit import SitMission
|
||||
|
||||
def get_mission_class( mtype):
|
||||
types = {
|
||||
@ -17,6 +18,7 @@ def get_mission_class( mtype):
|
||||
'idle': IdleMission,
|
||||
'siphon': SiphonMission,
|
||||
'haul': HaulMission,
|
||||
'sit': SitMission,
|
||||
|
||||
}
|
||||
if mtype not in types:
|
||||
|
@ -175,6 +175,9 @@ class BaseMission(Mission):
|
||||
self.sts('balance', balance)
|
||||
return balance
|
||||
|
||||
def step_pass(self):
|
||||
pass
|
||||
|
||||
def step_go_dest(self):
|
||||
destination = self.rst(Waypoint, 'destination')
|
||||
if self.ship.location() == destination:
|
||||
|
23
nullptr/missions/sit.py
Normal file
23
nullptr/missions/sit.py
Normal 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
|
||||
|
||||
|
@ -33,7 +33,7 @@ class MarketEntry:
|
||||
self.volume = volume
|
||||
self.supply = supply
|
||||
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):
|
||||
|
@ -174,15 +174,15 @@ class Store:
|
||||
return hdr
|
||||
|
||||
def purge(self, obj):
|
||||
if obj._file_offset is None:
|
||||
return
|
||||
self.fil.seek(obj._file_offset)
|
||||
hdr = ChunkHeader.parse(self.fil)
|
||||
hdr.in_use = False
|
||||
self.fil.seek(obj._file_offset)
|
||||
hdr.write(self.fil)
|
||||
if obj._file_offset is not None:
|
||||
self.fil.seek(obj._file_offset)
|
||||
hdr = ChunkHeader.parse(self.fil)
|
||||
hdr.in_use = False
|
||||
self.fil.seek(obj._file_offset)
|
||||
hdr.write(self.fil)
|
||||
if type(obj) in self.data and obj.symbol in self.data[type(obj)]:
|
||||
del self.data[type(obj)][obj.symbol]
|
||||
self.remove_from_members(obj)
|
||||
if obj in self.dirty_objects:
|
||||
self.dirty_objects.remove(obj)
|
||||
obj._file_offset = None
|
||||
@ -214,7 +214,14 @@ class Store:
|
||||
self.fil.write(data)
|
||||
slack = b'\x00' * (hdr.size - hdr.used)
|
||||
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):
|
||||
typ = type(obj)
|
||||
symbol = obj.symbol
|
||||
@ -316,7 +323,7 @@ class Store:
|
||||
for obj in copy(self.dirty_objects):
|
||||
it += 1
|
||||
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
|
||||
self.store(obj)
|
||||
self.fil.flush()
|
||||
@ -334,6 +341,6 @@ class Store:
|
||||
os.rename(nm, nm + '.bak')
|
||||
self.fil = open_file(nm)
|
||||
for t in self.data:
|
||||
for o in self.all(t):
|
||||
for o in self.data[t].values():
|
||||
o._file_offset = None
|
||||
self.store(o)
|
||||
|
Loading…
Reference in New Issue
Block a user