NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

targetEvaluation.py (5752B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\behaviors\targetEvaluation.py
      2 from behaviors.const.combat import RANDOM_TARGET_EVALUATOR, THREAT_TARGET_EVALUATOR, COST_TARGET_EVALUATOR, TOWING_TOW_OBJECTIVE_EVALUATOR
      3 from behaviors.const.combat import RANGE_TARGET_EVALUATOR, BASIC_TARGET_EVALUATOR, FITTED_MODULE_GROUP_TARGET_EVALUATOR
      4 from behaviors.const.combat import SIZE_TARGET_EVALUATOR, SIGNATURE_RADIUS_AND_VELOCITY_EVALUATOR
      5 from behaviors.utility.threat import evaluate_target
      6 from ccpProfile import TimedFunction
      7 from dogma.const import attributeSignatureRadius, attributeMaxVelocity
      8 from inventorycommon.typeHelpers import GetAveragePrice
      9 from random import random
     10 from spacecomponents.common.components.towGameObjective import SLIM_KEY_TOWING_ID
     11 
     12 class TargetEvaluator(object):
     13 
     14     def __init__(self, context, attributes):
     15         pass
     16 
     17     def EvaluateTarget(self, targetId):
     18         return 0
     19 
     20 
     21 class RandomTargetEvaluator(TargetEvaluator):
     22 
     23     def EvaluateTarget(self, targetId):
     24         return random()
     25 
     26 
     27 class SizeTargetEvaluator(TargetEvaluator):
     28 
     29     def __init__(self, context, attributes):
     30         super(SizeTargetEvaluator, self).__init__(context, attributes)
     31         self.inventory2 = context.ballpark.inventory2
     32         self.GetAttributeValue = context.dogmaLM.dogmaStaticMgr.GetTypeAttribute2
     33 
     34     @TimedFunction('behaviors::targetEvaluation::SizeTargetEvaluator::EvaluateTarget')
     35     def EvaluateTarget(self, targetId):
     36         typeId = self.inventory2.GetItem(targetId).typeID
     37         return self.GetAttributeValue(typeId, attributeSignatureRadius)
     38 
     39 
     40 class ThreatTargetEvaluator(TargetEvaluator):
     41 
     42     def __init__(self, context, attributes):
     43         super(ThreatTargetEvaluator, self).__init__(context, attributes)
     44         self.threatSampleIntervalSeconds = getattr(attributes, 'threatSampleIntervalSeconds', 10)
     45         self.damageTracker = sm.GetService('damageTracker').GetTrackerForSystem(context.solarSystemId)
     46         self.dogmaLM = context.dogmaLM
     47 
     48     @TimedFunction('behaviors::targetEvaluation::ThreatTargetEvaluator::EvaluateTarget')
     49     def EvaluateTarget(self, targetId):
     50         return evaluate_target(self.damageTracker, self.dogmaLM, targetId, self.threatSampleIntervalSeconds)
     51 
     52 
     53 class CostTargetEvaluator(TargetEvaluator):
     54 
     55     def __init__(self, context, attributes):
     56         super(CostTargetEvaluator, self).__init__(context, attributes)
     57         self.ballpark = context.ballpark
     58 
     59     @TimedFunction('behaviors::targetEvaluation::ThreatTargetEvaluator::EvaluateTarget')
     60     def EvaluateTarget(self, targetId):
     61         slimItem = self.ballpark.slims.get(targetId)
     62         return GetAveragePrice(slimItem.typeID) or 0.0
     63 
     64 
     65 class FittedModuleGroupTargetEvaluator(TargetEvaluator):
     66 
     67     def __init__(self, context, attributes):
     68         super(FittedModuleGroupTargetEvaluator, self).__init__(context, attributes)
     69         self.dogmaLM = context.ballpark.dogmaLM
     70         self.preferredModuleGroups = getattr(attributes, 'preferredModuleGroups', [])
     71 
     72     @TimedFunction('behaviors::targetEvaluation::ShipGroupTargetEvaluator::EvaluateTarget')
     73     def EvaluateTarget(self, targetId):
     74         fittedModuleGroupIds = self.dogmaLM.GetFittedModulesGroupIdsForShip(targetId)
     75         for moduleGroupId in self.preferredModuleGroups:
     76             if moduleGroupId in fittedModuleGroupIds:
     77                 return 1
     78 
     79         return 0
     80 
     81 
     82 class RangeTargetEvaluator(TargetEvaluator):
     83 
     84     def __init__(self, context, attributes):
     85         super(RangeTargetEvaluator, self).__init__(context, attributes)
     86         self.my_ball_id = context.myBall.id
     87         self.distance_between = context.ballpark.DistanceBetween
     88 
     89     @TimedFunction('behaviors::targetEvaluation::ThreatTargetEvaluator::EvaluateTarget')
     90     def EvaluateTarget(self, target_id):
     91         distance = self.distance_between(self.my_ball_id, target_id)
     92         return 1 - distance
     93 
     94 
     95 class SignatureRadiusAndVelocityEvaluator(TargetEvaluator):
     96 
     97     def __init__(self, context, attributes):
     98         super(SignatureRadiusAndVelocityEvaluator, self).__init__(context, attributes)
     99         self.inventory2 = context.ballpark.inventory2
    100         self.GetAttributeValue = context.dogmaLM.GetAttributeValue
    101 
    102     @TimedFunction('behaviors::targetEvaluation::SignatureRadiusAndVelocityEvaluator::EvaluateTarget')
    103     def EvaluateTarget(self, target_id):
    104         signature_radius = self.GetAttributeValue(target_id, attributeSignatureRadius)
    105         max_velocity = self.GetAttributeValue(target_id, attributeMaxVelocity)
    106         return signature_radius / max(1, max_velocity)
    107 
    108 
    109 class TowingTowObjectiveEvaulator(TargetEvaluator):
    110 
    111     def __init__(self, context, attributes):
    112         super(TowingTowObjectiveEvaulator, self).__init__(context, attributes)
    113         self.GetInvItem = context.ballpark.GetInvItem
    114 
    115     @TimedFunction('behaviors::targetEvaluation::TowingTowObjectiveEvaulator::EvaluateTarget')
    116     def EvaluateTarget(self, target_id):
    117         slimItem = self.GetInvItem(target_id)
    118         if slimItem:
    119             towing = getattr(slimItem, SLIM_KEY_TOWING_ID, default=None)
    120             if towing is not None:
    121                 return 1
    122             else:
    123                 return 0
    124         else:
    125             return 0
    126 
    127 
    128 targetEvaluationRegistry = {RANDOM_TARGET_EVALUATOR: RandomTargetEvaluator,
    129  SIZE_TARGET_EVALUATOR: SizeTargetEvaluator,
    130  THREAT_TARGET_EVALUATOR: ThreatTargetEvaluator,
    131  COST_TARGET_EVALUATOR: CostTargetEvaluator,
    132  BASIC_TARGET_EVALUATOR: TargetEvaluator,
    133  FITTED_MODULE_GROUP_TARGET_EVALUATOR: FittedModuleGroupTargetEvaluator,
    134  RANGE_TARGET_EVALUATOR: RangeTargetEvaluator,
    135  SIGNATURE_RADIUS_AND_VELOCITY_EVALUATOR: SignatureRadiusAndVelocityEvaluator,
    136  TOWING_TOW_OBJECTIVE_EVALUATOR: TowingTowObjectiveEvaulator}