From 1959820bc88401b418392fbe1554bd75600c8c0e Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 23 Nov 2015 21:24:17 +0000 Subject: [PATCH] Implement enter behaviour for Infiltrates plus other cleanups. --- OpenRA.Mods.RA/Activities/Infiltrate.cs | 23 ++++++++----------- .../Properties/InfiltrateProperties.cs | 13 ++++++++--- .../Traits/Infiltration/Infiltrates.cs | 22 ++++++++++++------ 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/OpenRA.Mods.RA/Activities/Infiltrate.cs b/OpenRA.Mods.RA/Activities/Infiltrate.cs index e443fddbfc..ff08174378 100644 --- a/OpenRA.Mods.RA/Activities/Infiltrate.cs +++ b/OpenRA.Mods.RA/Activities/Infiltrate.cs @@ -18,19 +18,17 @@ namespace OpenRA.Mods.RA.Activities class Infiltrate : Enter { readonly Actor target; - + readonly Stance validStances; readonly Cloak cloak; + readonly string notification; - readonly Infiltrates infiltrates; - - public Infiltrate(Actor self, Actor target) - : base(self, target, EnterBehaviour.Dispose) + public Infiltrate(Actor self, Actor target, EnterBehaviour enterBehaviour, Stance validStances, string notification) + : base(self, target, enterBehaviour) { this.target = target; - + this.validStances = validStances; + this.notification = notification; cloak = self.TraitOrDefault(); - - infiltrates = self.TraitOrDefault(); } protected override void OnInside(Actor self) @@ -39,7 +37,7 @@ namespace OpenRA.Mods.RA.Activities return; var stance = self.Owner.Stances[target.Owner]; - if (!infiltrates.Info.ValidStances.HasStance(stance)) + if (!validStances.HasStance(stance)) return; if (cloak != null && cloak.Info.UncloakOnInfiltrate) @@ -48,10 +46,9 @@ namespace OpenRA.Mods.RA.Activities foreach (var t in target.TraitsImplementing()) t.Infiltrated(target, self); - self.Dispose(); - - if (target.Info.HasTraitInfo()) - Game.Sound.PlayToPlayer(self.Owner, "bldginf1.aud"); + if (!string.IsNullOrEmpty(notification)) + Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", + notification, self.Owner.Faction.InternalName); } } } diff --git a/OpenRA.Mods.RA/Scripting/Properties/InfiltrateProperties.cs b/OpenRA.Mods.RA/Scripting/Properties/InfiltrateProperties.cs index 53e81b9a5e..41bd1c98f0 100644 --- a/OpenRA.Mods.RA/Scripting/Properties/InfiltrateProperties.cs +++ b/OpenRA.Mods.RA/Scripting/Properties/InfiltrateProperties.cs @@ -8,22 +8,29 @@ */ #endregion +using OpenRA.Mods.Common.Traits; using OpenRA.Mods.RA.Activities; +using OpenRA.Mods.RA.Traits; using OpenRA.Scripting; +using OpenRA.Traits; namespace OpenRA.Mods.RA.Scripting { [ScriptPropertyGroup("Ability")] - public class InfiltrateProperties : ScriptActorProperties + public class InfiltrateProperties : ScriptActorProperties, Requires { + readonly InfiltratesInfo info; + public InfiltrateProperties(ScriptContext context, Actor self) : base(context, self) - { } + { + info = Self.Info.TraitInfo(); + } [Desc("Infiltrate the target actor.")] public void Infiltrate(Actor target) { - Self.QueueActivity(new Infiltrate(Self, target)); + Self.QueueActivity(new Infiltrate(Self, target, info.EnterBehaviour, info.ValidStances, info.Notification)); } } } diff --git a/OpenRA.Mods.RA/Traits/Infiltration/Infiltrates.cs b/OpenRA.Mods.RA/Traits/Infiltration/Infiltrates.cs index dc2fa3a2e1..2d247b94f1 100644 --- a/OpenRA.Mods.RA/Traits/Infiltration/Infiltrates.cs +++ b/OpenRA.Mods.RA/Traits/Infiltration/Infiltrates.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using OpenRA.Mods.Common; +using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Orders; using OpenRA.Mods.RA.Activities; using OpenRA.Traits; @@ -27,21 +28,28 @@ namespace OpenRA.Mods.RA.Traits [Desc("What diplomatic stances can be infiltrated by this actor.")] public readonly Stance ValidStances = Stance.Neutral | Stance.Enemy; + [Desc("Behaviour when entering the structure.", + "Possible values are Exit, Suicide, Dispose.")] + public readonly EnterBehaviour EnterBehaviour = EnterBehaviour.Dispose; + + [Desc("Notification to play when a building is infiltrated.")] + public readonly string Notification = "BuildingInfiltrated"; + public object Create(ActorInitializer init) { return new Infiltrates(this); } } class Infiltrates : IIssueOrder, IResolveOrder, IOrderVoice { - public readonly InfiltratesInfo Info; + readonly InfiltratesInfo info; public Infiltrates(InfiltratesInfo info) { - Info = info; + this.info = info; } public IEnumerable Orders { - get { yield return new InfiltrationOrderTargeter(Info); } + get { yield return new InfiltrationOrderTargeter(info); } } public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued) @@ -79,13 +87,13 @@ namespace OpenRA.Mods.RA.Traits else targetTypes = order.TargetActor.GetEnabledTargetTypes(); - return Info.Types.Overlaps(targetTypes); + return info.Types.Overlaps(targetTypes); } public string VoicePhraseForOrder(Actor self, Order order) { return order.OrderString == "Infiltrate" && IsValidOrder(self, order) - ? Info.Voice : null; + ? info.Voice : null; } public void ResolveOrder(Actor self, Order order) @@ -95,14 +103,14 @@ namespace OpenRA.Mods.RA.Traits var target = self.ResolveFrozenActorOrder(order, Color.Red); if (target.Type != TargetType.Actor - || !Info.Types.Overlaps(target.Actor.GetAllTargetTypes())) + || !info.Types.Overlaps(target.Actor.GetAllTargetTypes())) return; if (!order.Queued) self.CancelActivity(); self.SetTargetLine(target, Color.Red); - self.QueueActivity(new Infiltrate(self, target.Actor)); + self.QueueActivity(new Infiltrate(self, target.Actor, info.EnterBehaviour, info.ValidStances, info.Notification)); } }