Remove legacy Lua API.
This commit is contained in:
7
AUTHORS
7
AUTHORS
@@ -111,13 +111,6 @@ the Apache 2.0 license.
|
||||
Using GeoLite2 data created by MaxMind and
|
||||
distributed under the CC BY-SA 3.0 license.
|
||||
|
||||
Using KopiLua created by Mark Feldman and
|
||||
maintained by Vinicius Jarina and distributed
|
||||
under the MIT license.
|
||||
|
||||
Using NLua created by Vinicius Jarina and
|
||||
distributed under the MIT license.
|
||||
|
||||
Using SharpFont created by Robert Rouhani and
|
||||
distributed under the MIT license.
|
||||
|
||||
|
||||
4
Makefile
4
Makefile
@@ -120,7 +120,7 @@ mod_common: $(mod_common_TARGET)
|
||||
|
||||
##### Official Mods #####
|
||||
|
||||
STD_MOD_LIBS = $(game_TARGET) thirdparty/KopiLua.dll thirdparty/NLua.dll
|
||||
STD_MOD_LIBS = $(game_TARGET)
|
||||
STD_MOD_DEPS = $(STD_MOD_LIBS) $(ralint_TARGET)
|
||||
|
||||
|
||||
@@ -341,8 +341,6 @@ install-core: default
|
||||
@$(INSTALL_PROGRAM) SharpFont.dll "$(DATA_INSTALL_DIR)"
|
||||
@$(CP) SharpFont.dll.config "$(DATA_INSTALL_DIR)"
|
||||
@$(INSTALL_PROGRAM) Mono.Nat.dll "$(DATA_INSTALL_DIR)"
|
||||
@$(INSTALL_PROGRAM) KopiLua.dll "$(DATA_INSTALL_DIR)"
|
||||
@$(INSTALL_PROGRAM) NLua.dll "$(DATA_INSTALL_DIR)"
|
||||
@$(INSTALL_PROGRAM) MaxMind.Db.dll "$(DATA_INSTALL_DIR)"
|
||||
@$(INSTALL_PROGRAM) MaxMind.GeoIP2.dll "$(DATA_INSTALL_DIR)"
|
||||
@$(INSTALL_PROGRAM) Newtonsoft.Json.dll "$(DATA_INSTALL_DIR)"
|
||||
|
||||
@@ -53,14 +53,6 @@
|
||||
<HintPath>..\thirdparty\FuzzyLogicLibrary.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="KopiLua">
|
||||
<HintPath>..\thirdparty\KopiLua.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="NLua">
|
||||
<HintPath>..\thirdparty\NLua.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
@@ -324,10 +316,7 @@
|
||||
<Compile Include="RepairsUnits.cs" />
|
||||
<Compile Include="Reservable.cs" />
|
||||
<Compile Include="ScaredyCat.cs" />
|
||||
<Compile Include="Scripting\LuaScriptEvents.cs" />
|
||||
<Compile Include="Scripting\LuaScriptInterface.cs" />
|
||||
<Compile Include="Scripting\Media.cs" />
|
||||
<Compile Include="Scripting\LuaScriptContext.cs" />
|
||||
<Compile Include="SeedsResource.cs" />
|
||||
<Compile Include="SelfHealing.cs" />
|
||||
<Compile Include="Sellable.cs" />
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
#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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using NLua;
|
||||
using NLua.Event;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[Desc("Part of the legacy Lua API.")]
|
||||
public sealed class LuaScriptContext : IDisposable
|
||||
{
|
||||
public Lua Lua { get; private set; }
|
||||
readonly Cache<string, LuaFunction> functionCache;
|
||||
|
||||
public LuaScriptContext()
|
||||
{
|
||||
Log.AddChannel("lua", "lua.log");
|
||||
Log.Write("lua", "Creating Lua script context");
|
||||
Lua = new Lua();
|
||||
Lua.HookException += OnLuaException;
|
||||
functionCache = new Cache<string, LuaFunction>(Lua.GetFunction);
|
||||
}
|
||||
|
||||
public void RegisterObject(object target, string tableName, bool exposeAllMethods)
|
||||
{
|
||||
Log.Write("lua", "Registering object {0}", target);
|
||||
|
||||
if (tableName != null && Lua.GetTable(tableName) == null)
|
||||
Lua.NewTable(tableName);
|
||||
|
||||
var type = target.GetType();
|
||||
|
||||
var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
|
||||
RegisterMethods(tableName, target, methods, exposeAllMethods);
|
||||
}
|
||||
|
||||
public void RegisterType(Type type, string tableName, bool exposeAllMethods)
|
||||
{
|
||||
Log.Write("lua", "Registering type {0}", type);
|
||||
|
||||
if (tableName != null && Lua.GetTable(tableName) == null)
|
||||
Lua.NewTable(tableName);
|
||||
|
||||
var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Static);
|
||||
RegisterMethods(tableName, null, methods, exposeAllMethods);
|
||||
}
|
||||
|
||||
void RegisterMethods(string tableName, object target, IEnumerable<MethodInfo> methods, bool allMethods)
|
||||
{
|
||||
foreach (var method in methods)
|
||||
{
|
||||
string methodName;
|
||||
|
||||
var attr = method.GetCustomAttributes<LuaGlobalAttribute>(true).FirstOrDefault();
|
||||
if (attr == null)
|
||||
{
|
||||
if (allMethods)
|
||||
methodName = method.Name;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
else
|
||||
methodName = attr.Name ?? method.Name;
|
||||
|
||||
var methodTarget = method.IsStatic ? null : target;
|
||||
|
||||
if (tableName != null)
|
||||
Lua.RegisterFunction(tableName + "." + methodName, methodTarget, method);
|
||||
else
|
||||
Lua.RegisterFunction(methodName, methodTarget, method);
|
||||
}
|
||||
}
|
||||
|
||||
void OnLuaException(object sender, HookExceptionEventArgs e)
|
||||
{
|
||||
ShowException(e.Exception);
|
||||
}
|
||||
|
||||
void ShowException(Exception e)
|
||||
{
|
||||
ShowErrorMessage(e.Message, e.ToString());
|
||||
}
|
||||
|
||||
public void ShowErrorMessage(string shortMessage, string longMessage)
|
||||
{
|
||||
Game.Debug("{0}", shortMessage);
|
||||
Game.Debug("See lua.log for details");
|
||||
Log.Write("lua", "{0}", longMessage ?? shortMessage);
|
||||
}
|
||||
|
||||
public void LoadLuaScripts(Func<string, string> getFileContents, params string[] files)
|
||||
{
|
||||
foreach (var file in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.Write("lua", "Loading Lua script {0}", file);
|
||||
var content = getFileContents(file);
|
||||
Lua.DoString(content, file);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ShowException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object[] InvokeLuaFunction(string name, params object[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
var function = functionCache[name];
|
||||
if (function == null)
|
||||
return null;
|
||||
return function.Call(args);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ShowException(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Lua != null)
|
||||
Lua.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
#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.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[Desc("Part of the legacy Lua API.")]
|
||||
public class LuaScriptEventsInfo : TraitInfo<LuaScriptEvents> { }
|
||||
|
||||
public class LuaScriptEvents : INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld,
|
||||
INotifyCapture, INotifyDamage, INotifyIdle, INotifyProduction
|
||||
{
|
||||
public event Action<Actor, AttackInfo> OnKilled = (self, e) => { };
|
||||
public event Action<Actor> OnAddedToWorld = self => { };
|
||||
public event Action<Actor> OnRemovedFromWorld = self => { };
|
||||
public event Action<Actor, Actor, Player, Player> OnCaptured = (self, captor, oldOwner, newOwner) => { };
|
||||
public event Action<Actor, AttackInfo> OnDamaged = (self, e) => { };
|
||||
public event Action<Actor> OnIdle = self => { };
|
||||
public event Action<Actor, Actor, CPos> OnProduced = (self, other, exit) => { };
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
{
|
||||
OnKilled(self, e);
|
||||
}
|
||||
|
||||
public void AddedToWorld(Actor self)
|
||||
{
|
||||
OnAddedToWorld(self);
|
||||
}
|
||||
|
||||
public void RemovedFromWorld(Actor self)
|
||||
{
|
||||
OnRemovedFromWorld(self);
|
||||
}
|
||||
|
||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
OnCaptured(self, captor, oldOwner, newOwner);
|
||||
}
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
OnDamaged(self, e);
|
||||
}
|
||||
|
||||
public void TickIdle(Actor self)
|
||||
{
|
||||
OnIdle(self);
|
||||
}
|
||||
|
||||
public void UnitProduced(Actor self, Actor other, CPos exit)
|
||||
{
|
||||
OnProduced(self, other, exit);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,470 +0,0 @@
|
||||
#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 System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLua;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Air;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Traits;
|
||||
using WorldRenderer = OpenRA.Graphics.WorldRenderer;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[Desc("Part of the legacy Lua API.")]
|
||||
public class LuaScriptInterfaceInfo : ITraitInfo, Requires<SpawnMapActorsInfo>
|
||||
{
|
||||
public readonly string[] LuaScripts = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new LuaScriptInterface(this); }
|
||||
}
|
||||
|
||||
public sealed class LuaScriptInterface : IWorldLoaded, ITick, IDisposable
|
||||
{
|
||||
World world;
|
||||
SpawnMapActors sma;
|
||||
readonly LuaScriptContext context = new LuaScriptContext();
|
||||
readonly LuaScriptInterfaceInfo info;
|
||||
|
||||
public LuaScriptInterface(LuaScriptInterfaceInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void WorldLoaded(World w, WorldRenderer wr)
|
||||
{
|
||||
world = w;
|
||||
sma = world.WorldActor.Trait<SpawnMapActors>();
|
||||
|
||||
context.Lua["World"] = w;
|
||||
context.Lua["WorldRenderer"] = wr;
|
||||
context.RegisterObject(this, "Internal", false);
|
||||
context.RegisterType(typeof(WVec), "WVec", true);
|
||||
context.RegisterType(typeof(CVec), "CVec", true);
|
||||
context.RegisterType(typeof(WPos), "WPos", true);
|
||||
context.RegisterType(typeof(CPos), "CPos", true);
|
||||
context.RegisterType(typeof(WRot), "WRot", true);
|
||||
context.RegisterType(typeof(WAngle), "WAngle", true);
|
||||
context.RegisterType(typeof(WRange), "WRange", true);
|
||||
context.RegisterType(typeof(int2), "int2", true);
|
||||
context.RegisterType(typeof(float2), "float2", true);
|
||||
|
||||
context.LoadLuaScripts(f => GlobalFileSystem.Open(f).ReadAllText(), Game.modData.Manifest.LuaScripts);
|
||||
|
||||
AddMapActorGlobals();
|
||||
|
||||
context.LoadLuaScripts(f => w.Map.Container.GetContent(f).ReadAllText(), info.LuaScripts);
|
||||
|
||||
context.InvokeLuaFunction("WorldLoaded");
|
||||
}
|
||||
|
||||
void AddMapActorGlobals()
|
||||
{
|
||||
foreach (var kv in sma.Actors)
|
||||
{
|
||||
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);
|
||||
else
|
||||
context.Lua[kv.Key] = kv.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
using (new PerfSample("tick_lua"))
|
||||
context.InvokeLuaFunction("Tick");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
context.Dispose();
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public object New(string typeName, LuaTable args)
|
||||
{
|
||||
var type = Game.modData.ObjectCreator.FindType(typeName);
|
||||
if (type == null)
|
||||
throw new InvalidOperationException("Cannot locate type: {0}".F(typeName));
|
||||
if (args == null)
|
||||
return Activator.CreateInstance(type);
|
||||
var argsArray = ConvertArgs(args);
|
||||
return Activator.CreateInstance(type, argsArray);
|
||||
}
|
||||
|
||||
static object[] ConvertArgs(LuaTable args)
|
||||
{
|
||||
var argsArray = new object[args.Keys.Count];
|
||||
for (var i = 1; i <= args.Keys.Count; i++)
|
||||
{
|
||||
var arg = args[i] as LuaTable;
|
||||
if (arg != null && arg[1] != null && arg[2] != null)
|
||||
argsArray[i - 1] = Convert.ChangeType(arg[1], Enum<TypeCode>.Parse(arg[2].ToString()));
|
||||
else
|
||||
argsArray[i - 1] = args[i];
|
||||
}
|
||||
return argsArray;
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void Debug(object obj)
|
||||
{
|
||||
if (obj != null)
|
||||
Game.Debug(obj.ToString());
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public object TraitOrDefault(Actor actor, string className)
|
||||
{
|
||||
var type = Game.modData.ObjectCreator.FindType(className);
|
||||
if (type == null)
|
||||
return null;
|
||||
|
||||
var method = typeof(Actor).GetMethod("TraitOrDefault");
|
||||
var genericMethod = method.MakeGenericMethod(type);
|
||||
return genericMethod.Invoke(actor, null);
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public object Trait(Actor actor, string className)
|
||||
{
|
||||
var ret = TraitOrDefault(actor, className);
|
||||
if (ret == null)
|
||||
throw new InvalidOperationException("Actor {0} does not have trait of type {1}".F(actor, className));
|
||||
return ret;
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public bool HasTrait(Actor actor, string className)
|
||||
{
|
||||
var ret = TraitOrDefault(actor, className);
|
||||
return ret != null;
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public object[] ActorsWithTrait(string className)
|
||||
{
|
||||
var type = Game.modData.ObjectCreator.FindType(className);
|
||||
if (type == null)
|
||||
throw new InvalidOperationException("Cannot locate type: {0}".F(className));
|
||||
|
||||
var method = typeof(World).GetMethod("ActorsWithTrait");
|
||||
var genericMethod = method.MakeGenericMethod(type);
|
||||
var result = ((IEnumerable)genericMethod.Invoke(world, null)).Cast<object>().ToArray();
|
||||
return result;
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public object TraitInfoOrDefault(string actorType, string className)
|
||||
{
|
||||
var type = Game.modData.ObjectCreator.FindType(className);
|
||||
if (type == null || !world.Map.Rules.Actors.ContainsKey(actorType))
|
||||
return null;
|
||||
|
||||
return world.Map.Rules.Actors[actorType].Traits.GetOrDefault(type);
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public object TraitInfo(string actorType, string className)
|
||||
{
|
||||
var ret = TraitInfoOrDefault(actorType, className);
|
||||
if (ret == null)
|
||||
throw new InvalidOperationException("Actor type {0} does not have trait info of type {1}".F(actorType, className));
|
||||
return ret;
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public bool HasTraitInfo(string actorType, string className)
|
||||
{
|
||||
var ret = TraitInfoOrDefault(actorType, className);
|
||||
return ret != null;
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void RunAfterDelay(double delay, Action func)
|
||||
{
|
||||
world.AddFrameEndTask(w => w.Add(new DelayedAction((int)delay, func)));
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void PlaySpeechNotification(Player player, string notification)
|
||||
{
|
||||
Sound.PlayNotification(world.Map.Rules, player, "Speech", notification, player != null ? player.Country.Race : null);
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void PlaySoundNotification(Player player, string notification)
|
||||
{
|
||||
Sound.PlayNotification(world.Map.Rules, player, "Sounds", notification, player != null ? player.Country.Race : null);
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void WaitFor(Actor actor, Func<bool> func)
|
||||
{
|
||||
actor.QueueActivity(new WaitFor(func));
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void CallFunc(Actor actor, Action func)
|
||||
{
|
||||
actor.QueueActivity(new CallFunc(func));
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public int GetFacing(object vec, double currentFacing)
|
||||
{
|
||||
if (vec is CVec)
|
||||
return world.Map.FacingBetween(CPos.Zero, CPos.Zero + (CVec)vec, (int)currentFacing);
|
||||
if (vec is WVec)
|
||||
return Util.GetFacing((WVec)vec, (int)currentFacing);
|
||||
throw new ArgumentException("Unsupported vector type: {0}".F(vec.GetType()));
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public WRange GetWRangeFromCells(double cells)
|
||||
{
|
||||
return WRange.FromCells((int)cells);
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void SetWinState(Player player, string winState)
|
||||
{
|
||||
player.WinState = Enum<WinState>.Parse(winState);
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void PlayRandomMusic()
|
||||
{
|
||||
if (!Game.Settings.Sound.MapMusic || !world.Map.Rules.InstalledMusic.Any())
|
||||
return;
|
||||
Game.ConnectionStateChanged += StopMusic;
|
||||
PlayMusic();
|
||||
}
|
||||
|
||||
void PlayMusic()
|
||||
{
|
||||
var track = world.Map.Rules.InstalledMusic.Random(Game.CosmeticRandom);
|
||||
Sound.PlayMusicThen(track.Value, PlayMusic);
|
||||
}
|
||||
|
||||
void StopMusic(OrderManager orderManager)
|
||||
{
|
||||
if (!orderManager.GameStarted)
|
||||
{
|
||||
Sound.StopMusic();
|
||||
Game.ConnectionStateChanged -= StopMusic;
|
||||
}
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public bool IsDead(Actor actor)
|
||||
{
|
||||
return actor.IsDead();
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void PlayMovieFullscreen(string movie, Action onComplete)
|
||||
{
|
||||
Media.PlayFMVFullscreen(world, movie, onComplete);
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void FlyToPos(Actor actor, WPos pos)
|
||||
{
|
||||
actor.QueueActivity(new Fly(actor, Target.FromPos(pos)));
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void FlyAttackActor(Actor actor, Actor targetActor)
|
||||
{
|
||||
actor.QueueActivity(new FlyAttack(Target.FromActor(targetActor)));
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void FlyAttackCell(Actor actor, CPos location)
|
||||
{
|
||||
actor.QueueActivity(new FlyAttack(Target.FromCell(actor.World, location)));
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void HeliFlyToPos(Actor actor, WPos pos)
|
||||
{
|
||||
actor.QueueActivity(new HeliFly(actor, Target.FromPos(pos)));
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void SetUnitStance(Actor actor, string stance)
|
||||
{
|
||||
var at = actor.TraitOrDefault<AutoTarget>();
|
||||
if (at != null)
|
||||
at.Stance = Enum<UnitStance>.Parse(stance);
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public bool RequiredUnitsAreDestroyed(Player player)
|
||||
{
|
||||
return player.HasNoRequiredUnits();
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void AttackMove(Actor actor, CPos location, double nearEnough)
|
||||
{
|
||||
if (actor.HasTrait<AttackMove>())
|
||||
actor.QueueActivity(new AttackMove.AttackMoveActivity(actor, new Move.Move(actor, location, (int)nearEnough)));
|
||||
else
|
||||
actor.QueueActivity(new Move.Move(actor, location, (int)nearEnough));
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public int GetRandomInteger(double low, double high)
|
||||
{
|
||||
return world.SharedRandom.Next((int)low, (int)high);
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public CPos GetRandomCell()
|
||||
{
|
||||
return world.Map.ChooseRandomCell(world.SharedRandom);
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public CPos GetRandomEdgeCell()
|
||||
{
|
||||
return world.Map.ChooseRandomEdgeCell(world.SharedRandom);
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public Actor GetNamedActor(string actorName)
|
||||
{
|
||||
return sma.Actors[actorName];
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public bool IsNamedActor(Actor actor)
|
||||
{
|
||||
return actor.ActorID <= sma.LastMapActorID && actor.ActorID > sma.LastMapActorID - sma.Actors.Count;
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public IEnumerable<Actor> GetNamedActors()
|
||||
{
|
||||
return sma.Actors.Values;
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public Actor[] FindActorsInBox(WPos topLeft, WPos bottomRight)
|
||||
{
|
||||
return world.ActorMap.ActorsInBox(topLeft, bottomRight).ToArray();
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public Actor[] FindActorsInCircle(WPos location, WRange radius)
|
||||
{
|
||||
return world.FindActorsInCircle(location, radius).ToArray();
|
||||
}
|
||||
|
||||
ClassicProductionQueue GetSharedQueueForCategory(Player player, string category)
|
||||
{
|
||||
return world.ActorsWithTrait<ClassicProductionQueue>()
|
||||
.Where(a => a.Actor.Owner == player && a.Trait.Info.Type == category)
|
||||
.Select(a => a.Trait).FirstOrDefault();
|
||||
}
|
||||
|
||||
ClassicProductionQueue GetSharedQueueForUnit(Player player, string unit)
|
||||
{
|
||||
var ri = world.Map.Rules.Actors[unit];
|
||||
|
||||
var bi = ri.Traits.GetOrDefault<BuildableInfo>();
|
||||
if (bi == null)
|
||||
return null;
|
||||
|
||||
return bi.Queue.Select(q => GetSharedQueueForCategory(player, q)).FirstOrDefault();
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void BuildWithSharedQueue(Player player, string unit, double amount)
|
||||
{
|
||||
var queue = GetSharedQueueForUnit(player, unit);
|
||||
|
||||
if (queue != null)
|
||||
queue.ResolveOrder(queue.Actor, Order.StartProduction(queue.Actor, unit, (int)amount));
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void BuildWithPerFactoryQueue(Actor factory, string unit, double amount)
|
||||
{
|
||||
var ri = world.Map.Rules.Actors[unit];
|
||||
|
||||
var bi = ri.Traits.GetOrDefault<BuildableInfo>();
|
||||
if (bi == null)
|
||||
return;
|
||||
|
||||
var queue = factory.TraitsImplementing<ProductionQueue>()
|
||||
.FirstOrDefault(q => q.Enabled);
|
||||
|
||||
if (queue != null)
|
||||
queue.ResolveOrder(factory, Order.StartProduction(factory, unit, (int)amount));
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public bool SharedQueueIsBusy(Player player, string category)
|
||||
{
|
||||
var queue = GetSharedQueueForCategory(player, category);
|
||||
|
||||
if (queue == null)
|
||||
return true;
|
||||
|
||||
return queue.CurrentItem() != null;
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public bool PerFactoryQueueIsBusy(Actor factory)
|
||||
{
|
||||
var queue = factory.TraitsImplementing<ProductionQueue>()
|
||||
.FirstOrDefault(q => q.Enabled);
|
||||
|
||||
if (queue == null)
|
||||
return true;
|
||||
|
||||
return queue.CurrentItem() != null;
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void Guard(Actor guard, Actor target)
|
||||
{
|
||||
if (target.HasTrait<Guardable>())
|
||||
{
|
||||
var gt = guard.TraitOrDefault<Guard>();
|
||||
|
||||
if (gt != null)
|
||||
gt.GuardTarget(guard, Target.FromActor(target));
|
||||
}
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public IEnumerable<CPos> ExpandFootprint(LuaTable cells, bool allowDiagonal)
|
||||
{
|
||||
return Util.ExpandFootprint(cells.Values.Cast<CPos>(), allowDiagonal);
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public WPos CenterOfCell(CPos position)
|
||||
{
|
||||
return world.Map.CenterOfCell(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,236 +0,0 @@
|
||||
Actor = { }
|
||||
|
||||
Actor.Create = function(name, init)
|
||||
if name == nil then error("No actor name specified", 2) end
|
||||
if init.Owner == nil then error("No actor owner specified", 2) end
|
||||
local td = OpenRA.New("TypeDictionary")
|
||||
local addToWorld = true
|
||||
for key, value in pairs(init) do
|
||||
if key == "AddToWorld" then
|
||||
addToWorld = value
|
||||
else
|
||||
td:Add(OpenRA.New(key .. "Init", { value }))
|
||||
end
|
||||
end
|
||||
return World:CreateActor(addToWorld, name, td)
|
||||
end
|
||||
|
||||
Actor.Turn = function(actor, facing)
|
||||
actor:QueueActivity(OpenRA.New("Turn", { actor, { facing, "Int32" } }))
|
||||
end
|
||||
|
||||
Actor.Move = function(actor, location)
|
||||
Actor.MoveNear(actor, location, 0)
|
||||
end
|
||||
|
||||
Actor.MoveNear = function(actor, location, nearEnough)
|
||||
actor:QueueActivity(OpenRA.New("Move", { actor, location, WRange.FromCells(nearEnough) }))
|
||||
end
|
||||
|
||||
Actor.ScriptedMove = function(actor, location)
|
||||
if Actor.HasTrait(actor, "Helicopter") then
|
||||
Internal.HeliFlyToPos(actor, Map.CenterOfCell(location))
|
||||
else
|
||||
actor:QueueActivity(OpenRA.New("Move", { actor, location }))
|
||||
end
|
||||
end
|
||||
|
||||
Actor.AfterMove = function(actor)
|
||||
local heli = Actor.TraitOrDefault(actor, "Helicopter")
|
||||
if heli ~= nil then
|
||||
Actor.Turn(actor, heli.Info.InitialFacing)
|
||||
Actor.HeliLand(actor, true)
|
||||
end
|
||||
end
|
||||
|
||||
Actor.Teleport = function(actor, location)
|
||||
actor:QueueActivity(OpenRA.New("SimpleTeleport", { location }))
|
||||
end
|
||||
|
||||
Actor.AttackMove = function(actor, location, nearEnough)
|
||||
Internal.AttackMove(actor, location, nearEnough or 0)
|
||||
end
|
||||
|
||||
Actor.HeliFly = function(actor, position)
|
||||
Internal.HeliFlyToPos(actor, position)
|
||||
end
|
||||
|
||||
Actor.HeliLand = function(actor, requireSpace)
|
||||
actor:QueueActivity(OpenRA.New("HeliLand", { requireSpace }))
|
||||
end
|
||||
|
||||
Actor.Fly = function(actor, position)
|
||||
Internal.FlyToPos(actor, position)
|
||||
end
|
||||
|
||||
Actor.FlyAttackActor = function(actor, targetActor)
|
||||
Internal.FlyAttackActor(actor, targetActor)
|
||||
end
|
||||
|
||||
Actor.FlyAttackCell = function(actor, location)
|
||||
Internal.FlyAttackCell(actor, location)
|
||||
end
|
||||
|
||||
Actor.FlyOffMap = function(actor)
|
||||
actor:QueueActivity(OpenRA.New("FlyOffMap"))
|
||||
end
|
||||
|
||||
Actor.Hunt = function(actor)
|
||||
if Actor.HasTrait(actor, "AttackBase") and Actor.HasTrait(actor, "IMove") then
|
||||
actor:QueueActivity(OpenRA.New("Hunt", { actor }))
|
||||
end
|
||||
end
|
||||
|
||||
Actor.CargoIsEmpty = function(actor)
|
||||
local cargo = Actor.TraitOrDefault(actor, "Cargo")
|
||||
return cargo == nil or cargo:IsEmpty(actor)
|
||||
end
|
||||
|
||||
Actor.UnloadCargo = function(actor, unloadAll)
|
||||
actor:QueueActivity(OpenRA.New("UnloadCargo", { actor, unloadAll }))
|
||||
end
|
||||
|
||||
Actor.Harvest = function(actor)
|
||||
actor:QueueActivity(OpenRA.New("FindResources"))
|
||||
end
|
||||
|
||||
Actor.Scatter = function(actor)
|
||||
local mobile = Actor.Trait(actor, "Mobile")
|
||||
mobile:Nudge(actor, actor, true)
|
||||
end
|
||||
|
||||
Actor.Wait = function(actor, period)
|
||||
actor:QueueActivity(OpenRA.New("Wait", { { period, "Int32" } }))
|
||||
end
|
||||
|
||||
Actor.WaitFor = function(actor, func)
|
||||
Internal.WaitFor(actor, func)
|
||||
end
|
||||
|
||||
Actor.CallFunc = function(actor, func)
|
||||
Internal.CallFunc(actor, func)
|
||||
end
|
||||
|
||||
Actor.DeployTransform = function(actor)
|
||||
Actor.CallFunc(actor, function()
|
||||
-- Queue the transform order
|
||||
Actor.Trait(actor, "Transforms"):DeployTransform(true)
|
||||
end)
|
||||
end
|
||||
|
||||
Actor.RemoveSelf = function(actor)
|
||||
actor:QueueActivity(OpenRA.New("RemoveSelf"))
|
||||
end
|
||||
|
||||
Actor.Stop = function(actor)
|
||||
actor:CancelActivity()
|
||||
end
|
||||
|
||||
Actor.IsDead = function(actor)
|
||||
return Internal.IsDead(actor)
|
||||
end
|
||||
|
||||
Actor.IsInWorld = function(actor)
|
||||
return actor.IsInWorld
|
||||
end
|
||||
|
||||
Actor.Owner = function(actor)
|
||||
return actor.Owner
|
||||
end
|
||||
|
||||
Actor.Facing = function(actor)
|
||||
return Actor.Trait(actor, "IFacing"):get_Facing()
|
||||
end
|
||||
|
||||
Actor.IsIdle = function(actor)
|
||||
return actor.IsIdle
|
||||
end
|
||||
|
||||
Actor.SetStance = function(actor, stance)
|
||||
Internal.SetUnitStance(actor, stance)
|
||||
end
|
||||
|
||||
Actor.RepairBuilding = function(actor)
|
||||
local rb = Actor.TraitOrDefault(actor, "RepairableBuilding")
|
||||
if rb ~= nil and not rb.RepairActive then
|
||||
rb:RepairBuilding(actor, Actor.Owner(actor))
|
||||
end
|
||||
end
|
||||
|
||||
Actor.OnDamaged = function(actor, eh)
|
||||
Actor.Trait(actor, "LuaScriptEvents").OnDamaged:Add(eh)
|
||||
end
|
||||
|
||||
Actor.OnKilled = function(actor, eh)
|
||||
Actor.Trait(actor, "LuaScriptEvents").OnKilled:Add(eh)
|
||||
end
|
||||
|
||||
Actor.OnAddedToWorld = function(actor, eh)
|
||||
Actor.Trait(actor, "LuaScriptEvents").OnAddedToWorld:Add(eh)
|
||||
end
|
||||
|
||||
Actor.OnRemovedFromWorld = function(actor, eh)
|
||||
Actor.Trait(actor, "LuaScriptEvents").OnRemovedFromWorld:Add(eh)
|
||||
end
|
||||
|
||||
Actor.OnCaptured = function(actor, eh)
|
||||
Actor.Trait(actor, "LuaScriptEvents").OnCaptured:Add(eh)
|
||||
end
|
||||
|
||||
Actor.OnIdle = function(actor, eh)
|
||||
Actor.Trait(actor, "LuaScriptEvents").OnIdle:Add(eh)
|
||||
end
|
||||
|
||||
Actor.OnProduced = function(actor, eh)
|
||||
Actor.Trait(actor, "LuaScriptEvents").OnProduced:Add(eh)
|
||||
end
|
||||
|
||||
Actor.ActorsWithTrait = function(className)
|
||||
local ret = { }
|
||||
for item in Utils.Enumerate(Internal.ActorsWithTrait(className)) do
|
||||
table.insert(ret, item.Actor)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
Actor.HasTrait = function(actor, className)
|
||||
return Internal.HasTrait(actor, className)
|
||||
end
|
||||
|
||||
Actor.TraitOrDefault = function(actor, className)
|
||||
return Internal.TraitOrDefault(actor, className)
|
||||
end
|
||||
|
||||
Actor.Trait = function(actor, className)
|
||||
return Internal.Trait(actor, className)
|
||||
end
|
||||
|
||||
Actor.ReturnToBase = function(actor, airfield)
|
||||
actor:QueueActivity(OpenRA.New("ReturnToBase", { actor, airfield }))
|
||||
end
|
||||
|
||||
Actor.Guard = function(actor, target)
|
||||
Internal.Guard(actor, target)
|
||||
end
|
||||
|
||||
Actor.Patrol = function(actor, waypoints, wait, loop)
|
||||
if not Actor.IsDead(actor) then
|
||||
Utils.Do(waypoints, function(wpt)
|
||||
Actor.AttackMove(actor, wpt.Location, 3)
|
||||
Actor.Wait(actor, wait or 0)
|
||||
end)
|
||||
if loop or loop == nil then
|
||||
Actor.CallFunc(actor, function() Actor.Patrol(actor, waypoints, wait, loop) end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Actor.PatrolUntil = function(actor, waypoints, wait, func)
|
||||
if func == nil then error("No function specified", 2) end
|
||||
if not Actor.IsDead(actor) then
|
||||
Actor.Patrol(actor, waypoints, wait, false)
|
||||
if not func(actor) then
|
||||
Actor.CallFunc(actor, function() Actor.PatrolUntil(actor, waypoints, wait, func) end)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,10 +0,0 @@
|
||||
Facing = { }
|
||||
|
||||
Facing.North = { 0, "Int32" }
|
||||
Facing.NorthWest = { 32, "Int32" }
|
||||
Facing.West = { 64, "Int32" }
|
||||
Facing.SouthWest = { 96, "Int32" }
|
||||
Facing.South = { 128, "Int32" }
|
||||
Facing.SouthEast = { 160, "Int32" }
|
||||
Facing.East = { 192, "Int32" }
|
||||
Facing.NorthEast = { 224, "Int32" }
|
||||
@@ -1,109 +0,0 @@
|
||||
Map = { }
|
||||
|
||||
Map.GetFacing = function(vec, currentFacing)
|
||||
return Internal.GetFacing(vec, currentFacing)
|
||||
end
|
||||
|
||||
Map.GetRandomCell = function()
|
||||
return Internal.GetRandomCell()
|
||||
end
|
||||
|
||||
Map.GetRandomEdgeCell = function()
|
||||
return Internal.GetRandomEdgeCell()
|
||||
end
|
||||
|
||||
Map.IsNamedActor = function(actor)
|
||||
return Internal.IsNamedActor(actor)
|
||||
end
|
||||
|
||||
Map.GetNamedActor = function(actorName)
|
||||
return Internal.GetNamedActor(actorName)
|
||||
end
|
||||
|
||||
Map.GetNamedActors = function()
|
||||
return Internal.GetNamedActors()
|
||||
end
|
||||
|
||||
Map.FindActorsInCircle = function(location, radius, func)
|
||||
local actors = Internal.FindActorsInCircle(location.CenterPosition, WRange.FromCells(radius))
|
||||
return Utils.EnumerableWhere(actors, func)
|
||||
end
|
||||
|
||||
Map.FindActorsInBox = function(topLeft, bottomRight, func)
|
||||
local actors = Internal.FindActorsInBox(topLeft.CenterPosition, bottomRight.CenterPosition)
|
||||
return Utils.EnumerableWhere(actors, func)
|
||||
end
|
||||
|
||||
Map.__FilterByTrait = function(a, player, trait)
|
||||
return Actor.Owner(a) == player and Actor.HasTrait(a, trait)
|
||||
end
|
||||
|
||||
Map.__FilterByTraitAndIdle = function(a, player, trait)
|
||||
return Map.__FilterByTrait(a, player, trait) and Actor.IsIdle(a)
|
||||
end
|
||||
|
||||
Map.FindUnitsInCircle = function(player, location, radius)
|
||||
return Map.FindActorsInCircle(location, radius, function(a) return Map.__FilterByTrait(a, player, "Mobile") end)
|
||||
end
|
||||
|
||||
Map.FindUnitsInBox = function(player, topLeft, bottomRight)
|
||||
return Map.FindActorsInBox(topLeft, bottomRight, function(a) return Map.__FilterByTrait(a, player, "Mobile") end)
|
||||
end
|
||||
|
||||
Map.FindStructuresInCircle = function(player, location, radius)
|
||||
return Map.FindActorsInCircle(location, radius, function(a) return Map.__FilterByTrait(a, player, "Building") end)
|
||||
end
|
||||
|
||||
Map.FindStructuresInBox = function(player, topLeft, bottomRight)
|
||||
return Map.FindActorsInBox(topLeft, bottomRight, function(a) return Map.__FilterByTrait(a, player, "Building") end)
|
||||
end
|
||||
|
||||
Map.FindIdleUnitsInCircle = function(player, location, radius)
|
||||
return Map.FindActorsInCircle(location, radius, function(a) return Map.__FilterByTraitAndIdle(a, player, "Mobile") end)
|
||||
end
|
||||
|
||||
Map.FindIdleUnitsInBox = function(player, topLeft, bottomRight)
|
||||
return Map.FindActorsInBox(topLeft, bottomRight, function(a) return Map.__FilterByTraitAndIdle(a, player, "Mobile") end)
|
||||
end
|
||||
|
||||
Map.ExpandFootprint = function(cells, allowDiagonal)
|
||||
return Utils.EnumerableToTable(Internal.ExpandFootprint(cells, allowDiagonal))
|
||||
end
|
||||
|
||||
Map.CenterOfCell = function(position)
|
||||
return Internal.CenterOfCell(position)
|
||||
end
|
||||
|
||||
CPos.New = function(x, y)
|
||||
return OpenRA.New("CPos", { { x, "Int32" }, { y, "Int32" } })
|
||||
end
|
||||
|
||||
WPos.New = function(x, y, z)
|
||||
if z == nil then
|
||||
z = 0
|
||||
end
|
||||
return OpenRA.New("WPos", { { x, "Int32" }, { y, "Int32" }, { z, "Int32" } })
|
||||
end
|
||||
|
||||
WPos.FromCPos = function(location)
|
||||
return WPos.New(location.X * 1024, location.Y * 1024, 0)
|
||||
end
|
||||
|
||||
CVec.New = function(x, y)
|
||||
return OpenRA.New("CVec", { { x, "Int32" }, { y, "Int32" } })
|
||||
end
|
||||
|
||||
WVec.New = function(x, y, z)
|
||||
if z == nil then
|
||||
z = 0
|
||||
end
|
||||
return OpenRA.New("WVec", { { x, "Int32" }, { y, "Int32" }, { z, "Int32" } })
|
||||
end
|
||||
|
||||
WRange.New = function(r)
|
||||
return OpenRA.New("WRange", { { r, "Int32" } })
|
||||
end
|
||||
|
||||
WRange.FromCells = function(cells)
|
||||
return WRange.New(cells * 1024)
|
||||
end
|
||||
@@ -1,20 +0,0 @@
|
||||
Media = { }
|
||||
|
||||
Media.PlaySpeechNotification = function(notification, player)
|
||||
Internal.PlaySpeechNotification(player, notification)
|
||||
end
|
||||
|
||||
Media.PlaySoundNotification = function(notification, player)
|
||||
Internal.PlaySoundNotification(player, notification)
|
||||
end
|
||||
|
||||
Media.PlayRandomMusic = function()
|
||||
Internal.PlayRandomMusic()
|
||||
end
|
||||
|
||||
Media.PlayMovieFullscreen = function(movie, onComplete)
|
||||
if onComplete == nil then
|
||||
onComplete = function() end
|
||||
end
|
||||
Internal.PlayMovieFullscreen(movie, onComplete)
|
||||
end
|
||||
@@ -1,37 +0,0 @@
|
||||
Mission = { }
|
||||
|
||||
Mission.MissionOver = function(winners, losers, setWinStates)
|
||||
World:SetLocalPauseState(true)
|
||||
World:set_PauseStateLocked(true)
|
||||
if winners then
|
||||
for i, player in ipairs(winners) do
|
||||
Media.PlaySpeechNotification("Win", player)
|
||||
if setWinStates then
|
||||
OpenRA.SetWinState(player, "Won")
|
||||
end
|
||||
end
|
||||
end
|
||||
if losers then
|
||||
for i, player in ipairs(losers) do
|
||||
Media.PlaySpeechNotification("Lose", player)
|
||||
if setWinStates then
|
||||
OpenRA.SetWinState(player, "Lost")
|
||||
end
|
||||
end
|
||||
end
|
||||
Mission.MissionIsOver = true
|
||||
end
|
||||
|
||||
Mission.GetGroundAttackersOf = function(player)
|
||||
return Utils.Where(Actor.ActorsWithTrait("AttackBase"), function(actor)
|
||||
return not Actor.IsDead(actor) and Actor.IsInWorld(actor) and Actor.Owner(actor) == player and Actor.HasTrait(actor, "Mobile")
|
||||
end)
|
||||
end
|
||||
|
||||
Mission.TickTakeOre = function(player)
|
||||
OpenRA.TakeOre(player, 0.01 * OpenRA.GetOreCapacity(player) / 25)
|
||||
end
|
||||
|
||||
Mission.RequiredUnitsAreDestroyed = function(player)
|
||||
return Internal.RequiredUnitsAreDestroyed(player)
|
||||
end
|
||||
@@ -1,83 +0,0 @@
|
||||
print = Internal.Debug
|
||||
|
||||
OpenRA = { }
|
||||
|
||||
OpenRA.New = function(className, args)
|
||||
if args == nil then
|
||||
args = { }
|
||||
end
|
||||
return Internal.New(className, args)
|
||||
end
|
||||
|
||||
OpenRA.RunAfterDelay = function(delay, func)
|
||||
if func == nil then error("No function specified", 2) end
|
||||
Internal.RunAfterDelay(delay, func)
|
||||
end
|
||||
|
||||
OpenRA.SetViewportCenterPosition = function(position)
|
||||
WorldRenderer.Viewport:Center(position)
|
||||
end
|
||||
|
||||
OpenRA.GetViewportCenterPosition = function()
|
||||
return WorldRenderer.Viewport.CenterPosition
|
||||
end
|
||||
|
||||
OpenRA.GetDifficulty = function()
|
||||
return World.LobbyInfo.GlobalSettings.Difficulty
|
||||
end
|
||||
|
||||
OpenRA.IsSinglePlayer = function()
|
||||
return World.LobbyInfo:get_IsSinglePlayer()
|
||||
end
|
||||
|
||||
OpenRA.GetPlayer = function(internalName)
|
||||
return Utils.EnumerableFirstOrNil(World.Players, function(p) return p.InternalName == internalName end)
|
||||
end
|
||||
|
||||
OpenRA.GetPlayers = function(func)
|
||||
return Utils.EnumerableWhere(World.Players, func)
|
||||
end
|
||||
|
||||
OpenRA.SetWinState = function(player, winState)
|
||||
Internal.SetWinState(player, winState)
|
||||
end
|
||||
|
||||
OpenRA.GetRandomInteger = function(low, high)
|
||||
if high <= low then
|
||||
return low
|
||||
else
|
||||
return Internal.GetRandomInteger(low, high)
|
||||
end
|
||||
end
|
||||
|
||||
OpenRA.TakeOre = function(player, amount)
|
||||
Actor.Trait(player.PlayerActor, "PlayerResources"):TakeResources(amount)
|
||||
end
|
||||
|
||||
OpenRA.TakeCash = function(player, amount)
|
||||
Actor.Trait(player.PlayerActor, "PlayerResources"):TakeCash(amount)
|
||||
end
|
||||
|
||||
OpenRA.GiveOre = function(player, amount)
|
||||
Actor.Trait(player.PlayerActor, "PlayerResources"):GiveResources(amount)
|
||||
end
|
||||
|
||||
OpenRA.GiveCash = function(player, amount)
|
||||
Actor.Trait(player.PlayerActor, "PlayerResources"):GiveCash(amount)
|
||||
end
|
||||
|
||||
OpenRA.CanGiveOre = function(player, amount)
|
||||
return Actor.Trait(player.PlayerActor, "PlayerResources"):CanGiveResources(amount)
|
||||
end
|
||||
|
||||
OpenRA.GetOreCapacity = function(player)
|
||||
return Actor.Trait(player.PlayerActor, "PlayerResources").ResourceCapacity
|
||||
end
|
||||
|
||||
OpenRA.GetOre = function(player)
|
||||
return Actor.Trait(player.PlayerActor, "PlayerResources").Resources
|
||||
end
|
||||
|
||||
OpenRA.GetCash = function(player)
|
||||
return Actor.Trait(player.PlayerActor, "PlayerResources").Cash
|
||||
end
|
||||
@@ -1,94 +0,0 @@
|
||||
Production = { }
|
||||
Production.EventHandlers = { }
|
||||
|
||||
Production.BuildWithSharedQueue = function(player, unit, amount)
|
||||
Internal.BuildWithSharedQueue(player, unit, amount or 1)
|
||||
end
|
||||
|
||||
Production.BuildWithPerFactoryQueue = function(factory, unit, amount)
|
||||
Internal.BuildWithPerFactoryQueue(factory, unit, amount or 1)
|
||||
end
|
||||
|
||||
Production.Build = function(factory, unit, amount)
|
||||
if Actor.HasTrait(factory, "ProductionQueue") then
|
||||
Production.BuildWithPerFactoryQueue(factory, unit, amount)
|
||||
elseif Actor.HasTrait(factory, "Production") then
|
||||
Production.SetPrimaryBuilding(factory)
|
||||
Production.BuildWithSharedQueue(Actor.Owner(factory), unit, amount)
|
||||
else
|
||||
error("Production.Build: not a factory")
|
||||
end
|
||||
end
|
||||
|
||||
Production.SharedQueueIsBusy = function(player, category)
|
||||
return Internal.SharedQueueIsBusy(player, category)
|
||||
end
|
||||
|
||||
Production.PerFactoryQueueIsBusy = function(factory)
|
||||
return Internal.PerFactoryQueueIsBusy(factory)
|
||||
end
|
||||
|
||||
Production.SetRallyPoint = function(factory, location)
|
||||
local srp = Actor.Trait(factory, "RallyPoint")
|
||||
if srp ~= nil then
|
||||
srp.Location = location.Location
|
||||
end
|
||||
end
|
||||
|
||||
Production.SetPrimaryBuilding = function(factory)
|
||||
local pb = Actor.TraitOrDefault(factory, "PrimaryBuilding")
|
||||
if pb ~= nil then
|
||||
pb:SetPrimaryProducer(factory, true)
|
||||
end
|
||||
end
|
||||
|
||||
Production.BuildTeamFromTemplate = function(player, template, func)
|
||||
local factories = { }
|
||||
Utils.Do(template, function(t) table.insert(factories, t[1]) end)
|
||||
|
||||
if Utils.Any(factories, Actor.IsDead) then
|
||||
return
|
||||
end
|
||||
|
||||
if Utils.Any(factories, function(fact) return Production.EventHandlers[fact] end) then
|
||||
OpenRA.RunAfterDelay(Utils.Seconds(10), function() Production.BuildTeamFromTemplate(player, template, func) end)
|
||||
return
|
||||
end
|
||||
|
||||
local team = Team.New({ })
|
||||
local teamSize = 0
|
||||
Utils.Do(template, function(t) teamSize = teamSize + #t[2] end)
|
||||
|
||||
local eventHandler = function(unit)
|
||||
Team.Add(team, unit)
|
||||
|
||||
if #team.Actors >= teamSize then
|
||||
func(team)
|
||||
Utils.Do(factories, function(factory)
|
||||
Production.EventHandlers[factory] = nil
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
Utils.Do(factories, function(factory)
|
||||
Production.EventHandlers[factory] = eventHandler
|
||||
end)
|
||||
|
||||
Utils.Do(template, function(t)
|
||||
Utils.Do(t[2], function(unit)
|
||||
Production.Build(t[1], unit)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
Production.EventHandlers.Setup = function(player)
|
||||
Utils.Do(Actor.ActorsWithTrait("Production"), function(factory)
|
||||
if Actor.Owner(factory) == player then
|
||||
Actor.OnProduced(factory, function(fact, unit)
|
||||
if Production.EventHandlers[fact] then
|
||||
Production.EventHandlers[fact](unit)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
@@ -1,82 +0,0 @@
|
||||
Reinforcements = { }
|
||||
|
||||
Reinforcements.Insert = function(owner, transportName, passengerNames, enterPath, exitPath)
|
||||
local facing = { Map.GetFacing(CPos.op_Subtraction(enterPath[2], enterPath[1]), 0), "Int32" }
|
||||
local center = WPos.op_Addition(Map.CenterOfCell(enterPath[1]), WVec.New(0, 0, Rules.InitialAltitude(transportName)))
|
||||
local transport = Actor.Create(transportName, { Owner = owner, Location = enterPath[1], CenterPosition = center, Facing = facing })
|
||||
local cargo = Actor.Trait(transport, "Cargo")
|
||||
local passengers = { }
|
||||
|
||||
for i, passengerName in ipairs(passengerNames) do
|
||||
local passenger = Actor.Create(passengerName, { AddToWorld = false, Owner = owner })
|
||||
passengers[i] = passenger
|
||||
cargo:Load(transport, passenger)
|
||||
end
|
||||
|
||||
Utils.Do(Utils.Skip(enterPath, 1), function(l) Actor.ScriptedMove(transport, l) end)
|
||||
Actor.AfterMove(transport)
|
||||
Actor.UnloadCargo(transport, true)
|
||||
Actor.Wait(transport, 25)
|
||||
Utils.Do(exitPath, function(l) Actor.ScriptedMove(transport, l) end)
|
||||
Actor.RemoveSelf(transport)
|
||||
return transport, passengers
|
||||
end
|
||||
|
||||
Reinforcements.Extract = function(owner, transportName, passengerNames, enterPath, exitPath)
|
||||
local facing = { Map.GetFacing(CPos.op_Subtraction(enterPath[2], enterPath[1]), 0), "Int32" }
|
||||
local center = WPos.op_Addition(Map.CenterOfCell(enterPath[1]), WVec.New(0, 0, Rules.InitialAltitude(transportName)))
|
||||
local transport = Actor.Create(transportName, { Owner = owner, Location = enterPath[1], CenterPosition = center, Facing = facing })
|
||||
local cargo = Actor.Trait(transport, "Cargo")
|
||||
|
||||
Utils.Do(Utils.Skip(enterPath, 1), function(l) Actor.ScriptedMove(transport, l) end)
|
||||
Actor.AfterMove(transport)
|
||||
Actor.WaitFor(transport, function()
|
||||
return Utils.All(passengerNames, function(passenger) return cargo.Passengers:Contains(passenger) end)
|
||||
end)
|
||||
|
||||
Actor.Wait(transport, 125)
|
||||
Utils.Do(exitPath, function(l) Actor.ScriptedMove(transport, l) end)
|
||||
Actor.RemoveSelf(transport)
|
||||
return transport
|
||||
end
|
||||
|
||||
Reinforcements.Reinforce = function(owner, reinforcementNames, enterLocation, rallyPointLocation, interval, onCreateFunc)
|
||||
local facing = { Map.GetFacing(CPos.op_Subtraction(rallyPointLocation, enterLocation), 0), "Int32" }
|
||||
local reinforcements = { }
|
||||
for i, reinforcementName in ipairs(reinforcementNames) do
|
||||
local reinforcement = Actor.Create(reinforcementName, { AddToWorld = false, Owner = owner, Location = enterLocation, Facing = facing })
|
||||
reinforcements[i] = reinforcement
|
||||
OpenRA.RunAfterDelay((i - 1) * interval, function()
|
||||
World:Add(reinforcement)
|
||||
Actor.MoveNear(reinforcement, rallyPointLocation, 2)
|
||||
if onCreateFunc ~= nil then
|
||||
onCreateFunc(reinforcement)
|
||||
end
|
||||
end)
|
||||
end
|
||||
return reinforcements
|
||||
end
|
||||
|
||||
Reinforcements.ReinforceWithCargo = function(owner, actorName, path, cargoNames, actionFunc)
|
||||
local facing = { Map.GetFacing(CPos.op_Subtraction(path[2].Location, path[1].Location), 0), "Int32" }
|
||||
local center = WPos.op_Addition(path[1].CenterPosition, WVec.New(0, 0, Rules.InitialAltitude(actorName)))
|
||||
local actor = Actor.Create(actorName, { Owner = owner, Location = path[1].Location, CenterPosition = center, Facing = facing })
|
||||
local cargo = Actor.TraitOrDefault(actor, "Cargo")
|
||||
local team = Team.New({})
|
||||
if cargo ~= nil and cargoNames ~= nil and #cargoNames > 0 then
|
||||
local passengers = { }
|
||||
|
||||
for i, cargoName in ipairs(cargoNames) do
|
||||
local passenger = Actor.Create(cargoName, { AddToWorld = false, Owner = owner })
|
||||
Team.Add(team, passenger)
|
||||
passengers[i] = passenger
|
||||
cargo:Load(actor, passenger)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Utils.Do(Utils.Skip(path, 1), function(waypoint) Actor.ScriptedMove(actor, waypoint.Location) end)
|
||||
|
||||
if actionFunc then actionFunc(actor, team) end
|
||||
return actor, team
|
||||
end
|
||||
@@ -1,21 +0,0 @@
|
||||
Rules = { }
|
||||
|
||||
Rules.HasTraitInfo = function(actorType, className)
|
||||
return Internal.HasTraitInfo(actorType, className)
|
||||
end
|
||||
|
||||
Rules.TraitInfoOrDefault = function(actorType, className)
|
||||
return Internal.TraitInfoOrDefault(actorType, className)
|
||||
end
|
||||
|
||||
Rules.TraitInfo = function(actorType, className)
|
||||
return Internal.TraitInfo(actorType, className)
|
||||
end
|
||||
|
||||
Rules.InitialAltitude = function(actorType)
|
||||
local ai = Rules.TraitInfoOrDefault(actorType, "AircraftInfo")
|
||||
if ai ~= nil then
|
||||
return ai.CruiseAltitude.Range
|
||||
end
|
||||
return 0
|
||||
end
|
||||
@@ -1,44 +0,0 @@
|
||||
SupportPowers = { }
|
||||
|
||||
SupportPowers.Airstrike = function(owner, planeName, enterLocation, bombLocation)
|
||||
local facing = { Map.GetFacing(CPos.op_Subtraction(bombLocation, enterLocation), 0), "Int32" }
|
||||
local center = WPos.op_Addition(Map.CenterOfCell(enterLocation), WVec.New(0, 0, Rules.InitialAltitude(planeName)))
|
||||
local plane = Actor.Create(planeName, { Location = enterLocation, Owner = owner, Facing = facing, CenterPosition = center })
|
||||
local bombLoc = Map.CenterOfCell(bombLocation)
|
||||
Actor.Trait(plane, "AttackBomber"):SetTarget(bombLoc)
|
||||
Actor.Fly(plane, bombLoc)
|
||||
Actor.FlyOffMap(plane)
|
||||
Actor.RemoveSelf(plane)
|
||||
return plane
|
||||
end
|
||||
|
||||
SupportPowers.Paradrop = function(owner, planeName, passengerNames, enterLocation, dropLocation)
|
||||
local facing = { Map.GetFacing(CPos.op_Subtraction(dropLocation, enterLocation), 0), "Int32" }
|
||||
local center = WPos.op_Addition(Map.CenterOfCell(enterLocation), WVec.New(0, 0, Rules.InitialAltitude(planeName)))
|
||||
local plane = Actor.Create(planeName, { Location = enterLocation, Owner = owner, Facing = facing, CenterPosition = center })
|
||||
Actor.Fly(plane, Map.CenterOfCell(dropLocation))
|
||||
Actor.Trait(plane, "ParaDrop"):SetLZ(dropLocation, true)
|
||||
Actor.FlyOffMap(plane)
|
||||
Actor.RemoveSelf(plane)
|
||||
local cargo = Actor.Trait(plane, "Cargo")
|
||||
local passengers = { }
|
||||
for i, passengerName in ipairs(passengerNames) do
|
||||
local passenger = Actor.Create(passengerName, { AddToWorld = false, Owner = owner })
|
||||
passengers[i] = passenger
|
||||
cargo:Load(plane, passenger)
|
||||
end
|
||||
return plane, passengers
|
||||
end
|
||||
|
||||
SupportPowers.Chronoshift = function(unitLocationPairs, chronosphere, duration, killCargo)
|
||||
duration = duration or -1
|
||||
killCargo = killCargo or true
|
||||
Utils.Do(unitLocationPairs, function(pair)
|
||||
local unit = pair[1]
|
||||
local cell = pair[2]
|
||||
local cs = Actor.TraitOrDefault(unit, "Chronoshiftable")
|
||||
if cs ~= nil and cs:CanChronoshiftTo(unit, cell) then
|
||||
cs:Teleport(unit, cell, duration, killCargo, chronosphere)
|
||||
end
|
||||
end)
|
||||
end
|
||||
@@ -1,73 +0,0 @@
|
||||
Team = { }
|
||||
|
||||
Team.New = function(actors)
|
||||
local team = { }
|
||||
team.Actors = actors
|
||||
team.OnAllKilled = { }
|
||||
team.OnAnyKilled = { }
|
||||
team.OnAllRemovedFromWorld = { }
|
||||
team.OnAnyRemovedFromWorld = { }
|
||||
Team.Do(team, function(actor) Team.AddActorEventHandlers(team, actor) end)
|
||||
return team
|
||||
end
|
||||
|
||||
Team.Add = function(team, actor)
|
||||
table.insert(team.Actors, actor)
|
||||
Team.AddActorEventHandlers(team, actor)
|
||||
end
|
||||
|
||||
Team.AddActorEventHandlers = function(team, actor)
|
||||
Actor.OnKilled(actor, function()
|
||||
Team.InvokeHandlers(team.OnAnyKilled)
|
||||
if Team.AllAreDead(team) then Team.InvokeHandlers(team.OnAllKilled) end
|
||||
end)
|
||||
|
||||
Actor.OnRemovedFromWorld(actor, function()
|
||||
Team.InvokeHandlers(team.OnAnyRemovedFromWorld)
|
||||
if not Team.AnyAreInWorld(team) then Team.InvokeHandlers(team.OnAllRemovedFromWorld) end
|
||||
end)
|
||||
end
|
||||
|
||||
Team.InvokeHandlers = function(event)
|
||||
Utils.Do(event, function(handler) handler() end)
|
||||
end
|
||||
|
||||
Team.AllAreDead = function(team)
|
||||
return Utils.All(team.Actors, Actor.IsDead)
|
||||
end
|
||||
|
||||
Team.AnyAreDead = function(team)
|
||||
return Utils.Any(team.Actors, Actor.IsDead)
|
||||
end
|
||||
|
||||
Team.AllAreInWorld = function(team)
|
||||
return Utils.All(team.Actors, Actor.IsInWorld)
|
||||
end
|
||||
|
||||
Team.AnyAreInWorld = function(team)
|
||||
return Utils.Any(team.Actors, Actor.IsInWorld)
|
||||
end
|
||||
|
||||
Team.AddEventHandler = function(event, func)
|
||||
table.insert(event, func)
|
||||
end
|
||||
|
||||
Team.Contains = function(team, actor)
|
||||
return Utils.Any(team.Actors, function(a) return a == actor end)
|
||||
end
|
||||
|
||||
Team.Do = function(team, func)
|
||||
Utils.Do(team.Actors, function(actor)
|
||||
if not Actor.IsDead(actor) then
|
||||
func(actor)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
Team.Patrol = function(team, waypoints, wait, loop)
|
||||
Team.Do(team, function(a) Actor.Patrol(a, waypoints, wait, loop) end)
|
||||
end
|
||||
|
||||
Team.PatrolUntil = function(team, waypoints, wait, func)
|
||||
Team.Do(team, function(a) Actor.PatrolUntil(a, waypoints, wait, func) end)
|
||||
end
|
||||
@@ -1,94 +0,0 @@
|
||||
Utils = { }
|
||||
|
||||
Utils.Enumerate = function(netEnumerable)
|
||||
local enum = netEnumerable:GetEnumerator()
|
||||
return function()
|
||||
if enum:MoveNext() then
|
||||
return enum:get_Current()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Utils.EnumerableFirstOrNil = function(netEnumerable, func)
|
||||
for item in Utils.Enumerate(netEnumerable) do
|
||||
if func(item) then
|
||||
return item
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
Utils.EnumerableWhere = function(netEnumerable, func)
|
||||
local ret = { }
|
||||
for item in Utils.Enumerate(netEnumerable) do
|
||||
if func(item) then
|
||||
table.insert(ret, item)
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
Utils.EnumerableToTable = function(netEnumerable, func)
|
||||
local ret = { }
|
||||
for item in Utils.Enumerate(netEnumerable) do
|
||||
table.insert(ret, item)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
Utils.Where = function(array, func)
|
||||
local ret = { }
|
||||
for i, item in ipairs(array) do
|
||||
if func(item) then
|
||||
table.insert(ret, item)
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
Utils.All = function(array, func)
|
||||
for i, item in ipairs(array) do
|
||||
if not func(item) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
Utils.Any = function(array, func)
|
||||
for i, item in ipairs(array) do
|
||||
if func(item) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
Utils.Do = function(array, func)
|
||||
for i, item in ipairs(array) do
|
||||
func(item)
|
||||
end
|
||||
end
|
||||
|
||||
Utils.Skip = function(array, n)
|
||||
local ret = { }
|
||||
for i, item in ipairs(array) do
|
||||
if i > n then
|
||||
table.insert(ret, item)
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
Utils.TableToArray = function(luaTable)
|
||||
return Internal.TableToArray(luaTable)
|
||||
end
|
||||
|
||||
Utils.Seconds = function(seconds)
|
||||
local TicksPerSecond = 25
|
||||
return seconds * TicksPerSecond
|
||||
end
|
||||
|
||||
Utils.Minutes = function(minutes)
|
||||
return Utils.Seconds(minutes * 60)
|
||||
end
|
||||
@@ -58,11 +58,7 @@ cp thirdparty/SDL2-CS* packaging/built
|
||||
# Mono.NAT for UPnP support
|
||||
cp thirdparty/Mono.Nat.dll packaging/built
|
||||
|
||||
# (legacy) Lua
|
||||
cp thirdparty/KopiLua.dll packaging/built
|
||||
cp thirdparty/NLua.dll packaging/built
|
||||
|
||||
# Eluant (new lua)
|
||||
# Eluant (Lua integration)
|
||||
cp thirdparty/Eluant* packaging/built
|
||||
|
||||
# GeoIP database access
|
||||
|
||||
@@ -90,8 +90,6 @@ Section "Game" GAME
|
||||
File "${SRCDIR}\Newtonsoft.Json.dll"
|
||||
File "${SRCDIR}\RestSharp.dll"
|
||||
File "${SRCDIR}\GeoLite2-Country.mmdb"
|
||||
File "${SRCDIR}\KopiLua.dll"
|
||||
File "${SRCDIR}\NLua.dll"
|
||||
File "${SRCDIR}\eluant.dll"
|
||||
File "${DEPSDIR}\soft_oal.dll"
|
||||
File "${DEPSDIR}\SDL2.dll"
|
||||
@@ -212,8 +210,6 @@ Function ${UN}Clean
|
||||
Delete $INSTDIR\RestSharp.dll
|
||||
Delete $INSTDIR\GeoLite2-Country.mmdb
|
||||
Delete $INSTDIR\KopiLua.dll
|
||||
Delete $INSTDIR\NLua.dll
|
||||
Delete $INSTDIR\SDL2-CS.dll
|
||||
Delete $INSTDIR\soft_oal.dll
|
||||
Delete $INSTDIR\SDL2.dll
|
||||
Delete $INSTDIR\lua51.dll
|
||||
|
||||
BIN
thirdparty/KopiLua.dll
vendored
BIN
thirdparty/KopiLua.dll
vendored
Binary file not shown.
BIN
thirdparty/NLua.dll
vendored
BIN
thirdparty/NLua.dll
vendored
Binary file not shown.
Reference in New Issue
Block a user