Add a number of small helper functions to Lua API

This commit is contained in:
Oliver Brakmann
2014-06-29 19:11:17 +02:00
parent d23707b5f7
commit 882f3f34c2
4 changed files with 68 additions and 7 deletions

View File

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