From 5b7c777d6bbd9ad27de918e46538c8f885e565a3 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Fri, 19 Apr 2019 09:36:28 +0300 Subject: [PATCH] Add 2 functions which calculate how many drones ship can release / store --- eos/gamedata.py | 11 ++++++++++ eos/saveddata/fit.py | 15 +++++++++++++ gui/fitCommands/calc/drone/localAdd.py | 3 ++- service/fit.py | 29 -------------------------- 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/eos/gamedata.py b/eos/gamedata.py index e63763cb8..4dda3eed2 100644 --- a/eos/gamedata.py +++ b/eos/gamedata.py @@ -250,6 +250,17 @@ class Item(EqBase): return self.__attributes + @property + def attribsWithOverrides(self): + overrides = self.overrides + attribs = {} + for aname, attr in self.attributes.items(): + if aname in overrides: + attribs[aname] = overrides[aname] + else: + attribs[aname] = attr + return attribs + def getAttribute(self, key, default=None): if key in self.attributes: return self.attributes[key].value diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index 9c28f77e6..e666e3339 100644 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -1507,6 +1507,21 @@ class Fit(object): return True + def howManyDronesRelease(self, item): + if not item.isDrone: + return 0 + bw = round(self.ship.getModifiedItemAttr("droneBandwidth")) + volume = round(item.attribsWithOverrides['volume']) + return int(bw / volume) + + def howManyDronesStore(self, item): + if not item.isDrone: + return 0 + bayTotal = round(self.ship.getModifiedItemAttr("droneCapacity")) + bayUsed = round(self.droneBayUsed) + volume = item.attribsWithOverrides['volume'] + return int((bayTotal - bayUsed) / volume) + def __deepcopy__(self, memo=None): fitCopy = Fit() # Character and owner are not copied diff --git a/gui/fitCommands/calc/drone/localAdd.py b/gui/fitCommands/calc/drone/localAdd.py index 13119e7c7..8b0842ff4 100644 --- a/gui/fitCommands/calc/drone/localAdd.py +++ b/gui/fitCommands/calc/drone/localAdd.py @@ -31,9 +31,10 @@ class CalcAddLocalDroneCommand(wx.Command): # with enough space for new drones and use it if not self.forceNewStack and self.droneInfo.amountActive == 0: for drone in fit.drones.find(item): + maxStack = max(5, fit.extraAttributes["maxActiveDrones"]) if ( drone is not None and drone.amountActive == 0 and - drone.amount + self.droneInfo.amount) <= max(5, fit.extraAttributes["maxActiveDrones"] + drone.amount + self.droneInfo.amount <= maxStack ): self.savedDroneInfo = DroneInfo.fromDrone(drone) self.savedPosition = fit.drones.index(drone) diff --git a/service/fit.py b/service/fit.py index 580520a43..8d8b3ffbf 100644 --- a/service/fit.py +++ b/service/fit.py @@ -346,35 +346,6 @@ class Fit(FitDeprecated): eos.db.commit() return mutator.value - @deprecated - def addDrone(self, fitID, itemID, numDronesToAdd=1, recalc=True): - pyfalog.debug("Adding {0} drones ({1}) to fit ID: {2}", numDronesToAdd, itemID, fitID) - if fitID is None: - return False - - fit = eos.db.getFit(fitID) - item = eos.db.getItem(itemID, eager=("attributes", "group.category")) - if item.category.name == "Drone": - drone = None - for d in fit.drones.find(item): - if d is not None and d.amountActive == 0 and d.amount < max(5, fit.extraAttributes["maxActiveDrones"]): - drone = d - break - - if drone is None: - drone = es_Drone(item) - if drone.fits(fit) is True: - fit.drones.append(drone) - else: - return False - drone.amount += numDronesToAdd - eos.db.commit() - if recalc: - self.recalc(fit) - return True - else: - return False - def toggleRestrictionIgnore(self, fitID): pyfalog.debug("Toggling restriction ignore for fit ID: {0}", fitID) fit = eos.db.getFit(fitID)