Add an interface to prevent actors from being spawned by SpawnMapActors
This commit is contained in:
committed by
Paul Chote
parent
df1d928242
commit
c2cf8ba599
@@ -26,6 +26,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void WorldLoaded(World world, WorldRenderer wr)
|
||||
{
|
||||
var preventMapSpawns = world.WorldActor.TraitsImplementing<IPreventMapSpawn>()
|
||||
.Concat(world.WorldActor.Owner.PlayerActor.TraitsImplementing<IPreventMapSpawn>())
|
||||
.ToArray();
|
||||
|
||||
foreach (var kv in world.Map.ActorDefinitions)
|
||||
{
|
||||
var actorReference = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
|
||||
@@ -38,11 +42,24 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var initDict = actorReference.InitDict;
|
||||
initDict.Add(new SkipMakeAnimsInit());
|
||||
initDict.Add(new SpawnedByMapInit(kv.Key));
|
||||
|
||||
if (PreventMapSpawn(world, actorReference, preventMapSpawns))
|
||||
continue;
|
||||
|
||||
var actor = world.CreateActor(actorReference.Type, initDict);
|
||||
Actors[kv.Key] = actor;
|
||||
LastMapActorID = actor.ActorID;
|
||||
}
|
||||
}
|
||||
|
||||
bool PreventMapSpawn(World world, ActorReference actorReference, IEnumerable<IPreventMapSpawn> preventMapSpawns)
|
||||
{
|
||||
foreach (var pms in preventMapSpawns)
|
||||
if (pms.PreventMapSpawn(world, actorReference))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class SkipMakeAnimsInit : IActorInit, ISuppressInitExport { }
|
||||
|
||||
@@ -538,4 +538,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
OnChange = onChange;
|
||||
}
|
||||
}
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
public interface IPreventMapSpawn
|
||||
{
|
||||
bool PreventMapSpawn(World world, ActorReference actorReference);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user