diff --git a/OpenRA.Mods.RA/Scripting/Global/TriggerGlobal.cs b/OpenRA.Mods.RA/Scripting/Global/TriggerGlobal.cs index 4e8cdf98e2..9d79d150e9 100644 --- a/OpenRA.Mods.RA/Scripting/Global/TriggerGlobal.cs +++ b/OpenRA.Mods.RA/Scripting/Global/TriggerGlobal.cs @@ -278,6 +278,13 @@ namespace OpenRA.Mods.RA.Scripting context.World.ActorMap.RemoveCellTrigger(id); } + [Desc("Call a function when this actor is infiltrated. The callback function " + + "will be called as func(Actor self, Actor infiltrator).")] + public void OnInfiltrated(Actor a, LuaFunction func) + { + GetScriptTriggers(a).RegisterCallback(Trigger.OnInfiltrated, func, context); + } + [Desc("Removes all triggers from this actor.")] public void ClearAll(Actor a) { diff --git a/OpenRA.Mods.RA/Scripting/ScriptTriggers.cs b/OpenRA.Mods.RA/Scripting/ScriptTriggers.cs index 3c8926d707..ffbe4902b1 100644 --- a/OpenRA.Mods.RA/Scripting/ScriptTriggers.cs +++ b/OpenRA.Mods.RA/Scripting/ScriptTriggers.cs @@ -19,7 +19,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Scripting { public enum Trigger { OnIdle, OnDamaged, OnKilled, OnProduction, OnOtherProduction, OnPlayerWon, OnPlayerLost, - OnObjectiveAdded, OnObjectiveCompleted, OnObjectiveFailed, OnCapture, OnAddedToWorld, OnRemovedFromWorld }; + OnObjectiveAdded, OnObjectiveCompleted, OnObjectiveFailed, OnCapture, OnInfiltrated, OnAddedToWorld, OnRemovedFromWorld }; [Desc("Allows map scripts to attach triggers to this actor via the Triggers global.")] public class ScriptTriggersInfo : ITraitInfo @@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Scripting public object Create(ActorInitializer init) { return new ScriptTriggers(init.world); } } - public sealed class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction, INotifyOtherProduction, INotifyObjectivesUpdated, INotifyCapture, INotifyAddedToWorld, INotifyRemovedFromWorld, IDisposable + public sealed class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction, INotifyOtherProduction, INotifyObjectivesUpdated, INotifyCapture, INotifyInfiltrated, INotifyAddedToWorld, INotifyRemovedFromWorld, IDisposable { readonly World world; @@ -238,6 +238,24 @@ namespace OpenRA.Mods.RA.Scripting } } + public void Infiltrated(Actor self, Actor infiltrator) + { + foreach (var f in Triggers[Trigger.OnInfiltrated]) + { + try + { + using (var a = self.ToLuaValue(f.Second)) + using (var b = infiltrator.ToLuaValue(f.Second)) + f.First.Call(a, b).Dispose(); + } + catch (Exception ex) + { + f.Second.FatalError(ex.Message); + return; + } + } + } + public void AddedToWorld(Actor self) { foreach (var f in Triggers[Trigger.OnAddedToWorld])