diff --git a/OpenRA.Mods.RA/Scripting/Global/CoordinateGlobals.cs b/OpenRA.Mods.RA/Scripting/Global/CoordinateGlobals.cs index dcc1763c22..f4c1775456 100644 --- a/OpenRA.Mods.RA/Scripting/Global/CoordinateGlobals.cs +++ b/OpenRA.Mods.RA/Scripting/Global/CoordinateGlobals.cs @@ -65,5 +65,8 @@ namespace OpenRA.Scripting [Desc("Create a new WRange.")] public WRange New(int r) { return new WRange(r); } + + [Desc("Create a new WRange by cell distance")] + public WRange FromCells(int numCells) { return WRange.FromCells(numCells); } } } diff --git a/OpenRA.Mods.RA/Scripting/Global/MapGlobal.cs b/OpenRA.Mods.RA/Scripting/Global/MapGlobal.cs index 34c61859f0..d7d45366f7 100644 --- a/OpenRA.Mods.RA/Scripting/Global/MapGlobal.cs +++ b/OpenRA.Mods.RA/Scripting/Global/MapGlobal.cs @@ -8,6 +8,7 @@ */ #endregion +using System; using System.Linq; using Eluant; using OpenRA.Scripting; @@ -43,6 +44,34 @@ namespace OpenRA.Mods.RA.Scripting return actors.ToLuaTable(context); } + [Desc("Returns a table of all actors within the requested rectangle, filtered using the specified function.")] + public LuaTable ActorsInBox(WPos topLeft, WPos bottomRight, LuaFunction filter = null) + { + var actors = context.World.ActorMap.ActorsInBox(topLeft, bottomRight) + .Select(a => a.ToLuaValue(context)); + + if (filter != null) + actors = actors.Where(a => + { + using (var f = filter.Call(a)) + return f.First().ToBoolean(); + }); + + return actors.ToLuaTable(context); + } + + [Desc("Returns the location of the top-left corner of the map.")] + public WPos TopLeft + { + get { return new WPos(context.World.Map.Bounds.Left * 1024, context.World.Map.Bounds.Top * 1024, 0); } + } + + [Desc("Returns the location of the bottom-right corner of the map.")] + public WPos BottomRight + { + get { return new WPos(context.World.Map.Bounds.Right * 1024, context.World.Map.Bounds.Bottom * 1024, 0); } + } + [Desc("Returns a random cell inside the visible region of the map.")] public CPos RandomCell() { diff --git a/OpenRA.Mods.RA/Scripting/Global/UtilsGlobal.cs b/OpenRA.Mods.RA/Scripting/Global/UtilsGlobal.cs index cb330e43cb..95b9c089e3 100644 --- a/OpenRA.Mods.RA/Scripting/Global/UtilsGlobal.cs +++ b/OpenRA.Mods.RA/Scripting/Global/UtilsGlobal.cs @@ -58,6 +58,17 @@ namespace OpenRA.Mods.RA.Scripting return true; } + [Desc("Skips over the first numElements members of the array and returns the rest")] + public LuaTable Skip(LuaTable table, int numElements) + { + var t = context.CreateTable(); + + for (var i = numElements; i <= table.Count; i++) + t.Add(t.Count + 1, table[i]); + + return t; + } + [Desc("Returns a random value from table.")] public LuaValue Random(LuaTable table) { @@ -94,5 +105,17 @@ namespace OpenRA.Mods.RA.Scripting { return context.World.Map.CenterOfCell(cell); } + + [Desc("Converts the number of seconds into game time (ticks).")] + public int Seconds(int seconds) + { + return seconds * 25; + } + + [Desc("Converts the number of minutes into game time (ticks).")] + public int Minutes(int minutes) + { + return Seconds(minutes * 60); + } } } diff --git a/OpenRA.Mods.RA/Scripting/Properties/PlayerProperties.cs b/OpenRA.Mods.RA/Scripting/Properties/PlayerProperties.cs index 707990fbd8..ee1e52a064 100644 --- a/OpenRA.Mods.RA/Scripting/Properties/PlayerProperties.cs +++ b/OpenRA.Mods.RA/Scripting/Properties/PlayerProperties.cs @@ -9,22 +9,28 @@ #endregion using System; +using System.Linq; +using Eluant; using OpenRA.Scripting; +using OpenRA.Mods.RA.Move; namespace OpenRA.Mods.RA.Scripting { [ScriptPropertyGroup("Player")] public class PlayerProperties : ScriptPlayerProperties { - readonly Player p; - public PlayerProperties(ScriptContext context, Player player) - : base(context, player) - { - p = player; - } + : base(context, player) { } [Desc("The player's name.")] - public string PlayerName { get { return p.PlayerName; } } + public string Name { get { return player.PlayerName; } } + + [Desc("Returns an array of actors representing all ground attack units of this player.")] + public LuaTable GetGroundAttackers() + { + return player.World.ActorsWithTrait().Select(a => a.Actor) + .Where(a => a.Owner == player && !a.IsDead() && a.IsInWorld && a.HasTrait()) + .Select(a => a.ToLuaValue(context)).ToLuaTable(context); + } } }