Save cap sim state on fit
This commit is contained in:
@@ -21,6 +21,7 @@ class CapSimulator:
|
||||
|
||||
self.capacitorCapacity = 100
|
||||
self.capacitorRecharge = 1000
|
||||
self.startingCapacity = 1000
|
||||
|
||||
# max simulated time.
|
||||
self.t_max = DAY
|
||||
@@ -41,6 +42,10 @@ class CapSimulator:
|
||||
# relevant decimal digits of capacitor for LCM period optimization
|
||||
self.stability_precision = 1
|
||||
|
||||
# Stores how cap sim changed cap values outside of cap regen time
|
||||
self.saved_changes = ()
|
||||
self.saved_changes_internal = None
|
||||
|
||||
def scale_activation(self, duration, capNeed):
|
||||
for res in self.scale_resolutions:
|
||||
mod = duration % res
|
||||
@@ -67,6 +72,7 @@ class CapSimulator:
|
||||
def reset(self):
|
||||
"""Reset the simulator state"""
|
||||
self.state = []
|
||||
self.saved_changes_internal = {}
|
||||
mods = {}
|
||||
period = 1
|
||||
disable_period = False
|
||||
@@ -143,10 +149,10 @@ class CapSimulator:
|
||||
capCapacity = self.capacitorCapacity
|
||||
tau = self.capacitorRecharge / 5.0
|
||||
|
||||
cap_wrap = capCapacity # cap value at last period
|
||||
cap_lowest = capCapacity # lowest cap value encountered
|
||||
cap_lowest_pre = capCapacity # lowest cap value before activations
|
||||
cap = capCapacity # current cap value
|
||||
cap_wrap = self.startingCapacity # cap value at last period
|
||||
cap_lowest = self.startingCapacity # lowest cap value encountered
|
||||
cap_lowest_pre = self.startingCapacity # lowest cap value before activations
|
||||
cap = self.startingCapacity # current cap value
|
||||
t_wrap = self.period # point in time of next period
|
||||
|
||||
t_last = 0
|
||||
@@ -203,6 +209,7 @@ class CapSimulator:
|
||||
cap -= inj_capNeed
|
||||
if cap > capCapacity:
|
||||
cap = capCapacity
|
||||
self.saved_changes_internal[t_now] = cap
|
||||
# Add injector to regular state tracker
|
||||
inj_t_now = t_now
|
||||
inj_t_now += inj_duration
|
||||
@@ -217,6 +224,7 @@ class CapSimulator:
|
||||
cap -= capNeed
|
||||
if cap > capCapacity:
|
||||
cap = capCapacity
|
||||
self.saved_changes_internal[t_now] = cap
|
||||
|
||||
if cap < cap_lowest:
|
||||
# Negative cap - we're unstable, simulation is over
|
||||
@@ -239,6 +247,7 @@ class CapSimulator:
|
||||
cap -= inj_capNeed
|
||||
if cap > capCapacity:
|
||||
cap = capCapacity
|
||||
self.saved_changes_internal[t_now] = cap
|
||||
# Add injector to regular state tracker
|
||||
inj_t_now = t_now
|
||||
inj_t_now += inj_duration
|
||||
@@ -280,4 +289,7 @@ class CapSimulator:
|
||||
else:
|
||||
self.cap_stable_low = self.cap_stable_high = 0.0
|
||||
|
||||
self.saved_changes = tuple((k, v) for k, v in self.saved_changes_internal.items())
|
||||
self.saved_changes_internal = None
|
||||
|
||||
self.runtime = time.time() - start
|
||||
|
||||
@@ -143,6 +143,7 @@ class Fit:
|
||||
self.__capState = None
|
||||
self.__capUsed = None
|
||||
self.__capRecharge = None
|
||||
self.__savedCapSimData = {}
|
||||
self.__calculatedTargets = []
|
||||
self.factorReload = False
|
||||
self.boostsFits = set()
|
||||
@@ -160,6 +161,7 @@ class Fit:
|
||||
self.__capState = None
|
||||
self.__capUsed = None
|
||||
self.__capRecharge = None
|
||||
self.__savedCapSimData.clear()
|
||||
|
||||
@property
|
||||
def targetProfile(self):
|
||||
@@ -461,6 +463,7 @@ class Fit:
|
||||
self.__capState = None
|
||||
self.__capUsed = None
|
||||
self.__capRecharge = None
|
||||
self.__savedCapSimData.clear()
|
||||
self.ecmProjectedStr = 1
|
||||
# self.commandBonuses = {}
|
||||
|
||||
@@ -1227,30 +1230,29 @@ class Fit:
|
||||
drains = []
|
||||
capUsed = 0
|
||||
capAdded = 0
|
||||
for mod in self.modules:
|
||||
if mod.state >= FittingModuleState.ACTIVE:
|
||||
if (mod.getModifiedItemAttr("capacitorNeed") or 0) != 0:
|
||||
cycleTime = mod.rawCycleTime or 0
|
||||
reactivationTime = mod.getModifiedItemAttr("moduleReactivationDelay") or 0
|
||||
fullCycleTime = cycleTime + reactivationTime
|
||||
reloadTime = mod.reloadTime
|
||||
if fullCycleTime > 0:
|
||||
capNeed = mod.capUse
|
||||
if capNeed > 0:
|
||||
capUsed += capNeed
|
||||
else:
|
||||
capAdded -= capNeed
|
||||
for mod in self.activeModulesIter():
|
||||
if (mod.getModifiedItemAttr("capacitorNeed") or 0) != 0:
|
||||
cycleTime = mod.rawCycleTime or 0
|
||||
reactivationTime = mod.getModifiedItemAttr("moduleReactivationDelay") or 0
|
||||
fullCycleTime = cycleTime + reactivationTime
|
||||
reloadTime = mod.reloadTime
|
||||
if fullCycleTime > 0:
|
||||
capNeed = mod.capUse
|
||||
if capNeed > 0:
|
||||
capUsed += capNeed
|
||||
else:
|
||||
capAdded -= capNeed
|
||||
|
||||
# If this is a turret, don't stagger activations
|
||||
disableStagger = mod.hardpoint == FittingHardpoint.TURRET
|
||||
# If this is a turret, don't stagger activations
|
||||
disableStagger = mod.hardpoint == FittingHardpoint.TURRET
|
||||
|
||||
drains.append((
|
||||
int(fullCycleTime),
|
||||
mod.getModifiedItemAttr("capacitorNeed") or 0,
|
||||
mod.numShots or 0,
|
||||
disableStagger,
|
||||
reloadTime,
|
||||
mod.item.group.name == 'Capacitor Booster'))
|
||||
drains.append((
|
||||
int(fullCycleTime),
|
||||
mod.getModifiedItemAttr("capacitorNeed") or 0,
|
||||
mod.numShots or 0,
|
||||
disableStagger,
|
||||
reloadTime,
|
||||
mod.item.group.name == 'Capacitor Booster'))
|
||||
|
||||
for fullCycleTime, capNeed, clipSize, reloadTime in self.iterDrains():
|
||||
drains.append((
|
||||
@@ -1272,16 +1274,7 @@ class Fit:
|
||||
drains, self.__capUsed, self.__capRecharge = self.__generateDrain()
|
||||
self.__capRecharge += self.calculateCapRecharge()
|
||||
if len(drains) > 0:
|
||||
sim = capSim.CapSimulator()
|
||||
sim.init(drains)
|
||||
sim.capacitorCapacity = self.ship.getModifiedItemAttr("capacitorCapacity")
|
||||
sim.capacitorRecharge = self.ship.getModifiedItemAttr("rechargeRate")
|
||||
sim.stagger = True
|
||||
sim.scale = False
|
||||
sim.t_max = 6 * 60 * 60 * 1000
|
||||
sim.reload = self.factorReload
|
||||
sim.run()
|
||||
|
||||
sim = self.__runCapSim(drains=drains)
|
||||
capState = (sim.cap_stable_low + sim.cap_stable_high) / (2 * sim.capacitorCapacity)
|
||||
self.__capStable = capState > 0
|
||||
self.__capState = min(100, capState * 100) if self.__capStable else sim.t / 1000.0
|
||||
@@ -1289,6 +1282,27 @@ class Fit:
|
||||
self.__capStable = True
|
||||
self.__capState = 100
|
||||
|
||||
def getCapSimData(self, startingCap):
|
||||
if startingCap not in self.__savedCapSimData:
|
||||
self.__runCapSim(startingCap=startingCap)
|
||||
return self.__savedCapSimData[startingCap]
|
||||
|
||||
def __runCapSim(self, drains=None, startingCap=None):
|
||||
if drains is None:
|
||||
drains, nil, nil = self.__generateDrain()
|
||||
sim = capSim.CapSimulator()
|
||||
sim.init(drains)
|
||||
sim.capacitorCapacity = self.ship.getModifiedItemAttr("capacitorCapacity")
|
||||
sim.capacitorRecharge = self.ship.getModifiedItemAttr("rechargeRate")
|
||||
sim.startingCapacity = startingCap = self.ship.getModifiedItemAttr("capacitorCapacity") if startingCap is None else startingCap
|
||||
sim.stagger = True
|
||||
sim.scale = False
|
||||
sim.t_max = 6 * 60 * 60 * 1000
|
||||
sim.reload = self.factorReload
|
||||
sim.run()
|
||||
self.__savedCapSimData[startingCap] = sim.saved_changes
|
||||
return sim
|
||||
|
||||
def getRemoteReps(self, spoolOptions=None):
|
||||
if spoolOptions not in self.__remoteRepMap:
|
||||
remoteReps = RRTypes(0, 0, 0, 0)
|
||||
|
||||
@@ -42,7 +42,7 @@ class FitCapRegenGraph(FitGraph):
|
||||
(('capAmount', '%'), None)]),
|
||||
Input(handle='capAmountT0', unit='%', label='Starting cap amount', iconID=1668, defaultValue=0, defaultRange=(0, 100), conditions=[
|
||||
(('time', 's'), None)])]
|
||||
checkboxes = [InputCheckbox(handle='useCapsim', label='Use capacitor simulator', defaultValue=True, conditions=[
|
||||
checkboxes = [InputCheckbox(handle='useCapsim', label='Use capacitor simulator', defaultValue=False, conditions=[
|
||||
(('time', 's'), ('capAmount', 'GJ'))])]
|
||||
srcExtraCols = ('CapAmount', 'CapTime')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user