Store Targetables in Actor.
This can be used to avoid several lookups for these traits, as well as allow Actor to provide specialised methods to deal with target types efficiently. This also reduces some code duplication.
This commit is contained in:
@@ -67,9 +67,9 @@ namespace OpenRA.Mods.Common.Orders
|
||||
|
||||
public class TargetTypeOrderTargeter : UnitOrderTargeter
|
||||
{
|
||||
readonly string[] targetTypes;
|
||||
readonly HashSet<string> targetTypes;
|
||||
|
||||
public TargetTypeOrderTargeter(string[] targetTypes, string order, int priority, string cursor, bool targetEnemyUnits, bool targetAllyUnits)
|
||||
public TargetTypeOrderTargeter(HashSet<string> targetTypes, string order, int priority, string cursor, bool targetEnemyUnits, bool targetAllyUnits)
|
||||
: base(order, priority, cursor, targetEnemyUnits, targetAllyUnits)
|
||||
{
|
||||
this.targetTypes = targetTypes;
|
||||
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
return target.TraitsImplementing<ITargetable>().Any(t => t.IsTraitEnabled() && t.TargetTypes.Overlaps(targetTypes));
|
||||
return targetTypes.Overlaps(target.GetEnabledTargetTypes());
|
||||
}
|
||||
|
||||
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
|
||||
|
||||
Reference in New Issue
Block a user