Cache FrozenActor ITargetable.TargetTypes union

This commit is contained in:
atlimit8
2015-07-16 11:47:16 -05:00
parent 6986cd9f0e
commit fadfd179cb
5 changed files with 10 additions and 10 deletions

View File

@@ -138,8 +138,7 @@ namespace OpenRA.GameRules
/// <summary>Checks if the weapon is valid against (can target) the frozen actor.</summary>
public bool IsValidAgainst(FrozenActor victim, Actor firedBy)
{
var targetable = victim.Info.Traits.WithInterface<ITargetableInfo>();
if (!IsValidTarget(targetable.SelectMany(t => t.GetTargetTypes())))
if (!IsValidTarget(victim.TargetTypes))
return false;
if (!Warheads.Any(w => w.IsValidAgainst(victim, firedBy)))

View File

@@ -27,6 +27,7 @@ namespace OpenRA.Traits
public readonly PPos[] Footprint;
public readonly WPos CenterPosition;
public readonly Rectangle Bounds;
public readonly string[] TargetTypes;
readonly IRemoveFrozenActor[] removeFrozenActors;
readonly Actor actor;
readonly Shroud shroud;
@@ -56,6 +57,7 @@ namespace OpenRA.Traits
CenterPosition = self.CenterPosition;
Bounds = self.Bounds;
TargetTypes = self.TraitsImplementing<ITargetable>().Where(Exts.IsTraitEnabled).SelectMany(t => t.TargetTypes).Distinct().ToArray();
UpdateVisibility();
}

View File

@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Orders
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
return target.Info.Traits.WithInterface<ITargetableInfo>().Any(t => t.GetTargetTypes().Intersect(targetTypes).Any());
return target.TargetTypes.Intersect(targetTypes).Any();
}
}
}

View File

@@ -75,8 +75,7 @@ namespace OpenRA.Mods.Common.Warheads
return false;
// A target type is valid if it is in the valid targets list, and not in the invalid targets list.
var targetable = victim.Info.Traits.WithInterface<ITargetableInfo>();
if (!IsValidTarget(targetable.SelectMany(t => t.GetTargetTypes())))
if (!IsValidTarget(victim.TargetTypes))
return false;
return true;

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.RA.Traits
if (order.ExtraData == 0 && order.TargetActor == null)
return false;
ActorInfo ai;
IEnumerable<string> targetTypes;
if (order.ExtraData != 0)
{
@@ -74,13 +74,13 @@ namespace OpenRA.Mods.RA.Traits
if (frozen == null)
return false;
ai = frozen.Info;
targetTypes = frozen.TargetTypes;
}
else
ai = order.TargetActor.Info;
targetTypes = order.TargetActor.TraitsImplementing<ITargetable>().Where(Exts.IsTraitEnabled)
.SelectMany(t => t.TargetTypes);
return ai.Traits.WithInterface<ITargetableInfo>()
.SelectMany(t => t.GetTargetTypes()).Intersect(Info.Types).Any();
return targetTypes.Intersect(Info.Types).Any();
}
public string VoicePhraseForOrder(Actor self, Order order)