diff --git a/OpenRA.Mods.RA/Guard.cs b/OpenRA.Mods.RA/Guard.cs index 9014c2baf2..7fc5e7e9ee 100644 --- a/OpenRA.Mods.RA/Guard.cs +++ b/OpenRA.Mods.RA/Guard.cs @@ -27,13 +27,19 @@ namespace OpenRA.Mods.RA if (order.OrderString == "Guard") { var target = Target.FromActor(order.TargetActor); - self.SetTargetLine(target, Color.Yellow); - var range = WRange.FromCells(target.Actor.Info.Traits.Get().Range); - self.QueueActivity(false, new AttackMove.AttackMoveActivity(self, self.Trait().MoveFollow(self, target, range))); + GuardTarget(self, target); } } + public void GuardTarget(Actor self, Target target) + { + self.SetTargetLine(target, Color.Yellow); + + var range = WRange.FromCells(target.Actor.Info.Traits.Get().Range); + self.QueueActivity(false, new AttackMove.AttackMoveActivity(self, self.Trait().MoveFollow(self, target, range))); + } + public string VoicePhraseForOrder(Actor self, Order order) { return order.OrderString == "Guard" ? "Move" : null; @@ -100,4 +106,4 @@ namespace OpenRA.Mods.RA } class Guardable { } -} \ No newline at end of file +} diff --git a/OpenRA.Mods.RA/Scripting/LuaScriptEvents.cs b/OpenRA.Mods.RA/Scripting/LuaScriptEvents.cs index f321920777..40b2778583 100644 --- a/OpenRA.Mods.RA/Scripting/LuaScriptEvents.cs +++ b/OpenRA.Mods.RA/Scripting/LuaScriptEvents.cs @@ -15,12 +15,13 @@ namespace OpenRA.Mods.RA.Scripting { public class LuaScriptEventsInfo : TraitInfo { } - public class LuaScriptEvents : INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyCapture + public class LuaScriptEvents : INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyCapture, INotifyDamage { public event Action OnKilled = (self, e) => { }; public event Action OnAddedToWorld = self => { }; public event Action OnRemovedFromWorld = self => { }; public event Action OnCaptured = (self, captor, oldOwner, newOwner) => { }; + public event Action OnDamaged = (self, e) => { }; public void Killed(Actor self, AttackInfo e) { @@ -41,5 +42,10 @@ namespace OpenRA.Mods.RA.Scripting { OnCaptured(self, captor, oldOwner, newOwner); } + + public void Damaged(Actor self, AttackInfo e) + { + OnDamaged(self, e); + } } } diff --git a/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs b/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs index 1861c770cb..10fab7b688 100644 --- a/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs +++ b/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs @@ -372,5 +372,17 @@ namespace OpenRA.Mods.RA.Scripting factory.Trait().ResolveOrder(factory, Order.StartProduction(factory, unit, (int)amount)); } + + [LuaGlobal] + public void Guard(Actor guard, Actor target) + { + if (target.HasTrait()) + { + var gt = guard.TraitOrDefault(); + + if (gt != null) + gt.GuardTarget(guard, Target.FromActor(target)); + } + } } } diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 82a28d7449..15e6a85a68 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -181,3 +181,4 @@ LuaScripts: mods/common/lua/supportpowers.lua mods/common/lua/rules.lua mods/common/lua/production.lua + mods/common/lua/facing.lua diff --git a/mods/common/lua/actor.lua b/mods/common/lua/actor.lua index 1eb1922ab1..a0aca22213 100644 --- a/mods/common/lua/actor.lua +++ b/mods/common/lua/actor.lua @@ -143,6 +143,10 @@ Actor.SetStance = function(actor, stance) Internal.SetUnitStance(actor, stance) end +Actor.OnDamaged = function(actor, eh) + Actor.Trait(actor, "LuaScriptEvents").OnDamaged:Add(eh) +end + Actor.OnKilled = function(actor, eh) Actor.Trait(actor, "LuaScriptEvents").OnKilled:Add(eh) end @@ -183,6 +187,10 @@ Actor.ReturnToBase = function(actor, airfield) actor:QueueActivity(OpenRA.New("ReturnToBase", { actor, airfield })) end +Actor.Guard = function(actor, target) + Internal.Guard(actor, target) +end + Actor.Patrol = function(actor, waypoints, wait, loop) Utils.Do(waypoints, function(wpt) Actor.AttackMove(actor, wpt.Location, 3) diff --git a/mods/common/lua/facing.lua b/mods/common/lua/facing.lua new file mode 100644 index 0000000000..827d3c6890 --- /dev/null +++ b/mods/common/lua/facing.lua @@ -0,0 +1,10 @@ +Facing = { } + +Facing.North = { 0, "Int32" } +Facing.NorthWest = { 32, "Int32" } +Facing.West = { 64, "Int32" } +Facing.SouthWest = { 96, "Int32" } +Facing.South = { 128, "Int32" } +Facing.SouthEast = { 160, "Int32" } +Facing.East = { 192, "Int32" } +Facing.NorthEast = { 224, "Int32" } diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index 2173f2b60a..0f03ded15d 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -162,3 +162,4 @@ LuaScripts: mods/common/lua/supportpowers.lua mods/common/lua/rules.lua mods/common/lua/production.lua + mods/common/lua/facing.lua diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index acf490c4e3..2ece64366a 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -178,3 +178,4 @@ LuaScripts: mods/common/lua/supportpowers.lua mods/common/lua/rules.lua mods/common/lua/production.lua + mods/common/lua/facing.lua diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index 6d339fdc35..07c4d5f72f 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -200,3 +200,4 @@ LuaScripts: mods/common/lua/supportpowers.lua mods/common/lua/rules.lua mods/common/lua/production.lua + mods/common/lua/facing.lua