Update central_command.py, commander.py and eleven other files

This commit is contained in:
Richard Bronkhorst
2023-06-18 19:15:51 +02:00
parent a229b9e300
commit 8b29ca8f58
13 changed files with 192 additions and 81 deletions

View File

@@ -1,8 +1,9 @@
from .base import Base
class Agent(Base):
token: str = None
credits: int = 0
def define(self):
self.token: str = None
self.credits: int = 0
def update(self, d):
self.seta('credits', d)

View File

@@ -9,7 +9,11 @@ class Base:
def __init__(self, symbol, store):
self.store = store
self.symbol = symbol
self.define()
def define(self):
pass
def __hash__(self):
return hash((str(type(self)), self.symbol))

View File

@@ -5,13 +5,14 @@ from .base import Base
class Contract(Base):
identifier = 'id'
type: str
deliveries: list
accepted: bool
fulfilled: bool
expires: int
expires_str: str
pay: int
def define(self):
self.type: str = ''
self.deliveries: list = []
self.accepted: bool = False
self.fulfilled: bool = False
self.expires: int = 0
self.expires_str: str = ''
self.pay: int = 0
@classmethod
def ext(cls):
@@ -29,6 +30,18 @@ class Contract(Base):
'expiration': self.expires_str,
}
def is_done(self):
for d in self.deliveries:
if d['units_fulfilled'] > d['units_requires']:
return False
return False
def unfinished_delivery(self):
for d in self.deliveries:
if d['units_required'] > d['units_fulfilled']:
return d
return None
def update(self, d):
self.seta('expires',d, 'terms.deadline',parse_timestamp)
self.seta('expires_str', d,'terms.deadline')
@@ -46,6 +59,7 @@ class Contract(Base):
delivery['destination'] = must_get(e, 'destinationSymbol')
self.deliveries.append(delivery)
def f(self, detail=1):
hours = int(max(0, self.expires - time()) / 3600)
accepted = 'A' if self.accepted else '-'

View File

@@ -2,9 +2,10 @@ from .system_member import SystemMember
from dataclasses import field
class Jumpgate(SystemMember):
range: int
faction: str
systems: list = []
def define(self):
self.range: int = 0
self.faction: str = ''
self.systems: list = []
def update(self, d):
self.setlst('systems', d, 'connectedSystems', 'symbol')

View File

@@ -5,11 +5,12 @@ from nullptr.util import *
from dataclasses import field
class Marketplace(SystemMember):
imports:list = []
exports:list = []
exchange:list = []
prices:dict = {}
last_prices:int = 0
def define(self):
self.imports:list = []
self.exports:list = []
self.exchange:list = []
self.prices:dict = {}
self.last_prices:int = 0
def update(self, d):
self.setlst('imports', d, 'imports', 'symbol')

View File

@@ -4,18 +4,19 @@ from nullptr.util import *
from dataclasses import dataclass, field
class Ship(Base):
cargo:dict = {}
mission_state:dict = {}
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'
def define(self):
self.cargo:dict = {}
self.mission_state:dict = {}
self.status:str = ''
self.cargo_capacity:int = 0
self.cargo_units:int = 0
self.location_str = ''
self.cooldown:int = 0
self.arrival:int = 0
self.fuel_current:int = 0
self.fuel_capacity:int = 0
self.mission:str = None
self.mission_status:str = 'init'
@classmethod
def ext(self):
@@ -50,6 +51,10 @@ class Ship(Base):
def is_travelling(self):
return self.status == 'IN_TRANSIT'
def set_mission_state(self, nm, val):
self.mission_state[nm] = val
self.store.dirty(self)
def get_cargo(self, typ):
if typ not in self.cargo:

View File

@@ -6,12 +6,13 @@ size_names = ['SMALL','MODERATE','LARGE']
class Survey(SystemMember):
identifier = 'signature'
type: str = ''
deposits: list[str] = []
size: int = 0
expires: int = 0
expires_str: str = ''
exhausted: bool = False
def define(self):
self.type: str = ''
self.deposits: list[str] = []
self.size: int = 0
self.expires: int = 0
self.expires_str: str = ''
self.exhausted: bool = False
@classmethod
def ext(cls):

View File

@@ -3,9 +3,10 @@ from .base import Base
from math import sqrt
class System(Base):
x:int = 0
y:int = 0
type:str = 'unknown'
def define(self):
self.x:int = 0
self.y:int = 0
self.type:str = 'unknown'
def update(self, d):
self.seta('x', d)

View File

@@ -3,11 +3,12 @@ from nullptr.util import *
from dataclasses import field
class Waypoint(SystemMember):
x:int = 0
y:int = 0
type:str = 'unknown'
traits:list = []
faction:str = ''
def define(self):
self.x:int = 0
self.y:int = 0
self.type:str = 'unknown'
self.traits:list = []
self.faction:str = ''
def update(self, d):
self.seta('x', d)