Add SpawnActorEffect

And use it to drop DelayedAction from ReinforcementsGlobal.
This commit is contained in:
reaperrr
2019-01-06 07:40:41 +01:00
committed by abcdefg30
parent ab4268025a
commit ea2e452075
3 changed files with 78 additions and 15 deletions

View File

@@ -0,0 +1,64 @@
#region Copyright & License Information
/*
* Copyright 2007-2019 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Effects;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Effects
{
public class SpawnActorEffect : IEffect
{
readonly Actor actor;
readonly CPos[] pathAfterSpawn;
readonly Activity activityAtDestination;
readonly IMove move;
int remainingDelay;
public SpawnActorEffect(Actor actor)
: this(actor, 0, new CPos[0], null) { }
public SpawnActorEffect(Actor actor, int delay)
: this(actor, delay, new CPos[0], null) { }
public SpawnActorEffect(Actor actor, int delay, CPos[] pathAfterSpawn, Activity activityAtDestination)
{
this.actor = actor;
remainingDelay = delay;
this.pathAfterSpawn = pathAfterSpawn;
this.activityAtDestination = activityAtDestination;
move = actor.TraitOrDefault<IMove>();
}
public void Tick(World world)
{
if (remainingDelay-- > 0)
return;
world.Add(actor);
if (move != null)
for (var j = 0; j < pathAfterSpawn.Length; j++)
actor.QueueActivity(move.MoveTo(pathAfterSpawn[j], 2));
if (activityAtDestination != null)
actor.QueueActivity(activityAtDestination);
world.AddFrameEndTask(w => w.Remove(this));
}
public IEnumerable<IRenderable> Render(WorldRenderer wr) { return SpriteRenderable.None; }
}
}

View File

@@ -149,6 +149,7 @@
<Compile Include="Effects\MapNotificationEffect.cs" />
<Compile Include="Effects\RallyPointIndicator.cs" />
<Compile Include="Effects\SpriteEffect.cs" />
<Compile Include="Effects\SpawnActorEffect.cs" />
<Compile Include="Graphics\RailgunRenderable.cs" />
<Compile Include="Lint\CheckNotifications.cs" />
<Compile Include="Projectiles\AreaBeam.cs" />

View File

@@ -16,6 +16,7 @@ using Eluant;
using OpenRA.Activities;
using OpenRA.Effects;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Effects;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Scripting;
@@ -84,24 +85,21 @@ namespace OpenRA.Mods.Common.Scripting
actors.Add(actor);
var actionDelay = i * interval;
Action actorAction = () =>
{
Context.World.Add(actor);
for (var j = 1; j < entryPath.Length; j++)
Move(actor, entryPath[j]);
Activity queuedActivity = null;
if (af != null)
{
actor.QueueActivity(new CallFunc(() =>
queuedActivity = new CallFunc(() =>
{
using (af)
using (var a = actor.ToLuaValue(Context))
af.Call(a);
}));
});
}
};
Context.World.AddFrameEndTask(w => w.Add(new DelayedAction(actionDelay, actorAction)));
// We need to exclude the spawn location from the movement path
var path = entryPath.Skip(1).ToArray();
Context.World.AddFrameEndTask(w => w.Add(new SpawnActorEffect(actor, actionDelay, path, queuedActivity)));
}
return actors.ToArray();