From ba1558259b871a58e365aa9a3ea738c5a2e9b1b2 Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Fri, 7 Feb 2014 22:36:22 +0100 Subject: [PATCH 1/3] Add constants for the 8 main facing values to Lua. Fixes #4490 --- mods/cnc/mod.yaml | 1 + mods/common/lua/facing.lua | 10 ++++++++++ mods/d2k/mod.yaml | 1 + mods/ra/mod.yaml | 1 + mods/ts/mod.yaml | 1 + 5 files changed, 14 insertions(+) create mode 100644 mods/common/lua/facing.lua 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/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 From bfc34df581c622556aae9a4e0d48a95292198b21 Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Sat, 8 Feb 2014 16:04:29 +0100 Subject: [PATCH 2/3] Add Actor.OnDamaged Allows the AI to react to its units being attacked. --- OpenRA.Mods.RA/Scripting/LuaScriptEvents.cs | 8 +++++++- mods/common/lua/actor.lua | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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/mods/common/lua/actor.lua b/mods/common/lua/actor.lua index 1eb1922ab1..613f9b927f 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 From e65626cc6bbe741365ba555a9b3c8b2a5ee85e65 Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Sun, 9 Feb 2014 15:56:29 +0100 Subject: [PATCH 3/3] Add Actor.Guard --- OpenRA.Mods.RA/Guard.cs | 14 ++++++++++---- OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs | 12 ++++++++++++ mods/common/lua/actor.lua | 4 ++++ 3 files changed, 26 insertions(+), 4 deletions(-) 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/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/common/lua/actor.lua b/mods/common/lua/actor.lua index 613f9b927f..a0aca22213 100644 --- a/mods/common/lua/actor.lua +++ b/mods/common/lua/actor.lua @@ -187,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)