Added more Lua functions

This commit is contained in:
Curtis Shmyr
2014-08-15 19:51:02 -06:00
parent 780fd0df29
commit cb4bd52fc0
7 changed files with 140 additions and 4 deletions

View File

@@ -57,4 +57,13 @@ namespace OpenRA.Scripting
[Desc("The world zero-vector.")]
public WVec Zero { get { return WVec.Zero; } }
}
[ScriptGlobal("WRange")]
public class WRangeGlobal : ScriptGlobal
{
public WRangeGlobal(ScriptContext context) : base(context) { }
[Desc("Create a new WRange.")]
public WRange New(int r) { return new WRange(r); }
}
}

View File

@@ -28,15 +28,18 @@ namespace OpenRA.Mods.RA.Scripting
}
[Desc("Returns a table of all actors within the requested region, filtered using the specified function.")]
public LuaTable ActorsInCircle(WPos location, WRange radius, LuaFunction filter)
public LuaTable ActorsInCircle(WPos location, WRange radius, LuaFunction filter = null)
{
var actors = context.World.FindActorsInCircle(location, radius)
.Select(a => a.ToLuaValue(context))
.Where(a =>
.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);
}
@@ -72,9 +75,13 @@ namespace OpenRA.Mods.RA.Scripting
public Actor NamedActor(string actorName)
{
Actor ret;
if (!sma.Actors.TryGetValue(actorName, out ret))
return null;
if (ret.Destroyed)
return null;
return ret;
}

View File

@@ -56,6 +56,9 @@ namespace OpenRA.Mods.RA.Scripting
[Desc("The player that owns the actor.")]
public Player Owner { get { return self.Owner; } }
[Desc("The type of the actor (e.g. \"e1\").")]
public string Type { get { return self.Info.Name; } }
[Desc("The direction that the actor is facing.")]
public int Facing
{

View File

@@ -0,0 +1,34 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using OpenRA.Scripting;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Scripting
{
[ScriptPropertyGroup("Guard")]
public class GuardProperties : ScriptActorProperties, Requires<GuardInfo>, Requires<IMoveInfo>
{
Guard guard;
public GuardProperties(Actor self)
: base(self)
{
guard = self.Trait<Guard>();
}
[ScriptActorPropertyActivity]
[Desc("Guard the target actor.")]
public void Guard(Actor targetActor)
{
if (targetActor.HasTrait<Guardable>())
guard.GuardTarget(self, Target.FromActor(targetActor));
}
}
}

View File

@@ -0,0 +1,30 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using OpenRA.Scripting;
namespace OpenRA.Mods.RA.Scripting
{
[ScriptPropertyGroup("Player")]
public class PlayerProperties : ScriptPlayerProperties
{
readonly Player p;
public PlayerProperties(Player player)
: base(player)
{
p = player;
}
[Desc("The player's name.")]
public string PlayerName { get { return p.PlayerName; } }
}
}