Improve some actor queries.
Use ActorsWithTrait if possible to avoid querying all actors in the world.
This commit is contained in:
@@ -23,8 +23,9 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
public Hunt(Actor self)
|
public Hunt(Actor self)
|
||||||
{
|
{
|
||||||
var attack = self.Trait<AttackBase>();
|
var attack = self.Trait<AttackBase>();
|
||||||
targets = self.World.Actors.Where(a => self != a && !a.IsDead && a.IsInWorld && a.AppearsHostileTo(self)
|
targets = self.World.ActorsWithTrait<Huntable>().Select(p => p.Actor).Where(
|
||||||
&& a.Info.HasTraitInfo<HuntableInfo>() && IsTargetable(a, self) && attack.HasAnyValidWeapons(Target.FromActor(a)));
|
a => self != a && !a.IsDead && a.IsInWorld && a.AppearsHostileTo(self)
|
||||||
|
&& IsTargetable(a, self) && attack.HasAnyValidWeapons(Target.FromActor(a)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsTargetable(Actor self, Actor viewer)
|
bool IsTargetable(Actor self, Actor viewer)
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
ConvertBridgeToActor(w, cell);
|
ConvertBridgeToActor(w, cell);
|
||||||
|
|
||||||
// Link adjacent (long)-bridges so that artwork is updated correctly
|
// Link adjacent (long)-bridges so that artwork is updated correctly
|
||||||
foreach (var b in w.Actors.SelectMany(a => a.TraitsImplementing<Bridge>()))
|
foreach (var p in w.ActorsWithTrait<Bridge>())
|
||||||
b.LinkNeighbouringBridges(w, this);
|
p.Trait.LinkNeighbouringBridges(w, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConvertBridgeToActor(World w, CPos cell)
|
void ConvertBridgeToActor(World w, CPos cell)
|
||||||
|
|||||||
Reference in New Issue
Block a user