Merge pull request #4662 from obrakmann/lua

Add Actor.Guard, Actor.OnDamaged and constants for facing values to Lua interface
This commit is contained in:
Matthias Mailänder
2014-02-19 00:09:38 +01:00
9 changed files with 51 additions and 5 deletions

View File

@@ -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<GuardableInfo>().Range);
self.QueueActivity(false, new AttackMove.AttackMoveActivity(self, self.Trait<IMove>().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<GuardableInfo>().Range);
self.QueueActivity(false, new AttackMove.AttackMoveActivity(self, self.Trait<IMove>().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 { }
}
}

View File

@@ -15,12 +15,13 @@ namespace OpenRA.Mods.RA.Scripting
{
public class LuaScriptEventsInfo : TraitInfo<LuaScriptEvents> { }
public class LuaScriptEvents : INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyCapture
public class LuaScriptEvents : INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyCapture, INotifyDamage
{
public event Action<Actor, AttackInfo> OnKilled = (self, e) => { };
public event Action<Actor> OnAddedToWorld = self => { };
public event Action<Actor> OnRemovedFromWorld = self => { };
public event Action<Actor, Actor, Player, Player> OnCaptured = (self, captor, oldOwner, newOwner) => { };
public event Action<Actor, AttackInfo> 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);
}
}
}

View File

@@ -372,5 +372,17 @@ namespace OpenRA.Mods.RA.Scripting
factory.Trait<ProductionQueue>().ResolveOrder(factory, Order.StartProduction(factory, unit, (int)amount));
}
[LuaGlobal]
public void Guard(Actor guard, Actor target)
{
if (target.HasTrait<Guardable>())
{
var gt = guard.TraitOrDefault<Guard>();
if (gt != null)
gt.GuardTarget(guard, Target.FromActor(target));
}
}
}
}

View File

@@ -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

View File

@@ -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)

View File

@@ -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" }

View File

@@ -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

View File

@@ -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

View File

@@ -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