Check for dead actors when searching for exits.

This commit is contained in:
Matthias Mailänder
2021-10-02 15:30:00 +02:00
committed by abcdefg30
parent 31267aa22d
commit 98b25ddd5e

View File

@@ -35,12 +35,12 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Exits with larger priorities will be used before lower priorities.")]
public readonly int Priority = 1;
public override object Create(ActorInitializer init) { return new Exit(init, this); }
public override object Create(ActorInitializer init) { return new Exit(this); }
}
public class Exit : ConditionalTrait<ExitInfo>
{
public Exit(ActorInitializer init, ExitInfo info)
public Exit(ExitInfo info)
: base(info) { }
}
@@ -62,6 +62,9 @@ namespace OpenRA.Mods.Common.Traits
public static IEnumerable<Exit> Exits(this Actor actor, string productionType = null)
{
if (!actor.IsInWorld || actor.Disposed)
return Enumerable.Empty<Exit>();
var all = actor.TraitsImplementing<Exit>()
.Where(Exts.IsTraitEnabled);
@@ -73,6 +76,9 @@ namespace OpenRA.Mods.Common.Traits
public static Exit RandomExitOrDefault(this Actor actor, World world, string productionType, Func<Exit, bool> p = null)
{
if (!actor.IsInWorld || actor.Disposed)
return null;
var allOfType = Exits(actor, productionType);
if (!allOfType.Any())
return null;