diff --git a/eos/saveddata/module.py b/eos/saveddata/module.py index 6f7620b62..ab72e25b9 100644 --- a/eos/saveddata/module.py +++ b/eos/saveddata/module.py @@ -677,30 +677,41 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): def canHaveState(self, state=None, projectedOnto=None): """ - Check with other modules if there are restrictions that might not allow this module to be activated + Check with other modules if there are restrictions that might not allow this module to be activated. + Returns True if state is allowed, or max state module can have if current state is invalid. """ - # If we're going to set module to offline or online for local modules or offline for projected, - # it should be fine for all cases + # If we're going to set module to offline, it should be fine for all cases item = self.item - if (state <= FittingModuleState.ONLINE and projectedOnto is None) or (state <= FittingModuleState.OFFLINE): + if state <= FittingModuleState.OFFLINE: return True # Check if the local module is over it's max limit; if it's not, we're fine + maxGroupOnline = self.getModifiedItemAttr("maxGroupOnline", None) maxGroupActive = self.getModifiedItemAttr("maxGroupActive", None) - if maxGroupActive is None and projectedOnto is None: + if maxGroupOnline is None and maxGroupActive is None and projectedOnto is None: return True # Following is applicable only to local modules, we do not want to limit projected if projectedOnto is None: + currOnline = 0 currActive = 0 group = item.group.name + maxState = None for mod in self.owner.modules: currItem = getattr(mod, "item", None) - if mod.state >= FittingModuleState.ACTIVE and currItem is not None and currItem.group.name == group: - currActive += 1 - if currActive > maxGroupActive: - break - return currActive <= maxGroupActive + if currItem is not None and currItem.group.name == group: + if mod.state >= FittingModuleState.ONLINE: + currOnline += 1 + if mod.state >= FittingModuleState.ACTIVE: + currActive += 1 + if maxGroupOnline is not None and currOnline > maxGroupOnline: + if maxState is None or maxState > FittingModuleState.OFFLINE: + maxState = FittingModuleState.OFFLINE + break + if maxGroupActive is not None and currActive > maxGroupActive: + if maxState is None or maxState > FittingModuleState.ONLINE: + maxState = FittingModuleState.ONLINE + return True if maxState is None else maxState # For projected, we're checking if ship is vulnerable to given item else: # Do not allow to apply offensive modules on ship with offensive module immunite, with few exceptions @@ -711,10 +722,10 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): "energyNosferatuFalloff", "energyNeutralizerFalloff"} if not offensiveNonModifiers.intersection(set(item.effects)): - return False + return FittingModuleState.OFFLINE # If assistive modules are not allowed, do not let to apply these altogether if item.assistive and projectedOnto.ship.getModifiedItemAttr("disallowAssistance") == 1: - return False + return FittingModuleState.OFFLINE return True def isValidCharge(self, charge): diff --git a/gui/fitCommands/calc/module/projectedAdd.py b/gui/fitCommands/calc/module/projectedAdd.py index 564c6d4f3..660b24534 100644 --- a/gui/fitCommands/calc/module/projectedAdd.py +++ b/gui/fitCommands/calc/module/projectedAdd.py @@ -31,8 +31,9 @@ class CalcAddProjectedModuleCommand(wx.Command): sFit = Fit.getInstance() fit = sFit.getFit(self.fitID) - if not newMod.canHaveState(newMod.state, projectedOnto=fit): - newMod.state = FittingModuleState.OFFLINE + canHaveState = newMod.canHaveState(newMod.state, projectedOnto=fit) + if canHaveState is not True: + newMod.state = canHaveState if not self.ignoreRestrictions and not newMod.isValidCharge(newMod.charge): newMod.charge = None self.oldPosition, self.oldModInfo = fit.projectedModules.makeRoom(newMod) diff --git a/service/fit.py b/service/fit.py index dc842731a..12fe67090 100644 --- a/service/fit.py +++ b/service/fit.py @@ -450,13 +450,21 @@ class Fit: for pos, mod in enumerate(fit.modules): if mod is not base: # fix for #529, where a module may be in incorrect state after CCP changes mechanics of module - if not mod.canHaveState(mod.state) or not mod.isValidState(mod.state): + canHaveState = mod.canHaveState(mod.state) + if canHaveState is not True: + changedMods[pos] = mod.state + mod.state = canHaveState + elif not mod.isValidState(mod.state): changedMods[pos] = mod.state mod.state = FittingModuleState.ONLINE for pos, mod in enumerate(fit.projectedModules): # fix for #529, where a module may be in incorrect state after CCP changes mechanics of module - if not mod.canHaveState(mod.state, fit) or not mod.isValidState(mod.state): + canHaveState = mod.canHaveState(mod.state, fit) + if canHaveState is not True: + changedProjMods[pos] = mod.state + mod.state = canHaveState + elif not mod.isValidState(mod.state): changedProjMods[pos] = mod.state mod.state = FittingModuleState.OFFLINE