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:
RoosterDragon
2015-10-17 00:45:40 +01:00
parent 8230be6a14
commit dcf375a412
14 changed files with 66 additions and 35 deletions

View File

@@ -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)