Replace RemoveOnConditions with KillsSelf.

Upgrades offer more flexibility than prerequisites.
This commit is contained in:
Paul Chote
2014-09-28 21:03:27 +13:00
parent bb44d76762
commit abba61dd8c
5 changed files with 80 additions and 81 deletions

View File

@@ -620,6 +620,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (depth == 1 && node.Key == "-IronCurtainable")
node.Key = "-InvulnerabilityUpgrade@IRONCURTAIN";
// Replaced RemoveOnConditions with KillsSelf
if (depth == 1 && node.Key == "RemoveOnConditions")
{
node.Key = "KillsSelf";
node.Value.Nodes.Add(new MiniYamlNode("RemoveInstead", new MiniYaml("true")));
}
}
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);

View File

@@ -0,0 +1,71 @@
#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
{
class KillsSelfInfo : ITraitInfo
{
[Desc("Enable only if this upgrade is enabled.")]
public readonly string RequiresUpgrade = null;
[Desc("Remove the actor from the world (and destroy it) instead of killing it.")]
public readonly bool RemoveInstead = false;
public object Create(ActorInitializer init) { return new KillsSelf(init.self, this); }
}
class KillsSelf : INotifyAddedToWorld, IUpgradable
{
readonly KillsSelfInfo info;
readonly Actor self;
public KillsSelf(Actor self, KillsSelfInfo info)
{
this.info = info;
this.self = self;
}
public void AddedToWorld(Actor self)
{
if (info.RequiresUpgrade == null)
Kill();
}
public bool AcceptsUpgrade(string type)
{
return type == info.RequiresUpgrade;
}
public void UpgradeAvailable(Actor self, string type, bool available)
{
if (type == info.RequiresUpgrade)
Kill();
}
void Kill()
{
if (self.IsDead())
return;
if (info.RemoveInstead || !self.HasTrait<Health>())
self.Destroy();
else
self.Kill(self);
}
}
}

View File

@@ -295,7 +295,6 @@
<Compile Include="Warheads\CreateEffectWarhead.cs" />
<Compile Include="Warheads\CreateResourceWarhead.cs" />
<Compile Include="Warheads\LeaveSmudgeWarhead.cs" />
<Compile Include="RemoveOnConditions.cs" />
<Compile Include="Widgets\Logic\TabCompletionLogic.cs" />
<Compile Include="World\RadarPings.cs" />
<Compile Include="Player\TechTree.cs" />

View File

@@ -1,79 +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 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) { }
}
}

View File

@@ -11,7 +11,8 @@
Name: Concrete
Description: Provides a strong foundation that prevents\ndamage from the terrain.
RenderSprites:
RemoveOnConditions:
KillsSelf:
RemoveInstead: true
CONCRETEA:
Inherits: ^CONCRETE