Add Map.GetNamedActor for map actor lookup

This commit is contained in:
ScottNZ
2013-12-20 19:05:24 +13:00
parent 3cf06119f7
commit 09b694095c
3 changed files with 15 additions and 2 deletions

View File

@@ -10,6 +10,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using NLua;
using OpenRA.Effects;
@@ -34,6 +35,7 @@ namespace OpenRA.Mods.RA.Scripting
public class LuaScriptInterface : IWorldLoaded, ITick
{
World world;
Dictionary<string, Actor> mapActors;
readonly LuaScriptContext context = new LuaScriptContext();
readonly LuaScriptInterfaceInfo info;
@@ -45,6 +47,7 @@ namespace OpenRA.Mods.RA.Scripting
public void WorldLoaded(World w, WorldRenderer wr)
{
world = w;
mapActors = world.WorldActor.Trait<SpawnMapActors>().Actors;
context.Lua["World"] = w;
context.Lua["WorldRenderer"] = wr;
@@ -72,7 +75,7 @@ namespace OpenRA.Mods.RA.Scripting
void AddMapActorGlobals()
{
foreach (var kv in world.WorldActor.Trait<SpawnMapActors>().Actors)
foreach (var kv in mapActors)
{
if (context.Lua[kv.Key] != null)
context.ShowErrorMessage("{0}: The global name '{1}' is reserved and may not be used by map actor {2}".F(GetType().Name, kv.Key, kv.Value), null);
@@ -315,5 +318,11 @@ namespace OpenRA.Mods.RA.Scripting
{
return world.ChooseRandomEdgeCell();
}
[LuaGlobal]
public Actor GetNamedActor(string actorName)
{
return mapActors[actorName];
}
}
}

View File

@@ -12,6 +12,10 @@ Map.GetRandomEdgeCell = function()
return Internal.GetRandomEdgeCell()
end
Map.GetNamedActor = function(actorName)
return Internal.GetNamedActor(actorName)
end
CPos.New = function(x, y)
return OpenRA.New("CPos", { { x, "Int32" }, { y, "Int32" } })
end

View File

@@ -72,7 +72,7 @@ end
SendCruisers = function()
for i, cruiser in ipairs(Cruisers) do
local ca = Actor.Create(cruiser, { Owner = england, Location = SouthReinforcementsPoint.Location })
Actor.Move(ca, _G["CruiserPoint" .. i].Location)
Actor.Move(ca, Map.GetNamedActor("CruiserPoint" .. i).Location)
end
end