Add Map.GetNamedActor for map actor lookup
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NLua;
|
using NLua;
|
||||||
using OpenRA.Effects;
|
using OpenRA.Effects;
|
||||||
@@ -34,6 +35,7 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
public class LuaScriptInterface : IWorldLoaded, ITick
|
public class LuaScriptInterface : IWorldLoaded, ITick
|
||||||
{
|
{
|
||||||
World world;
|
World world;
|
||||||
|
Dictionary<string, Actor> mapActors;
|
||||||
readonly LuaScriptContext context = new LuaScriptContext();
|
readonly LuaScriptContext context = new LuaScriptContext();
|
||||||
readonly LuaScriptInterfaceInfo info;
|
readonly LuaScriptInterfaceInfo info;
|
||||||
|
|
||||||
@@ -45,6 +47,7 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
public void WorldLoaded(World w, WorldRenderer wr)
|
public void WorldLoaded(World w, WorldRenderer wr)
|
||||||
{
|
{
|
||||||
world = w;
|
world = w;
|
||||||
|
mapActors = world.WorldActor.Trait<SpawnMapActors>().Actors;
|
||||||
|
|
||||||
context.Lua["World"] = w;
|
context.Lua["World"] = w;
|
||||||
context.Lua["WorldRenderer"] = wr;
|
context.Lua["WorldRenderer"] = wr;
|
||||||
@@ -72,7 +75,7 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
|
|
||||||
void AddMapActorGlobals()
|
void AddMapActorGlobals()
|
||||||
{
|
{
|
||||||
foreach (var kv in world.WorldActor.Trait<SpawnMapActors>().Actors)
|
foreach (var kv in mapActors)
|
||||||
{
|
{
|
||||||
if (context.Lua[kv.Key] != null)
|
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);
|
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();
|
return world.ChooseRandomEdgeCell();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[LuaGlobal]
|
||||||
|
public Actor GetNamedActor(string actorName)
|
||||||
|
{
|
||||||
|
return mapActors[actorName];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ Map.GetRandomEdgeCell = function()
|
|||||||
return Internal.GetRandomEdgeCell()
|
return Internal.GetRandomEdgeCell()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Map.GetNamedActor = function(actorName)
|
||||||
|
return Internal.GetNamedActor(actorName)
|
||||||
|
end
|
||||||
|
|
||||||
CPos.New = function(x, y)
|
CPos.New = function(x, y)
|
||||||
return OpenRA.New("CPos", { { x, "Int32" }, { y, "Int32" } })
|
return OpenRA.New("CPos", { { x, "Int32" }, { y, "Int32" } })
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ end
|
|||||||
SendCruisers = function()
|
SendCruisers = function()
|
||||||
for i, cruiser in ipairs(Cruisers) do
|
for i, cruiser in ipairs(Cruisers) do
|
||||||
local ca = Actor.Create(cruiser, { Owner = england, Location = SouthReinforcementsPoint.Location })
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user