Improve some actor queries.

Use ActorsWithTrait if possible to avoid querying all actors in the world.
This commit is contained in:
RoosterDragon
2015-10-25 01:19:29 +01:00
parent e0177d7798
commit 30aee56d78
2 changed files with 5 additions and 4 deletions

View File

@@ -23,8 +23,9 @@ namespace OpenRA.Mods.Common.Activities
public Hunt(Actor self)
{
var attack = self.Trait<AttackBase>();
targets = self.World.Actors.Where(a => self != a && !a.IsDead && a.IsInWorld && a.AppearsHostileTo(self)
&& a.Info.HasTraitInfo<HuntableInfo>() && IsTargetable(a, self) && attack.HasAnyValidWeapons(Target.FromActor(a)));
targets = self.World.ActorsWithTrait<Huntable>().Select(p => p.Actor).Where(
a => self != a && !a.IsDead && a.IsInWorld && a.AppearsHostileTo(self)
&& IsTargetable(a, self) && attack.HasAnyValidWeapons(Target.FromActor(a)));
}
bool IsTargetable(Actor self, Actor viewer)