2023-06-15 19:10:33 +00:00
|
|
|
from .base import Base
|
|
|
|
from time import time
|
|
|
|
from nullptr.util import *
|
2023-06-16 12:41:11 +00:00
|
|
|
from dataclasses import dataclass, field
|
2023-06-15 19:10:33 +00:00
|
|
|
|
|
|
|
class Ship(Base):
|
|
|
|
cargo:dict = {}
|
2023-06-17 12:59:52 +00:00
|
|
|
mission_state:dict = {}
|
2023-06-15 19:10:33 +00:00
|
|
|
status:str = ''
|
|
|
|
cargo_capacity:int = 0
|
|
|
|
cargo_units:int = 0
|
|
|
|
location_str = ''
|
|
|
|
cooldown:int = 0
|
|
|
|
arrival:int = 0
|
|
|
|
fuel_current:int = 0
|
|
|
|
fuel_capacity:int = 0
|
|
|
|
mission:str = None
|
|
|
|
mission_status:str = 'init'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def ext(self):
|
|
|
|
return 'shp'
|
|
|
|
|
|
|
|
def location(self):
|
|
|
|
return self.store.get('Waypoint', self.location_str)
|
|
|
|
|
|
|
|
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')
|
|
|
|
self.seta('location_str', d, 'nav.waypointSymbol')
|
|
|
|
self.seta('cargo_capacity', d, 'cargo.capacity')
|
|
|
|
self.seta('cargo_units', d, 'cargo.units')
|
|
|
|
self.seta('fuel_capacity', d, 'fuel.capacity')
|
|
|
|
self.seta('fuel_current', d,'fuel.current')
|
|
|
|
cargo = sg(d, 'cargo.inventory')
|
|
|
|
if cargo is not None:
|
|
|
|
self.load_cargo(cargo)
|
2023-06-16 11:03:19 +00:00
|
|
|
self.seta('cooldown', d, 'cooldown.expiration', parse_timestamp)
|
|
|
|
self.seta('arrival', d, 'nav.route.arrival', parse_timestamp)
|
|
|
|
|
2023-06-15 19:10:33 +00:00
|
|
|
def tick(self):
|
|
|
|
if self.status == 'IN_TRANSIT' and self.arrival < time():
|
|
|
|
self.status = 'IN_ORBIT'
|
|
|
|
|
|
|
|
def is_cooldown(self):
|
|
|
|
return self.cooldown > time()
|
|
|
|
|
|
|
|
def is_travelling(self):
|
|
|
|
return self.status == 'IN_TRANSIT'
|
|
|
|
|
|
|
|
def get_cargo(self, typ):
|
|
|
|
if typ not in self.cargo:
|
|
|
|
return 0
|
2023-06-16 11:03:19 +00:00
|
|
|
return self.cargo[typ]
|
2023-06-15 19:10:33 +00:00
|
|
|
|
|
|
|
def load_cargo(self, cargo):
|
|
|
|
result = {}
|
|
|
|
for i in cargo:
|
|
|
|
symbol = must_get(i, 'symbol')
|
|
|
|
units = must_get(i, 'units')
|
2023-06-16 11:03:19 +00:00
|
|
|
result[symbol] = units
|
2023-06-15 19:10:33 +00:00
|
|
|
self.cargo = result
|
|
|
|
|
|
|
|
def deliverable_cargo(self, contract):
|
|
|
|
result = []
|
|
|
|
for d in contract.deliveries:
|
2023-06-16 11:03:19 +00:00
|
|
|
if self.get_cargo(d['trade_symbol']) > 0:
|
|
|
|
result.append(d['trade_symbol'])
|
2023-06-15 19:10:33 +00:00
|
|
|
return result
|
|
|
|
|
|
|
|
def nondeliverable_cargo(self, contract):
|
2023-06-16 11:03:19 +00:00
|
|
|
cargo = self.cargo.keys()
|
|
|
|
deliveries = [d['trade_symbol'] for d in contract.deliveries]
|
2023-06-15 19:10:33 +00:00
|
|
|
garbage = [c for c in cargo if c not in deliveries]
|
|
|
|
return garbage
|
|
|
|
|
|
|
|
def update_timers(self):
|
|
|
|
if self.status == 'IN_TRANSIT' and self.arrival < time():
|
|
|
|
self.status = 'IN_ORBIT'
|
|
|
|
|
|
|
|
|
|
|
|
def f(self, detail=1):
|
|
|
|
self.update_timers()
|
|
|
|
arrival = int(self.arrival - time())
|
|
|
|
cooldown = int(self.cooldown - time())
|
|
|
|
r = self.symbol
|
|
|
|
if detail > 1:
|
|
|
|
r += ' ' + self.status
|
|
|
|
r += f' [{self.fuel_current}/{self.fuel_capacity}]'
|
|
|
|
r += ' ' + str(self.location())
|
|
|
|
if self.is_travelling():
|
|
|
|
r += f' [A: {arrival}]'
|
|
|
|
if self.is_cooldown():
|
|
|
|
r += f' [C: {cooldown}]'
|
|
|
|
return r
|
|
|
|
|