MCPcopy Index your code
hub / github.com/pyfa-org/Pyfa / getModuleStructuredAmmo

Method getModuleStructuredAmmo

service/ammo.py:60–201  ·  view source on GitHub ↗
(cls, mod, ammo=None)

Source from the content-addressed store, hash-verified

58
59 @classmethod
60 def getModuleStructuredAmmo(cls, mod, ammo=None):
61 chargesFlat = cls.getModuleFlatAmmo(mod) if ammo is None else ammo
62 # Make sure we do not consider mining turrets as combat turrets
63 if mod.hardpoint == FittingHardpoint.TURRET and not mod.getModifiedItemAttr('miningAmount'):
64
65 def turretSorter(charge):
66 damage = 0
67 range_ = (mod.item.getAttribute('maxRange')) * \
68 (charge.getAttribute('weaponRangeMultiplier') or 1)
69 falloff = (mod.item.getAttribute('falloff') or 0) * \
70 (charge.getAttribute('fallofMultiplier') or 1)
71 for type_ in DmgTypes.names():
72 d = charge.getAttribute('%sDamage' % type_, default=0)
73 if d > 0:
74 damage += d
75 # Take optimal and falloff as range factor
76 rangeFactor = range_ + falloff
77 return -rangeFactor, charge.typeName.rsplit()[-2:], damage, charge.name
78
79 all = OrderedDict()
80 sub = []
81 prevNameBase = None
82 prevRange = None
83 for charge in sorted(chargesFlat, key=turretSorter):
84 if 'civilian' in charge.typeName.lower():
85 continue
86 currNameBase = ' '.join(charge.typeName.rsplit()[-2:])
87 currRange = charge.getAttribute('weaponRangeMultiplier')
88 if sub and (currRange != prevRange or currNameBase != prevNameBase):
89 all[sub[0].name] = sub
90 sub = []
91 sub.append(charge)
92 prevNameBase = currNameBase
93 prevRange = currRange
94 else:
95 if sub:
96 all[sub[0].name] = sub
97 return 'ddTurret', all
98
99 elif mod.hardpoint == FittingHardpoint.MISSILE and mod.item.name != 'Festival Launcher':
100
101 def getChargeDamageInfo(charge):
102 # Set up data storage for missile damage stuff
103 damageMap = {}
104 totalDamage = 0
105 # Fill them with the data about charge
106 for damageType in DmgTypes.names():
107 currentDamage = charge.getAttribute('{}Damage'.format(damageType)) or 0
108 damageMap[damageType] = currentDamage
109 totalDamage += currentDamage
110 # Detect type of ammo
111 chargeDamageType = None
112 for damageType in damageMap:
113 # If all damage belongs to certain type purely, set appropriate
114 # ammoType
115 if damageMap[damageType] == totalDamage:
116 chargeDamageType = damageType
117 break

Callers 2

getSubMenuMethod · 0.80
__init__Method · 0.80

Calls 7

getModuleFlatAmmoMethod · 0.80
getAttributeMethod · 0.80
itemsMethod · 0.80
_tFunction · 0.50
getModifiedItemAttrMethod · 0.45
appendMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected