Skip to content
Browse files

Fixed autotargeter bug related to dealing with reserved target slots

Errors are now trapped in remote call completions
Fixed an unhandled exception in dronehelper
Fixed weaponhelper shooting at things that are out of range
  • Loading branch information...
1 parent 52e17cb commit da00609cb5df4ecc57ba433f5551626a2c03a67f @kg committed Jan 7, 2011
Showing with 44 additions and 18 deletions.
  1. +5 −6 AutoTargeter/autotargeter.py
  2. +6 −1 Common/Common.cs
  3. +8 −0 Common/common.eve.py
  4. +6 −3 DroneHelper/dronehelper.py
  5. +19 −8 WeaponHelper/weaponhelper.py
View
11 AutoTargeter/autotargeter.py
@@ -95,12 +95,11 @@ def getMaxTargetRange(self):
def getMaxTargets(self):
godma = eve.LocalSvc("godma")
- reservedSlots = int(getPref("ReservedTargetSlots", 1))
maxTargets = int(min(
godma.GetItem(eve.session.charid).maxLockedTargets,
godma.GetItem(eve.session.shipid).maxLockedTargets
))
- return max(maxTargets - reservedSlots, 0)
+ return max(maxTargets, 0)
def filterTargets(self, bis, gp, gd):
targetSvc = sm.services['target']
@@ -157,6 +156,9 @@ def updateTargets(self):
maxTargets = self.getMaxTargets()
if maxTargets <= 0:
return
+
+ reservedSlots = int(getPref("ReservedTargetSlots", 1))
+ maxAutoTargets = max(0, maxTargets - reservedSlots)
gd = Memoized(self.getDistance)
gp = Memoized(getPriority)
@@ -167,11 +169,8 @@ def updateTargets(self):
exclusionSet = set(targetSvc.targeting + targetSvc.autoTargeting + currentTargets)
targetSorter = self.makeTargetSorter(exclusionSet, gp, gd)
- startTime = blue.os.GetTime(1)
targets = self.filterTargets(self.__eligibleBalls, gp, gd)
-
targets.sort(targetSorter)
- elapsed = (blue.os.GetTime(1) - startTime) / 10000000.0
currentlyTargeting = set([
id for id in (targetSvc.targeting + targetSvc.autoTargeting)
@@ -180,7 +179,7 @@ def updateTargets(self):
allLockedTargets = set(targetSvc.targeting + targetSvc.autoTargeting + targetSvc.targets)
maxNewTargets = max(maxTargets - len(allLockedTargets), 0)
- targets = set([bi.id for bi in targets[0:maxTargets]])
+ targets = set([bi.id for bi in targets[0:maxAutoTargets]])
currentTargets = set(currentTargets)
View
7 Common/Common.cs
@@ -322,7 +322,12 @@ public Common (ScriptName name)
string errorText = null;
if (error != null)
errorText = error.ToString();
- yield return Program.CallFunction(process, "common", "_remoteCallComplete", resultId, result, errorText);
+
+ var f = Program.CallFunction(process, "common", "_remoteCallComplete", resultId, result, errorText);
+ yield return f;
+
+ if (f.Failed)
+ Program.Scheduler.OnTaskError(f.Error);
}
public void LoggedInCharacterChanged (ProcessInfo process, object characterName) {
View
8 Common/common.eve.py
@@ -431,6 +431,8 @@ class MainThreadInvoker(object):
"OnSessionChanged",
"OnClientReady",
"OnJukeboxChange"
+ "DoDestinyUpdate",
+ "DoDestinyUpdates"
]
def __init__(self, handler):
@@ -486,6 +488,12 @@ def OnClientReady(self, *args, **kwargs):
def OnJukeboxChange(self, *args, **kwargs):
self.doInvoke()
+
+ def DoDestinyUpdate(self, *args, **kwargs):
+ self.doInvoke()
+
+ def DoDestinyUpdates(self, *args, **kwargs):
+ self.doInvoke()
def _mainThreadQueueFunc():
import blue
View
9 DroneHelper/dronehelper.py
@@ -37,15 +37,19 @@ class DroneInfo(object):
def __init__(self, droneID):
self.id = droneID
ci = getCachedItem(droneID)
+
self.ball = ci.ball
self.slimItem = ci.slimItem
self.target = None
self.actionTimestamp = self.timestamp = 0
self.shield = self.armor = self.structure = 1.0
self.state = None
- attributes = getTypeAttributes(ci.slimItem.typeID, obj=ci.ball)
- self.isSentry = float(attributes.get("entityCruiseSpeed", 0.0)) <= 0.0
+ if ci.slimItem:
+ attributes = getTypeAttributes(ci.slimItem.typeID, obj=ci.ball)
+ self.isSentry = float(attributes.get("entityCruiseSpeed", 0.0)) <= 0.0
+ else:
+ self.isSentry = False
def setState(self, newState, timestamp):
if timestamp > self.timestamp:
@@ -300,7 +304,6 @@ def doAttack(self, idleOnly, targetID=None, dronesToAttack=[], oldTarget=None):
(droneObj.state == const.entityDeparting2) or
(droneObj.state == const.entityFleeing) or
(droneObj.state == const.entityPursuit)):
- log("drone state=%r, not attacking", droneObj.state)
drones.remove(id)
elif ((droneObj.target == targetID) or
abs(droneObj.actionTimestamp - timestamp) <= ActionThreshold):
View
27 WeaponHelper/weaponhelper.py
@@ -50,16 +50,17 @@ def __init__(self):
self.__hookedMethods = []
self.__lastAttackOrder = None
- def getTargetSorter(self, module):
+ def getChanceToHitCalculator(self, module):
+ cthc = ChanceToHitCalculator(eve.session.shipid)
+ cthc.setModule(module)
+ return Memoized(cthc.calculate)
+
+ def getTargetSorter(self, module, chanceToHitGetter):
godma = eve.LocalSvc("godma")
ballpark = eve.LocalSvc("michelle").GetBallpark()
gp = Memoized(getPriority)
- cthc = ChanceToHitCalculator(eve.session.shipid)
- cthc.setModule(module)
- chanceToHitGetter = Memoized(cthc.calculate)
-
def targetSorter(lhs, rhs):
# Highest priority first
priLhs = gp(lhs)
@@ -80,10 +81,12 @@ def targetSorter(lhs, rhs):
return targetSorter
- def filterTargets(self, ids):
+ def filterTargets(self, ids, chanceToHitGetter):
ballpark = eve.LocalSvc("michelle").GetBallpark()
result = []
+ cannotHit = set()
+
for id in ids:
invItem = ballpark.GetInvItem(id)
if not invItem:
@@ -94,15 +97,23 @@ def filterTargets(self, ids):
if getPriority(id) < 0:
continue
+
+ if chanceToHitGetter(id) <= 0:
+ cannotHit.add(id)
+ continue
result.append(id)
+ if (len(cannotHit) > 0) and (len(result) == 0):
+ log("Cannot hit target(s) %s", ", ".join(getNamesOfIDs(cannotHit)))
+
return result
def selectTarget(self, module):
- targets = self.filterTargets(sm.services["target"].targets)
+ cthc = self.getChanceToHitCalculator(module)
+ targets = self.filterTargets(sm.services["target"].targets, cthc)
if len(targets):
- targetSorter = self.getTargetSorter(module)
+ targetSorter = self.getTargetSorter(module, cthc)
targets.sort(targetSorter)
return targets[0]

0 comments on commit da00609

Please sign in to comment.
Something went wrong with that request. Please try again.