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

View File

@@ -27,6 +27,7 @@ namespace OpenRA.Traits
public readonly PPos[] Footprint; public readonly PPos[] Footprint;
public readonly WPos CenterPosition; public readonly WPos CenterPosition;
public readonly Rectangle Bounds; public readonly Rectangle Bounds;
public readonly string[] TargetTypes;
readonly IRemoveFrozenActor[] removeFrozenActors; readonly IRemoveFrozenActor[] removeFrozenActors;
readonly Actor actor; readonly Actor actor;
readonly Shroud shroud; readonly Shroud shroud;
@@ -56,6 +57,7 @@ namespace OpenRA.Traits
CenterPosition = self.CenterPosition; CenterPosition = self.CenterPosition;
Bounds = self.Bounds; Bounds = self.Bounds;
TargetTypes = self.TraitsImplementing<ITargetable>().Where(Exts.IsTraitEnabled).SelectMany(t => t.TargetTypes).Distinct().ToArray();
UpdateVisibility(); 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) 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; return false;
// A target type is valid if it is in the valid targets list, and not in the invalid targets list. // 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(victim.TargetTypes))
if (!IsValidTarget(targetable.SelectMany(t => t.GetTargetTypes())))
return false; return false;
return true; return true;

View File

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