Added a trait that removes an actor when prereqs are met, with delay.
This commit is contained in:
@@ -292,6 +292,7 @@
|
|||||||
<Compile Include="Warheads\CreateEffectWarhead.cs" />
|
<Compile Include="Warheads\CreateEffectWarhead.cs" />
|
||||||
<Compile Include="Warheads\CreateResourceWarhead.cs" />
|
<Compile Include="Warheads\CreateResourceWarhead.cs" />
|
||||||
<Compile Include="Warheads\LeaveSmudgeWarhead.cs" />
|
<Compile Include="Warheads\LeaveSmudgeWarhead.cs" />
|
||||||
|
<Compile Include="RemoveOnConditions.cs" />
|
||||||
<Compile Include="World\RadarPings.cs" />
|
<Compile Include="World\RadarPings.cs" />
|
||||||
<Compile Include="Player\TechTree.cs" />
|
<Compile Include="Player\TechTree.cs" />
|
||||||
<Compile Include="PrimaryBuilding.cs" />
|
<Compile Include="PrimaryBuilding.cs" />
|
||||||
@@ -473,7 +474,6 @@
|
|||||||
<Compile Include="Widgets\Logic\ReplayControlBarLogic.cs" />
|
<Compile Include="Widgets\Logic\ReplayControlBarLogic.cs" />
|
||||||
<Compile Include="World\BuildableTerrainLayer.cs" />
|
<Compile Include="World\BuildableTerrainLayer.cs" />
|
||||||
<Compile Include="Buildings\LaysTerrain.cs" />
|
<Compile Include="Buildings\LaysTerrain.cs" />
|
||||||
<Compile Include="RemoveImmediately.cs" />
|
|
||||||
<Compile Include="Attack\AttackFollow.cs" />
|
<Compile Include="Attack\AttackFollow.cs" />
|
||||||
<Compile Include="Attack\AttackGarrisoned.cs" />
|
<Compile Include="Attack\AttackGarrisoned.cs" />
|
||||||
<Compile Include="Widgets\Logic\LobbyMapPreviewLogic.cs" />
|
<Compile Include="Widgets\Logic\LobbyMapPreviewLogic.cs" />
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright 2007-2014 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. For more information,
|
|
||||||
* see COPYING.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
|
||||||
{
|
|
||||||
[Desc("Destroy the actor right after being added to the game world.")]
|
|
||||||
public class RemoveImmediatelyInfo : TraitInfo<RemoveImmediately> {}
|
|
||||||
|
|
||||||
public class RemoveImmediately : INotifyAddedToWorld
|
|
||||||
{
|
|
||||||
public void AddedToWorld(Actor self) { self.Destroy(); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
79
OpenRA.Mods.RA/RemoveOnConditions.cs
Normal file
79
OpenRA.Mods.RA/RemoveOnConditions.cs
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2014 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. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using OpenRA.Primitives;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
using OpenRA.Effects;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA
|
||||||
|
{
|
||||||
|
[Desc("Destroys the actor after a specified number of ticks if all conditions are met.")]
|
||||||
|
class RemoveOnConditionsInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
[Desc("Prerequisites required before removal")]
|
||||||
|
public readonly string[] Prerequisites = {};
|
||||||
|
|
||||||
|
[Desc("Delay until it starts checking if you have the prerequisites", "0 = Removal attempted on AddedToWorld")]
|
||||||
|
public readonly int Delay = 0;
|
||||||
|
|
||||||
|
[Desc("Should the trait kill instead of destroy?")]
|
||||||
|
public readonly bool KillInstead = false;
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new RemoveOnConditions(init.self, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
class RemoveOnConditions : INotifyAddedToWorld, ITechTreeElement
|
||||||
|
{
|
||||||
|
readonly RemoveOnConditionsInfo info;
|
||||||
|
readonly Actor self;
|
||||||
|
|
||||||
|
public RemoveOnConditions(Actor self, RemoveOnConditionsInfo info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
this.self = self;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddedToWorld(Actor self)
|
||||||
|
{
|
||||||
|
Action act = () =>
|
||||||
|
{
|
||||||
|
if (!info.Prerequisites.Any() || self.Owner.PlayerActor.Trait<TechTree>().HasPrerequisites(info.Prerequisites))
|
||||||
|
Remove();
|
||||||
|
else
|
||||||
|
self.Owner.PlayerActor.Trait<TechTree>().Add("remove_" + string.Join("_", info.Prerequisites.OrderBy(a => a)), info.Prerequisites, 0, this);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (info.Delay <= 0 && (!info.Prerequisites.Any() || self.Owner.PlayerActor.Trait<TechTree>().HasPrerequisites(info.Prerequisites)))
|
||||||
|
Remove();
|
||||||
|
else
|
||||||
|
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(info.Delay, act)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Remove()
|
||||||
|
{
|
||||||
|
if (!self.IsDead())
|
||||||
|
{
|
||||||
|
if (info.KillInstead && self.HasTrait<Health>())
|
||||||
|
self.Kill(self);
|
||||||
|
else
|
||||||
|
self.Destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PrerequisitesAvailable(string key) { Remove(); }
|
||||||
|
public void PrerequisitesUnavailable(string key) { }
|
||||||
|
public void PrerequisitesItemHidden(string key) { }
|
||||||
|
public void PrerequisitesItemVisible(string key) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -437,6 +437,20 @@ namespace OpenRA.Utility
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
|
|
||||||
|
// RemoveImmediately was replaced with RemoveOnConditions
|
||||||
|
if (engineVersion < 20140821)
|
||||||
|
{
|
||||||
|
if (depth == 1)
|
||||||
|
{
|
||||||
|
if (node.Key == "RemoveImmediately")
|
||||||
|
node.Key = "RemoveOnConditions";
|
||||||
|
|
||||||
|
if (node.Key == "-RemoveImmediately")
|
||||||
|
node.Key = "-RemoveOnConditions";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
Name: Concrete
|
Name: Concrete
|
||||||
Description: Provides a strong foundation that prevents\ndamage from the terrain.
|
Description: Provides a strong foundation that prevents\ndamage from the terrain.
|
||||||
RenderSprites:
|
RenderSprites:
|
||||||
RemoveImmediately:
|
RemoveOnConditions:
|
||||||
|
|
||||||
CONCRETEA:
|
CONCRETEA:
|
||||||
Inherits: ^CONCRETE
|
Inherits: ^CONCRETE
|
||||||
|
|||||||
Reference in New Issue
Block a user