Take ship radius in consideration when displaying missile range in range column

This commit is contained in:
DarkPhoenix
2019-11-13 20:51:14 +03:00
parent 7fb6170bcb
commit f778f9ceae
2 changed files with 8 additions and 2 deletions

View File

@@ -368,11 +368,16 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
higherTime = math.ceil(flightTime)
lowerRange = calculateRange(maxVelocity, mass, agility, lowerTime)
higherRange = calculateRange(maxVelocity, mass, agility, higherTime)
# Fof range limit is supposedly calculated based on overview (surface-to-surface) range
if 'fofMissileLaunching' in self.charge.effects:
rangeLimit = self.getModifiedChargeAttr("maxFOFTargetRange")
if rangeLimit:
lowerRange = min(lowerRange, rangeLimit)
higherRange = min(higherRange, rangeLimit)
# Make range center-to-surface, as missiles spawn in the center of the ship
shipRadius = self.owner.ship.getModifiedItemAttr("radius")
lowerRange = max(0, lowerRange - shipRadius)
higherRange = max(0, higherRange - shipRadius)
higherChance = flightTime - lowerTime
return lowerRange, higherRange, higherChance

View File

@@ -155,10 +155,11 @@ def getLauncherMult(mod, src, distance, tgtSpeed, tgtSigRadius):
missileMaxRangeData = mod.missileMaxRangeData
if missileMaxRangeData is None:
return 0
# The ranges already consider ship radius
lowerRange, higherRange, higherChance = missileMaxRangeData
if distance is None or distance + src.getRadius() <= lowerRange:
if distance is None or distance <= lowerRange:
distanceFactor = 1
elif lowerRange < distance + src.getRadius() <= higherRange:
elif lowerRange < distance <= higherRange:
distanceFactor = higherChance
else:
distanceFactor = 0