def CreateFittingData(self, items, putModuleAmmoInHangar = True): fitData = [] dronesByType = defaultdict(int) chargesByType = defaultdict(int) iceByType = defaultdict(int) fightersByType = defaultdict(int) for item in items: typeID = item.typeID flagID = item.flagID if IsShipFittingFlag(flagID) and IsShipFittable(item.categoryID): fitData.append((int(typeID), int(flagID), 1)) elif item.categoryID == const.categoryDrone and flagID == const.flagDroneBay: dronesByType[typeID] += item.stacksize elif item.categoryID == const.categoryFighter and flagID == const.flagFighterBay: fightersByType[typeID] += item.stacksize elif item.categoryID == const.categoryCharge and flagID == const.flagCargo: chargesByType[typeID] += item.stacksize elif hasattr(item, 'groupID') and item.groupID == const.groupIceProduct and flagID == const.flagCargo: iceByType[typeID] += item.stacksize elif putModuleAmmoInHangar and item.categoryID == const.categoryCharge and flagID in const.moduleSlotFlags: chargesByType[typeID] += getattr(item, 'stacksize', 1) fitData += self.GetDataToAddToFitData(const.flagDroneBay, dronesByType) fitData += self.GetDataToAddToFitData(const.flagFighterBay, fightersByType) fitData += self.GetDataToAddToFitData(const.flagCargo, chargesByType) fitData += self.GetDataToAddToFitData(const.flagCargo, iceByType) return fitData
def GetStringForFitting(self, fitting): typesDict = defaultdict(int) drones = {} fighters = {} charges = {} ice = {} for typeID, flag, qty in fitting.fitData: categoryID = evetypes.GetCategoryID(typeID) groupID = evetypes.GetGroupID(typeID) if IsShipFittable(categoryID): typesDict[typeID] += 1 elif categoryID == const.categoryDrone: drones[typeID] = qty elif categoryID == const.categoryFighter: fighters[typeID] = qty elif categoryID == const.categoryCharge: charges[typeID] = qty elif groupID == const.groupIceProduct: ice[typeID] = qty retList = [] subString = str(fitting.shipTypeID) retList.append(subString) for eachDict in [typesDict, drones, fighters, charges, ice]: for typeID, qty in eachDict.iteritems(): subString = '%s;%s' % (typeID, qty) retList.append(subString) ret = ':'.join(retList) ret += '::' return ret
def ImportFromShip(self, shipID = None, ownerID = None, deferred = False): if deferred: self.deferred = (shipID, ownerID) return self self.__init__() if shipID is None: shipID = util.GetActiveShip() if ownerID is None: ownerID = eve.session.charid loc = cfg.evelocations.GetIfExists(shipID) if loc: self.name = loc.name else: self.name = None if ownerID != eve.session.charid: dna = sm.RemoteSvc('slash').SlashCmd('/getshipsetup %d' % shipID) return self.ImportFromDNA(dna) if shipID == util.GetActiveShip(): ship = sm.GetService('clientDogmaIM').GetDogmaLocation().GetDogmaItem(shipID) if ship is None: self.errorMessage = 'Could not get shipID: %s' % shipID return self self.typeID = ship.typeID for module in ship.GetFittedItems().itervalues(): if IsShipFittable(module.categoryID): self.moduleByFlag[module.flagID] = module.typeID else: try: shipinv = sm.GetService('invCache').GetInventoryFromId(shipID) self.typeID = shipinv.GetTypeID() if not self.name: self.name = evetypes.GetName(self.typeID) mods = shipinv.ListHardwareModules() except: self.errorMessage = 'Could not get inv of shipID: %s' % shipID return self for rec in mods: if IsShipFittable(evetypes.GetCategoryID(rec.typeID)): self.moduleByFlag[rec.flagID] = rec.typeID self.valid = True self.Update() return self
def GetClassForItem(self, item): categoryID = item.categoryID if categoryID == const.categoryShip: return GhostShipDogmaItem if IsStructureFittable(categoryID): return GhostStructureModuleDogmaItem if IsShipFittable(categoryID): return GhostModuleDogmaItem return BaseDogmaLocation.GetClassForItem(self, item)
def OnDropData(self, dragObj, nodes): self.Hilite(0) if len(nodes) == 1: item = nodes[0].item if IsShipFittingFlag(item.flagID): dogmaLocation = sm.GetService( 'clientDogmaIM').GetDogmaLocation() shipID = util.GetActiveShip() if IsShipFittable(item.categoryID): dogmaLocation.UnloadModuleToContainer(shipID, item.itemID, (shipID, ), flag=const.flagCargo) return if item.categoryID == const.categoryCharge: dogmaLocation.UnloadChargeToContainer( shipID, item.itemID, (shipID, ), const.flagCargo) return invCtrl.ShipCargo(util.GetActiveShip()).OnDropData(nodes) CargoSlots.OnDropData(self, dragObj, nodes)
def FitUsingHangar(self, shipID): if shipID != util.GetActiveShip(): self.Oops('Oops', 'You cannot fit ships other than your active one.') dogmaLocation = sm.GetService('clientDogmaIM').GetDogmaLocation() ship = dogmaLocation.GetDogmaItem(shipID) if ship is None: self.Oops('Huh?', 'Where is your ship?') title = 'Fitting %s' % GetTypeName(self.typeID) setup = self.GetModuleInfo() Cycle(title, 'Locating required modules...') source = {} for typeID in setup['modulelist']: source[typeID] = [] fit = {} for flag, typeID in self.moduleByFlag.iteritems(): if typeID: fit[flag] = typeID for item in ship.GetFittedItems().itervalues(): if item.typeID == self.moduleByFlag[item.flagID]: if fit.has_key(item.flagID): del fit[item.flagID] else: source[typeID].append(item) if setup.has_key(item.typeID): setup[item.typeID] -= 1 invCache = sm.GetService('invCache') for item in invCache.GetInventory(const.containerHangar).List(const.flagHangar): if IsShipFittable(item.categoryID): if setup.has_key(item.typeID): if item.singleton: source[item.typeID].insert(0, item) else: source[item.typeID].append(item) setup[item.typeID] -= item.stacksize missing = [] for typeID in setup['modulelist']: if setup[typeID] > 0: missing.append(' %s %s' % (setup[typeID], GetTypeName(typeID))) if missing: StopCycle() msg = 'Sorry, you cannot fit your ship with this setup; The following modules are not in your possession:<br><br>' msg += '<br>'.join(missing) self.Oops('Unable to fit ship', msg) Cycle(title, 'Unfitting modules...') charges = {} for item in ship.subLocations.itervalues(): charges[item.flagID] = item unfit = [] for item in ship.GetFittedItems().itervalues(): if item.categoryID == const.categoryCharge: charges[item.flagID] = item elif self.moduleByFlag[item.flagID] != item.typeID: unfit.append(item) ids = [] for item in unfit: charge = charges.get(item.flagID, None) if charge: ids.append(charge.itemID) ids.append(item.itemID) invCache.GetInventory(const.containerHangar).MultiAdd(ids, shipID, flag=const.flagHangar) del charges del unfit del ids del item fitByTypeID = {} for slot in (const.flagLoSlot0, const.flagMedSlot0, const.flagHiSlot0): for flag in xrange(slot, slot + 8): if fit.has_key(flag): typeID = fit[flag] if fitByTypeID.has_key(typeID): fitByTypeID[typeID].append(flag) else: fitByTypeID[typeID] = [flag] total = len(fit) state = [1, False] def _fit(typeID, flags): for flag in flags: sm.GetService('loading').ProgressWnd(title, 'Fitting modules...', state[0], total) try: while source[typeID]: item = source[typeID][0] try: if item.stacksize == 1: source[typeID].pop(0) invCache.GetInventoryFromId(shipID).Add(item.itemID, item.locationID, qty=1, flag=flag) state[0] += 1 break except: pass except: state[1] = True break parallelCalls = [] for typeID, flags in fitByTypeID.iteritems(): parallelCalls.append((_fit, (typeID, flags))) StopCycle() try: uthread.parallel(parallelCalls) except: pass if state[1]: StopCycle() self.Oops('There was a problem...', 'Your hangar inventory changed while fitting the ship, one or more required modules are locked or no longer within your reach.<br>The fitting operation has been aborted.') sm.GetService('loading').ProgressWnd(title, 'Done', 1, 1)
def ImportFromDNA(self, dna, name = None): self.__init__() if dna[:4] != 'DNA:': self.errorMessage = 'Not a DNA key: %s' % (dna,) return self if name: self.name = name self.source = dna self.dna = dna.split(':')[1:] expectedCategoryIDs = [const.categoryShip] flags = list(SLOTGROUPS) try: for frag in self.dna: try: parts = map(int, frag.split('*', 1)) except: raise RuntimeError(-1, "Invalid DNA fragment: '%s'" % frag) if len(parts) == 2: typeID, multi = parts else: typeID, = parts multi = 1 self.errorTypeID = typeID if multi < 1 or multi > 8: raise RuntimeError(typeID, 'Invalid module count: %s' % multi) if typeID > 3: if not evetypes.Exists(typeID): raise RuntimeError(typeID, 'Type not found') categoryID = evetypes.GetCategoryID(typeID) while multi > 0: if typeID <= 3: grp = typeID self.moduleByFlag[flags[grp]] = 0 flags[grp] += 1 multi -= 1 continue if categoryID not in expectedCategoryIDs: raise RuntimeError(typeID, 'Expected %s type, got %s type' % (evetypes.GetCategoryNameByCategory(expectedCategoryIDs[0]), evetypes.GetCategoryNameByCategory(categoryID))) if categoryID == const.categoryShip: self.typeID = typeID expectedCategoryIDs = [const.categoryModule, const.categorySubSystem] elif IsShipFittable(categoryID): grp = GetSlotGroup(typeID) if grp is not None: self.moduleByFlag[flags[grp]] = typeID flags[grp] += 1 else: raise RuntimeError(typeID, 'Type is not a module or rig') else: raise RuntimeError(typeID, 'Type is not a ship or module') multi -= 1 for startFlag, endFlag in zip(SLOTGROUPS, flags): if endFlag > startFlag + 8: raise RuntimeError(-1, 'Malformed template') self.valid = True self.Update() except RuntimeError as e: self.errorTypeID, self.errorMessage = e return self