2024-02-09 14:52:30 +00:00
|
|
|
from nullptr.util import *
|
|
|
|
from nullptr.analyzer import find_gas, find_metal
|
|
|
|
class GeneralError(AppError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class General:
|
|
|
|
def __init__(self, context):
|
|
|
|
self.store = context.store
|
|
|
|
self.api = context.api
|
|
|
|
self.c = context
|
|
|
|
agents = self.store.all('Agent')
|
|
|
|
self.agent = next(agents, None)
|
|
|
|
self.phases = {
|
|
|
|
'init': self.phase_startup,
|
|
|
|
'probes': self.phase_probes,
|
|
|
|
'trade': self.phase_trade,
|
|
|
|
'mine': self.phase_mine,
|
|
|
|
'siphon': self.phase_siphon,
|
|
|
|
'rampup': self.phase_rampup,
|
|
|
|
'gate': self.phase_gate
|
|
|
|
}
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
self.create_default_crews()
|
|
|
|
|
|
|
|
def find_shipyard(self, stype):
|
2024-02-11 13:37:46 +00:00
|
|
|
occ = [s.location.symbol for s in self.store.all('Ship') if s.status != 'IN_TRANSIT']
|
|
|
|
best_price = -1
|
|
|
|
best_yard = None
|
2024-02-09 14:52:30 +00:00
|
|
|
for shipyard in self.store.all('Shipyard'):
|
2024-02-11 13:37:46 +00:00
|
|
|
if stype in shipyard.prices:
|
|
|
|
price = shipyard.prices[stype]
|
|
|
|
if shipyard.symbol in occ:
|
|
|
|
if best_yard is None or price < best_price:
|
|
|
|
best_yard = shipyard
|
|
|
|
best_price = price
|
|
|
|
return best_yard, best_price
|
2024-02-09 14:52:30 +00:00
|
|
|
|
2024-02-11 13:37:46 +00:00
|
|
|
def maybe_purchase(self, stype, role):
|
|
|
|
sy, price = self.find_shipyard(stype)
|
|
|
|
if sy is None:
|
|
|
|
return False
|
|
|
|
traders = [s for s in self.store.all('Ship') if s.role == 'trader']
|
|
|
|
safe_buffer = len(traders) * 100000 + 100000
|
|
|
|
|
|
|
|
if self.agent.credits < safe_buffer + price:
|
|
|
|
return # cant afford it!
|
|
|
|
ship = self.c.api.purchase(stype, sy)
|
|
|
|
ship.role = role
|
2024-02-09 14:52:30 +00:00
|
|
|
|
|
|
|
def tick(self):
|
|
|
|
phase = self.agent.phase
|
|
|
|
if phase not in self.phases:
|
|
|
|
raise GeneralError('Invalid phase')
|
|
|
|
hdl = self.phases[phase]
|
|
|
|
new_phase = hdl()
|
|
|
|
if new_phase:
|
|
|
|
self.agent.phase = new_phase
|
|
|
|
|
|
|
|
|
|
|
|
def phase_startup(self):
|
|
|
|
# * first pricing info
|
|
|
|
# * probe at shipyard that sells probes
|
|
|
|
ag = self.agent.symbol
|
|
|
|
command = self.store.get('Ship', f'{ag}-1')
|
|
|
|
probe = self.store.get('Ship', f'{ag}-2')
|
2024-02-10 18:29:11 +00:00
|
|
|
if command.role is None:
|
|
|
|
command.role = 'probe'
|
|
|
|
if probe.role is None:
|
|
|
|
probe.role = 'sitter'
|
2024-02-11 13:37:46 +00:00
|
|
|
system = command.location.system
|
|
|
|
markets = list(self.store.all_members(system, 'Marketplace'))
|
|
|
|
discovered = len([m for m in markets if m.last_prices > 0])
|
|
|
|
if discovered > len(markets) // 2:
|
|
|
|
return 'probes'
|
2024-02-09 14:52:30 +00:00
|
|
|
|
|
|
|
def phase_probes(self):
|
2024-02-11 13:37:46 +00:00
|
|
|
ag = self.agent.symbol
|
|
|
|
command = self.store.get('Ship', f'{ag}-1')
|
2024-02-09 14:52:30 +00:00
|
|
|
# * probes on all markets
|
2024-02-11 13:37:46 +00:00
|
|
|
if command.role != 'trader':
|
|
|
|
command.role = 'trader'
|
|
|
|
self.c.captain.init_mission(command, 'none')
|
|
|
|
self.maybe_purchase('SHIP_PROBE', 'sitter')
|
|
|
|
sitters = [s for s in self.store.all('Ship') if s.role == 'sitter']
|
|
|
|
markets = [m for m in self.store.all('Marketplace')]
|
|
|
|
if len(sitters) >= len(markets):
|
|
|
|
return 'trade'
|
|
|
|
|
2024-02-09 14:52:30 +00:00
|
|
|
def phase_trade(self):
|
|
|
|
# 20? traders
|
|
|
|
pass
|
|
|
|
|
|
|
|
def phase_mine(self):
|
|
|
|
# metal mining crew
|
|
|
|
pass
|
|
|
|
|
|
|
|
def phase_siphon(self):
|
|
|
|
# siphon crew
|
|
|
|
pass
|
|
|
|
|
|
|
|
def phase_rampup(self):
|
|
|
|
# stimulate markets for gate building
|
|
|
|
pass
|
|
|
|
|
|
|
|
def phase_gate(self):
|
|
|
|
# build the gate
|
|
|
|
pass
|
|
|
|
|
|
|
|
def create_default_crews(self):
|
|
|
|
system = self.api.agent.headquarters.system
|
|
|
|
gas_w = find_gas(self.c, system)
|
|
|
|
metal_w = find_metal(self.c, system)
|
|
|
|
metal = self.store.get('Crew', 'METAL', create=True)
|
|
|
|
metal.site = metal_w
|
|
|
|
metal.resources = ['COPPER_ORE','IRON_ORE','ALUMINUM_ORE']
|
|
|
|
gas = self.store.get('Crew', 'GAS', create=True)
|
|
|
|
gas.site = gas_w
|
|
|
|
gas.resources = ['HYDROCARBON','LIQUID_HYDROGEN','LIQUID_NITROGEN']
|
|
|
|
return [gas, metal]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|