diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index e768bf216..d44f8adca 100644 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -1016,6 +1016,16 @@ class Fit(object): def getNumSlots(self, type): return self.ship.getModifiedItemAttr(self.slots[type]) or 0 + def getHardpointsFree(self, type): + if type == Hardpoint.NONE: + return 1 + elif type == Hardpoint.TURRET: + return self.ship.getModifiedItemAttr('turretSlotsLeft') - self.getHardpointsUsed(Hardpoint.TURRET) + elif type == Hardpoint.MISSILE: + return self.ship.getModifiedItemAttr('launcherSlotsLeft') - self.getHardpointsUsed(Hardpoint.MISSILE) + else: + raise ValueError("%d is not a valid value for Hardpoint Enum", type) + @property def calibrationUsed(self): return self.getItemAttrOnlineSum(self.modules, 'upgradeCost') diff --git a/eos/saveddata/module.py b/eos/saveddata/module.py index e6e2c1823..f6d27053c 100644 --- a/eos/saveddata/module.py +++ b/eos/saveddata/module.py @@ -472,7 +472,8 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): if max is not None: current = 0 # if self.owner != fit else -1 # Disabled, see #1278 for mod in fit.modules: - if mod.item and mod.item.groupID == self.item.groupID: + if (mod.item and mod.item.groupID == self.item.groupID and + self.modPosition != mod.modPosition): current += 1 if current >= max: @@ -480,12 +481,8 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): # Check this only if we're told to do so if hardpointLimit: - if self.hardpoint == Hardpoint.TURRET: - if fit.ship.getModifiedItemAttr('turretSlotsLeft') - fit.getHardpointsUsed(Hardpoint.TURRET) < 1: - return False - elif self.hardpoint == Hardpoint.MISSILE: - if fit.ship.getModifiedItemAttr('launcherSlotsLeft') - fit.getHardpointsUsed(Hardpoint.MISSILE) < 1: - return False + if fit.getHardpointsFree(self.hardpoint) < 1: + return False return True diff --git a/gui/builtinViews/fittingView.py b/gui/builtinViews/fittingView.py index 36b3da6b1..9a7a97a43 100644 --- a/gui/builtinViews/fittingView.py +++ b/gui/builtinViews/fittingView.py @@ -686,7 +686,22 @@ class FittingView(d.Display): # only consider changing color if we're dealing with a Module if type(mod) is Module: - if slotMap[mod.slot] or getattr(mod, 'restrictionOverridden', None): # Color too many modules as red + hasRestrictionOverriden = getattr(mod, 'restrictionOverridden', None) + # If module had broken fitting restrictions but now doesn't, + # ensure it is now valid, and remove restrictionOverridden + # variable. More in #1519 + if not fit.ignoreRestrictions and hasRestrictionOverriden: + clean = False + if mod.fits(fit, False): + if not mod.hardpoint: + clean = True + elif fit.getHardpointsFree(mod.hardpoint) >= 0: + clean = True + if clean: + del mod.restrictionOverridden + hasRestrictionOverriden = not hasRestrictionOverriden + + if slotMap[mod.slot] or hasRestrictionOverriden: # Color too many modules as red self.SetItemBackgroundColour(i, wx.Colour(204, 51, 51)) elif sFit.serviceFittingOptions["colorFitBySlot"]: # Color by slot it enabled self.SetItemBackgroundColour(i, self.slotColour(mod.slot)) diff --git a/service/fit.py b/service/fit.py index 5fb884cad..75939a049 100644 --- a/service/fit.py +++ b/service/fit.py @@ -973,7 +973,7 @@ class Fit(object): # remove invalid modules when switching back to enabled fitting restrictions if not fit.ignoreRestrictions: for m in fit.modules: - if not m.isEmpty and not m.fits(fit): + if not m.isEmpty and not m.fits(fit, False): self.removeModule(fit.ID, m.modPosition) eos.db.commit()