From 1caf982c1ff2e96963acf3aec49ad7c7714c68cf Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 21 Oct 2017 13:29:07 +0000 Subject: [PATCH] Support multiple capture types on Capturable. --- .../Scripting/Properties/CaptureProperties.cs | 4 ++-- OpenRA.Mods.Common/Traits/Capturable.cs | 9 ++++++--- OpenRA.Mods.Common/Traits/ExternalCapturable.cs | 9 ++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.Common/Scripting/Properties/CaptureProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/CaptureProperties.cs index 821d843d82..7660cba6e5 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/CaptureProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/CaptureProperties.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Scripting if (capturable != null) { - if (captures.Any(x => !x.IsTraitDisabled && x.Info.CaptureTypes.Contains(capturable.Type))) + if (captures.Any(x => !x.IsTraitDisabled && x.Info.CaptureTypes.Overlaps(capturable.Types))) { Self.QueueActivity(new CaptureActor(Self, target)); return; @@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Scripting var externalCapturable = target.Info.TraitInfoOrDefault(); - if (externalInfo != null && externalCapturable != null && externalInfo.CaptureTypes.Contains(externalCapturable.Type)) + if (externalInfo != null && externalCapturable != null && externalInfo.CaptureTypes.Overlaps(externalCapturable.Types)) Self.QueueActivity(new ExternalCaptureActor(Self, Target.FromActor(target))); else throw new LuaException("Actor '{0}' cannot capture actor '{1}'!".F(Self, target)); diff --git a/OpenRA.Mods.Common/Traits/Capturable.cs b/OpenRA.Mods.Common/Traits/Capturable.cs index 158cb43f8c..397d9fb891 100644 --- a/OpenRA.Mods.Common/Traits/Capturable.cs +++ b/OpenRA.Mods.Common/Traits/Capturable.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Collections.Generic; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -16,11 +17,13 @@ namespace OpenRA.Mods.Common.Traits [Desc("This actor can be captured by a unit with Captures: trait.")] public class CapturableInfo : ITraitInfo { - [Desc("Type listed under Types in Captures: trait of actors that can capture this).")] - public readonly string Type = "building"; + [Desc("CaptureTypes (from the Captures trait) that are able to capture this.")] + public readonly HashSet Types = new HashSet() { "building" }; + public readonly bool AllowAllies = false; public readonly bool AllowNeutral = true; public readonly bool AllowEnemies = true; + [Desc("Health percentage the target must be at (or below) before it can be captured.")] public readonly int CaptureThreshold = 50; public readonly bool CancelActivity = false; @@ -43,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits if (playerRelationship == Stance.Neutral && !AllowNeutral) return false; - if (!c.CaptureTypes.Contains(Type)) + if (!c.CaptureTypes.Overlaps(Types)) return false; return true; diff --git a/OpenRA.Mods.Common/Traits/ExternalCapturable.cs b/OpenRA.Mods.Common/Traits/ExternalCapturable.cs index 1ba0cd9369..8d16955f8d 100644 --- a/OpenRA.Mods.Common/Traits/ExternalCapturable.cs +++ b/OpenRA.Mods.Common/Traits/ExternalCapturable.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Collections.Generic; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -16,11 +17,13 @@ namespace OpenRA.Mods.Common.Traits [Desc("This actor can be captured by a unit with ExternalCaptures: trait.")] public class ExternalCapturableInfo : ITraitInfo { - [Desc("Type of actor (the ExternalCaptures: trait defines what Types it can capture).")] - public readonly string Type = "building"; + [Desc("CaptureTypes (from the ExternalCaptures trait) that are able to capture this.")] + public readonly HashSet Types = new HashSet() { "building" }; + public readonly bool AllowAllies = false; public readonly bool AllowNeutral = true; public readonly bool AllowEnemies = true; + [Desc("Seconds it takes to change the owner.", "You might want to add a ExternalCapturableBar: trait, too.")] public readonly int CaptureCompleteTime = 15; @@ -43,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits if (playerRelationship == Stance.Neutral && !AllowNeutral) return false; - if (!c.CaptureTypes.Contains(Type)) + if (!c.CaptureTypes.Overlaps(Types)) return false; return true;