diff --git a/AUTHORS b/AUTHORS index 19d7cd2132..61952da5d7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -69,7 +69,11 @@ Also thanks to: Using GeoLite data created by MaxMind and distributed under the CC BY-SA 3.0 license. -Using MonoBoxedLua created by Sparklin Labs +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. Finally, special thanks goes to the original teams diff --git a/Makefile b/Makefile index 0fec946245..8010ed4047 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ INSTALL_PROGRAM = $(INSTALL) -m755 INSTALL_DATA = $(INSTALL) -m644 # program targets -CORE = fileformats rcg rgl rsdl rnull game utility geoip irc lua +CORE = fileformats rcg rgl rsdl rnull game utility geoip irc TOOLS = editor tsbuild ralint VERSION = $(shell git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || echo git-`git rev-parse --short HEAD`) @@ -107,14 +107,6 @@ irc_LIBS = $(COMMON_LIBS) $(irc_DEPS) PROGRAMS += irc irc: $(irc_TARGET) -lua_SRCS := $(shell find LuaInterface/ -name '*.cs') -lua_TARGET = LuaInterface.dll -lua_KIND = library -lua_DEPS = $(fileformats_TARGET) -lua_LIBS = $(COMMON_LIBS) $(lua_DEPS) -PROGRAMS += lua -lua: $(lua_TARGET) - # Renderer dlls rsdl_SRCS := $(shell find OpenRA.Renderer.SdlCommon/ -iname '*.cs') rsdl_TARGET = OpenRA.Renderer.SdlCommon.dll @@ -152,15 +144,15 @@ renderers: $(rcg_TARGET) $(rgl_TARGET) $(rsdl2_TARGET) $(rnull_TARGET) $(rsdl_TA ##### Official Mods ##### -STD_MOD_LIBS = $(fileformats_TARGET) $(game_TARGET) +STD_MOD_LIBS = $(fileformats_TARGET) $(game_TARGET) thirdparty/KopiLua.dll thirdparty/NLua.dll STD_MOD_DEPS = $(STD_MOD_LIBS) $(ralint_TARGET) # Red Alert mod_ra_SRCS := $(shell find OpenRA.Mods.RA/ -iname '*.cs') mod_ra_TARGET = mods/ra/OpenRA.Mods.RA.dll mod_ra_KIND = library -mod_ra_DEPS = $(STD_MOD_DEPS) $(geoip_TARGET) $(irc_TARGET) $(lua_TARGET) -mod_ra_LIBS = $(COMMON_LIBS) $(STD_MOD_LIBS) $(geoip_TARGET) $(irc_TARGET) $(lua_TARGET) +mod_ra_DEPS = $(STD_MOD_DEPS) $(geoip_TARGET) $(irc_TARGET) +mod_ra_LIBS = $(COMMON_LIBS) $(STD_MOD_LIBS) $(geoip_TARGET) $(irc_TARGET) PROGRAMS += mod_ra mod_ra: $(mod_ra_TARGET) @@ -303,8 +295,6 @@ distclean: clean dependencies: @ $(CP_R) thirdparty/*.dl* . - @ $(CP_R) thirdparty/*.dylib . - @ $(CP_R) thirdparty/*.so . @ $(CP_R) thirdparty/Tao/* . version: mods/ra/mod.yaml mods/cnc/mod.yaml mods/d2k/mod.yaml @@ -348,10 +338,8 @@ install-core: default @$(INSTALL_PROGRAM) thirdparty/SharpFont.dll "$(DATA_INSTALL_DIR)" @$(CP) thirdparty/SharpFont.dll.config "$(DATA_INSTALL_DIR)" @$(INSTALL_PROGRAM) thirdparty/Mono.Nat.dll "$(DATA_INSTALL_DIR)" - @$(CP) thirdparty/LuaInterface.dll.config "$(DATA_INSTALL_DIR)" - @$(INSTALL_PROGRAM) thirdparty/liblua-linux32.so "$(DATA_INSTALL_DIR)" - @$(INSTALL_PROGRAM) thirdparty/liblua-linux64.so "$(DATA_INSTALL_DIR)" - @$(INSTALL_PROGRAM) thirdparty/liblua-osx.dylib "$(DATA_INSTALL_DIR)" + @$(INSTALL_PROGRAM) thirdparty/KopiLua.dll "$(DATA_INSTALL_DIR)" + @$(INSTALL_PROGRAM) thirdparty/NLua.dll "$(DATA_INSTALL_DIR)" @echo "#!/bin/sh" > openra @echo 'BINDIR=$$(dirname $$(readlink -f $$0))' >> openra diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 8bfeee8316..224c878321 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -63,6 +63,12 @@ ..\thirdparty\FuzzyLogicLibrary.dll + + ..\thirdparty\KopiLua.dll + + + ..\thirdparty\NLua.dll + @@ -478,10 +484,6 @@ - - {E915A0A4-2641-4F7E-8A88-8F123FA88BF1} - LuaInterface - {BDAEAB25-991E-46A7-AF1E-4F0E03358DAA} OpenRA.FileFormats diff --git a/OpenRA.Mods.RA/Scripting/LuaScriptContext.cs b/OpenRA.Mods.RA/Scripting/LuaScriptContext.cs index 5930d87fb9..12a44ff2e0 100644 --- a/OpenRA.Mods.RA/Scripting/LuaScriptContext.cs +++ b/OpenRA.Mods.RA/Scripting/LuaScriptContext.cs @@ -12,18 +12,23 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using LuaInterface; +using NLua; +using NLua.Event; +using OpenRA.FileFormats; namespace OpenRA.Mods.RA.Scripting { public class LuaScriptContext : IDisposable { public Lua Lua { get; private set; } + readonly Cache functionCache; public LuaScriptContext() { Log.Write("debug", "Creating Lua script context"); Lua = new Lua(); + Lua.HookException += OnLuaException; + functionCache = new Cache(Lua.GetFunction); } public void RegisterObject(object target, string tableName, bool exposeAllMethods) @@ -76,11 +81,21 @@ namespace OpenRA.Mods.RA.Scripting } } - void LogException(Exception e) + void OnLuaException(object sender, HookExceptionEventArgs e) { - Game.Debug("{0}", e.Message); + 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 debug.log for details"); - Log.Write("debug", "{0}", e); + Log.Write("debug", "{0}", longMessage ?? shortMessage); } public void LoadLuaScripts(Func getFileContents, params string[] files) @@ -95,7 +110,7 @@ namespace OpenRA.Mods.RA.Scripting } catch (Exception e) { - LogException(e); + ShowException(e); } } } @@ -104,14 +119,14 @@ namespace OpenRA.Mods.RA.Scripting { try { - var function = Lua.GetFunction(name); + var function = functionCache[name]; if (function == null) return null; return function.Call(args); } catch (Exception e) { - LogException(e); + ShowException(e); return null; } } diff --git a/OpenRA.Mods.RA/Scripting/LuaScriptEvents.cs b/OpenRA.Mods.RA/Scripting/LuaScriptEvents.cs index a9a361b5be..b5da934217 100644 --- a/OpenRA.Mods.RA/Scripting/LuaScriptEvents.cs +++ b/OpenRA.Mods.RA/Scripting/LuaScriptEvents.cs @@ -9,7 +9,6 @@ #endregion using System; -using System.Collections.Generic; using OpenRA.Traits; namespace OpenRA.Mods.RA.Scripting diff --git a/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs b/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs index db5c240a14..69345ff428 100644 --- a/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs +++ b/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs @@ -8,16 +8,17 @@ */ #endregion -using LuaInterface; +using System; +using System.Linq; +using NLua; using OpenRA.Effects; using OpenRA.FileFormats; using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Air; using OpenRA.Mods.RA.Missions; using OpenRA.Scripting; +using OpenRA.Support; using OpenRA.Traits; -using System; -using System.Linq; using WorldRenderer = OpenRA.Graphics.WorldRenderer; namespace OpenRA.Mods.RA.Scripting @@ -43,7 +44,7 @@ namespace OpenRA.Mods.RA.Scripting public void WorldLoaded(World w, WorldRenderer wr) { world = w; - AddMapActorGlobals(); + context.Lua["World"] = w; context.Lua["WorldRenderer"] = wr; context.RegisterObject(this, "Internal", false); @@ -55,22 +56,33 @@ namespace OpenRA.Mods.RA.Scripting context.RegisterType(typeof(WRange), "WRange", true); context.RegisterType(typeof(int2), "int2", true); context.RegisterType(typeof(float2), "float2", true); + var sharedScripts = Game.modData.Manifest.LuaScripts ?? new string[0]; if (sharedScripts.Any()) context.LoadLuaScripts(f => FileSystem.Open(f).ReadAllText(), sharedScripts); + + AddMapActorGlobals(); + context.LoadLuaScripts(f => w.Map.Container.GetContent(f).ReadAllText(), info.LuaScripts); + context.InvokeLuaFunction("WorldLoaded"); } void AddMapActorGlobals() { foreach (var kv in world.WorldActor.Trait().Actors) - context.Lua[kv.Key] = kv.Value; + { + 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) { - context.InvokeLuaFunction("Tick"); + using (new PerfSample("tick_lua")) + context.InvokeLuaFunction("Tick"); } [LuaGlobal] diff --git a/OpenRA.sln b/OpenRA.sln index d1d5dcbd60..be7b5e62af 100644 --- a/OpenRA.sln +++ b/OpenRA.sln @@ -41,8 +41,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Irc", "OpenRA.Irc\Op EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Renderer.Sdl2", "OpenRA.Renderer.Sdl2\OpenRA.Renderer.Sdl2.csproj", "{33D03738-C154-4028-8EA8-63A3C488A651}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LuaInterface", "LuaInterface\LuaInterface.csproj", "{E915A0A4-2641-4F7E-8A88-8F123FA88BF1}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -138,14 +136,6 @@ Global {E9C01A96-C3E2-4772-825B-A740AC513D31}.Release|Any CPU.Build.0 = Release|Any CPU {E9C01A96-C3E2-4772-825B-A740AC513D31}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {E9C01A96-C3E2-4772-825B-A740AC513D31}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {33D03738-C154-4028-8EA8-63A3C488A651}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {33D03738-C154-4028-8EA8-63A3C488A651}.Debug|Any CPU.Build.0 = Debug|Any CPU - {33D03738-C154-4028-8EA8-63A3C488A651}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {33D03738-C154-4028-8EA8-63A3C488A651}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {33D03738-C154-4028-8EA8-63A3C488A651}.Release|Any CPU.ActiveCfg = Release|Any CPU - {33D03738-C154-4028-8EA8-63A3C488A651}.Release|Any CPU.Build.0 = Release|Any CPU - {33D03738-C154-4028-8EA8-63A3C488A651}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {33D03738-C154-4028-8EA8-63A3C488A651}.Release|Mixed Platforms.Build.0 = Release|Any CPU {52FD9F0B-B209-4ED7-8A32-AC8033363263}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {52FD9F0B-B209-4ED7-8A32-AC8033363263}.Debug|Any CPU.Build.0 = Debug|Any CPU {52FD9F0B-B209-4ED7-8A32-AC8033363263}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -186,14 +176,14 @@ Global {85B48234-8B31-4BE6-AF9C-665CC6866841}.Release|Any CPU.Build.0 = Release|Any CPU {85B48234-8B31-4BE6-AF9C-665CC6866841}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {85B48234-8B31-4BE6-AF9C-665CC6866841}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {E915A0A4-2641-4F7E-8A88-8F123FA88BF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E915A0A4-2641-4F7E-8A88-8F123FA88BF1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E915A0A4-2641-4F7E-8A88-8F123FA88BF1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {E915A0A4-2641-4F7E-8A88-8F123FA88BF1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {E915A0A4-2641-4F7E-8A88-8F123FA88BF1}.Release|Any CPU.ActiveCfg = Debug|Any CPU - {E915A0A4-2641-4F7E-8A88-8F123FA88BF1}.Release|Any CPU.Build.0 = Debug|Any CPU - {E915A0A4-2641-4F7E-8A88-8F123FA88BF1}.Release|Mixed Platforms.ActiveCfg = Debug|Any CPU - {E915A0A4-2641-4F7E-8A88-8F123FA88BF1}.Release|Mixed Platforms.Build.0 = Debug|Any CPU + {33D03738-C154-4028-8EA8-63A3C488A651}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {33D03738-C154-4028-8EA8-63A3C488A651}.Debug|Any CPU.Build.0 = Debug|Any CPU + {33D03738-C154-4028-8EA8-63A3C488A651}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {33D03738-C154-4028-8EA8-63A3C488A651}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {33D03738-C154-4028-8EA8-63A3C488A651}.Release|Any CPU.ActiveCfg = Release|Any CPU + {33D03738-C154-4028-8EA8-63A3C488A651}.Release|Any CPU.Build.0 = Release|Any CPU + {33D03738-C154-4028-8EA8-63A3C488A651}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {33D03738-C154-4028-8EA8-63A3C488A651}.Release|Mixed Platforms.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution StartupItem = OpenRA.Game\OpenRA.Game.csproj diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index f00675d58a..369bf87239 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -172,3 +172,5 @@ LuaScripts: mods/ra/lua/team.lua mods/ra/lua/media.lua mods/ra/lua/mission.lua + mods/ra/lua/reinforcements.lua + mods/ra/lua/supportpowers.lua diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index bdccad9daa..857a1c26e8 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -152,3 +152,5 @@ LuaScripts: mods/ra/lua/team.lua mods/ra/lua/media.lua mods/ra/lua/mission.lua + mods/ra/lua/reinforcements.lua + mods/ra/lua/supportpowers.lua diff --git a/mods/ra/lua/mission.lua b/mods/ra/lua/mission.lua index ed26c90e0a..94fca80214 100644 --- a/mods/ra/lua/mission.lua +++ b/mods/ra/lua/mission.lua @@ -1,87 +1,5 @@ Mission = { } -Mission.PerformHelicopterInsertion = function(owner, helicopterName, passengerNames, enterPosition, unloadPosition, exitPosition) - local facing = { Map.GetFacing(WPos.op_Subtraction(unloadPosition, enterPosition), 0), "Int32" } - local altitude = { Actor.TraitInfo(helicopterName, "AircraftInfo").CruiseAltitude, "Int32" } - local heli = Actor.Create(helicopterName, { Owner = owner, CenterPosition = enterPosition, Facing = facing, Altitude = altitude }) - local cargo = Actor.Trait(heli, "Cargo") - local passengers = { } - for i, passengerName in ipairs(passengerNames) do - local passenger = Actor.Create(passengerName, { AddToWorld = false, Owner = owner }) - cargo:Load(heli, passenger) - passengers[i] = passenger - end - Actor.HeliFly(heli, unloadPosition) - Actor.Turn(heli, 0) - Actor.HeliLand(heli, true) - Actor.UnloadCargo(heli, true) - Actor.Wait(heli, 125) - Actor.HeliFly(heli, exitPosition) - Actor.RemoveSelf(heli) - return heli, passengers -end - -Mission.PerformHelicopterExtraction = function(owner, helicopterName, passengers, enterPosition, loadPosition, exitPosition) - local facing = { Map.GetFacing(WPos.op_Subtraction(loadPosition, enterPosition), 0), "Int32" } - local altitude = { Actor.TraitInfo(helicopterName, "AircraftInfo").CruiseAltitude, "Int32" } - local heli = Actor.Create(helicopterName, { Owner = owner, CenterPosition = enterPosition, Facing = facing, Altitude = altitude }) - local cargo = Actor.Trait(heli, "Cargo") - Actor.HeliFly(heli, loadPosition) - Actor.Turn(heli, 0) - Actor.HeliLand(heli, true) - Actor.WaitFor(heli, function() - for i, passenger in ipairs(passengers) do - if not cargo.Passengers:Contains(passenger) then - return false - end - end - return true - end) - Actor.Wait(heli, 125) - Actor.HeliFly(heli, exitPosition) - Actor.RemoveSelf(heli) - return heli -end - -Mission.Reinforce = function(owner, reinforcementNames, enterLocation, rallyPointLocation, interval, onCreateFunc) - local facing = { Map.GetFacing(CPos.op_Subtraction(rallyPointLocation, enterLocation), 0), "Int32" } - local ret = { } - for i = 1, #reinforcementNames do - local reinforcement = Actor.Create(reinforcementNames[i], { AddToWorld = false, Owner = owner, Location = enterLocation, Facing = facing }) - table.insert(ret, 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 ret -end - -Mission.Parabomb = function(owner, planeName, enterLocation, bombLocation) - local facing = { Map.GetFacing(CPos.op_Subtraction(bombLocation, enterLocation), 0), "Int32" } - local altitude = { Actor.TraitInfo(planeName, "AircraftInfo").CruiseAltitude, "Int32" } - local plane = Actor.Create(planeName, { Location = enterLocation, Owner = owner, Facing = facing, Altitude = altitude }) - Actor.Trait(plane, "AttackBomber"):SetTarget(bombLocation.CenterPosition) - Actor.Fly(plane, bombLocation.CenterPosition) - Actor.FlyOffMap(plane) - Actor.RemoveSelf(plane) -end - -Mission.Paradrop = function(owner, planeName, passengerNames, enterLocation, dropLocation) - local facing = { Map.GetFacing(CPos.op_Subtraction(dropLocation, enterLocation), 0), "Int32" } - local altitude = { Actor.TraitInfo(planeName, "AircraftInfo").CruiseAltitude, "Int32" } - local plane = Actor.Create(planeName, { Location = enterLocation, Owner = owner, Facing = facing, Altitude = altitude }) - Actor.FlyAttackCell(plane, dropLocation) - Actor.Trait(plane, "ParaDrop"):SetLZ(dropLocation) - local cargo = Actor.Trait(plane, "Cargo") - for i, passengerName in ipairs(passengerNames) do - cargo:Load(plane, Actor.Create(passengerName, { AddToWorld = false, Owner = owner })) - end -end - Mission.MissionOver = function(winners, losers, setWinStates) World:SetLocalPauseState(true) World:set_PauseStateLocked(true) diff --git a/mods/ra/lua/openra.lua b/mods/ra/lua/openra.lua index ae746d2db4..64589a1ba1 100644 --- a/mods/ra/lua/openra.lua +++ b/mods/ra/lua/openra.lua @@ -1,6 +1,11 @@ +print = Internal.Debug + OpenRA = { } OpenRA.New = function(className, args) + if args == nil then + args = { } + end return Internal.New(className, args) end @@ -8,10 +13,6 @@ OpenRA.RunAfterDelay = function(delay, func) Internal.RunAfterDelay(delay, func) end -OpenRA.Debug = function(obj) - Internal.Debug(obj) -end - OpenRA.SetViewportCenterPosition = function(position) WorldRenderer.Viewport:Center(position) end diff --git a/mods/ra/lua/reinforcements.lua b/mods/ra/lua/reinforcements.lua new file mode 100644 index 0000000000..d9eb68b131 --- /dev/null +++ b/mods/ra/lua/reinforcements.lua @@ -0,0 +1,61 @@ +Reinforcements = { } + +Reinforcements.PerformHelicopterInsertion = function(owner, helicopterName, passengerNames, enterPosition, unloadPosition, exitPosition) + local facing = { Map.GetFacing(WPos.op_Subtraction(unloadPosition, enterPosition), 0), "Int32" } + local altitude = { Actor.TraitInfo(helicopterName, "AircraftInfo").CruiseAltitude, "Int32" } + local heli = Actor.Create(helicopterName, { Owner = owner, CenterPosition = enterPosition, Facing = facing, Altitude = altitude }) + local cargo = Actor.Trait(heli, "Cargo") + local passengers = { } + for i, passengerName in ipairs(passengerNames) do + local passenger = Actor.Create(passengerName, { AddToWorld = false, Owner = owner }) + cargo:Load(heli, passenger) + passengers[i] = passenger + end + Actor.HeliFly(heli, unloadPosition) + Actor.Turn(heli, 0) + Actor.HeliLand(heli, true) + Actor.UnloadCargo(heli, true) + Actor.Wait(heli, 125) + Actor.HeliFly(heli, exitPosition) + Actor.RemoveSelf(heli) + return heli, passengers +end + +Reinforcements.PerformHelicopterExtraction = function(owner, helicopterName, passengers, enterPosition, loadPosition, exitPosition) + local facing = { Map.GetFacing(WPos.op_Subtraction(loadPosition, enterPosition), 0), "Int32" } + local altitude = { Actor.TraitInfo(helicopterName, "AircraftInfo").CruiseAltitude, "Int32" } + local heli = Actor.Create(helicopterName, { Owner = owner, CenterPosition = enterPosition, Facing = facing, Altitude = altitude }) + local cargo = Actor.Trait(heli, "Cargo") + Actor.HeliFly(heli, loadPosition) + Actor.Turn(heli, 0) + Actor.HeliLand(heli, true) + Actor.WaitFor(heli, function() + for i, passenger in ipairs(passengers) do + if not cargo.Passengers:Contains(passenger) then + return false + end + end + return true + end) + Actor.Wait(heli, 125) + Actor.HeliFly(heli, exitPosition) + Actor.RemoveSelf(heli) + return heli +end + +Reinforcements.Reinforce = function(owner, reinforcementNames, enterLocation, rallyPointLocation, interval, onCreateFunc) + local facing = { Map.GetFacing(CPos.op_Subtraction(rallyPointLocation, enterLocation), 0), "Int32" } + local ret = { } + for i = 1, #reinforcementNames do + local reinforcement = Actor.Create(reinforcementNames[i], { AddToWorld = false, Owner = owner, Location = enterLocation, Facing = facing }) + table.insert(ret, 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 ret +end \ No newline at end of file diff --git a/mods/ra/lua/supportpowers.lua b/mods/ra/lua/supportpowers.lua new file mode 100644 index 0000000000..bd6b4d50bc --- /dev/null +++ b/mods/ra/lua/supportpowers.lua @@ -0,0 +1,23 @@ +SupportPowers = { } + +SupportPowers.Parabomb = function(owner, planeName, enterLocation, bombLocation) + local facing = { Map.GetFacing(CPos.op_Subtraction(bombLocation, enterLocation), 0), "Int32" } + local altitude = { Actor.TraitInfo(planeName, "AircraftInfo").CruiseAltitude, "Int32" } + local plane = Actor.Create(planeName, { Location = enterLocation, Owner = owner, Facing = facing, Altitude = altitude }) + Actor.Trait(plane, "AttackBomber"):SetTarget(bombLocation.CenterPosition) + Actor.Fly(plane, bombLocation.CenterPosition) + Actor.FlyOffMap(plane) + Actor.RemoveSelf(plane) +end + +SupportPowers.Paradrop = function(owner, planeName, passengerNames, enterLocation, dropLocation) + local facing = { Map.GetFacing(CPos.op_Subtraction(dropLocation, enterLocation), 0), "Int32" } + local altitude = { Actor.TraitInfo(planeName, "AircraftInfo").CruiseAltitude, "Int32" } + local plane = Actor.Create(planeName, { Location = enterLocation, Owner = owner, Facing = facing, Altitude = altitude }) + Actor.FlyAttackCell(plane, dropLocation) + Actor.Trait(plane, "ParaDrop"):SetLZ(dropLocation) + local cargo = Actor.Trait(plane, "Cargo") + for i, passengerName in ipairs(passengerNames) do + cargo:Load(plane, Actor.Create(passengerName, { AddToWorld = false, Owner = owner })) + end +end \ No newline at end of file diff --git a/mods/ra/maps/allies-01-classic/mission.lua b/mods/ra/maps/allies-01-classic/mission.lua index b57014e5c3..c52bf6be7b 100644 --- a/mods/ra/maps/allies-01-classic/mission.lua +++ b/mods/ra/maps/allies-01-classic/mission.lua @@ -13,7 +13,7 @@ CivilianWait = 150 BaseAlertDelay = 300 SendInsertionHelicopter = function() - local heli, passengers = Mission.PerformHelicopterInsertion(player, InsertionHelicopterType, { TanyaType }, + local heli, passengers = Reinforcements.PerformHelicopterInsertion(player, InsertionHelicopterType, { TanyaType }, InsertionEntry.CenterPosition, InsertionLZ.CenterPosition, InsertionEntry.CenterPosition) tanya = passengers[1] Actor.OnKilled(tanya, TanyaKilled) @@ -21,7 +21,7 @@ end SendJeeps = function() Media.PlaySpeechNotification("ReinforcementsArrived") - Mission.Reinforce(player, JeepReinforcements, InsertionEntry.Location, InsertionLZ.Location, JeepInterval) + Reinforcements.Reinforce(player, JeepReinforcements, InsertionEntry.Location, InsertionLZ.Location, JeepInterval) end RunInitialActivities = function() @@ -59,7 +59,7 @@ LabGuardsKilled = function() end SendExtractionHelicopter = function() - local heli = Mission.PerformHelicopterExtraction(player, ExtractionHelicopterType, { einstein }, + local heli = Reinforcements.PerformHelicopterExtraction(player, ExtractionHelicopterType, { einstein }, SouthReinforcementsPoint.CenterPosition, ExtractionLZ.CenterPosition, ExtractionExitPoint.CenterPosition) Actor.OnKilled(heli, HelicopterDestroyed) Actor.OnRemovedFromWorld(heli, HelicopterExtractionCompleted) diff --git a/mods/ra/maps/allies-02-classic/mission.lua b/mods/ra/maps/allies-02-classic/mission.lua index b6c0bf1d37..1c2ae5d54d 100644 --- a/mods/ra/maps/allies-02-classic/mission.lua +++ b/mods/ra/maps/allies-02-classic/mission.lua @@ -1,5 +1,5 @@ -Reinforcements = { "e1", "e1", "e1", "jeep" } -ReinforcementsInterval = 15 +JeepReinforcements = { "e1", "e1", "e1", "jeep" } +JeepReinforcementsInterval = 15 TruckNames = { "truk", "truk", "truk" } TruckInterval = 25 TruckDelay = 75 @@ -15,7 +15,7 @@ end SendJeepReinforcements = function() Media.PlaySpeechNotification("ReinforcementsArrived") - Mission.Reinforce(player, Reinforcements, ReinforcementsEntryPoint.Location, ReinforcementsRallyPoint.Location, ReinforcementsInterval) + Reinforcements.Reinforce(player, JeepReinforcements, ReinforcementsEntryPoint.Location, ReinforcementsRallyPoint.Location, JeepReinforcementsInterval) end RunInitialActivities = function() @@ -49,7 +49,7 @@ end SendTrucks = function() Media.PlaySpeechNotification("ConvoyApproaching") OpenRA.RunAfterDelay(TruckDelay, function() - local trucks = Mission.Reinforce(france, TruckNames, TruckEntryPoint.Location, TruckRallyPoint.Location, TruckInterval, + local trucks = Reinforcements.Reinforce(france, TruckNames, TruckEntryPoint.Location, TruckRallyPoint.Location, TruckInterval, function(truck) Actor.Move(truck, TruckExitPoint.Location) Actor.RemoveSelf(truck) diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index 630f97383f..245e507a6c 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -172,3 +172,5 @@ LuaScripts: mods/ra/lua/team.lua mods/ra/lua/media.lua mods/ra/lua/mission.lua + mods/ra/lua/reinforcements.lua + mods/ra/lua/supportpowers.lua diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index ffb690c447..ad335e599b 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -193,3 +193,5 @@ LuaScripts: mods/ra/lua/team.lua mods/ra/lua/media.lua mods/ra/lua/mission.lua + mods/ra/lua/reinforcements.lua + mods/ra/lua/supportpowers.lua diff --git a/packaging/linux/buildpackage.sh b/packaging/linux/buildpackage.sh index 3aa9fe6afe..25cd6990ce 100644 --- a/packaging/linux/buildpackage.sh +++ b/packaging/linux/buildpackage.sh @@ -25,9 +25,6 @@ cp *.sh "$PWD/packaging/linux/$ROOTDIR/usr/lib/openra/" || exit 3 # Icons and .desktop files make install-shortcuts prefix="/usr" DESTDIR="$PWD/packaging/linux/$ROOTDIR" -# Remove Mac OS X libaries -rm -rf "$PWD/packaging/linux/$ROOTDIR/usr/lib/openra/liblua-osx.dylib" || exit 3 - cd packaging/linux ( diff --git a/packaging/osx/buildpackage.sh b/packaging/osx/buildpackage.sh index c511a3d8fe..ded6a6f695 100755 --- a/packaging/osx/buildpackage.sh +++ b/packaging/osx/buildpackage.sh @@ -21,10 +21,6 @@ cp -rv $2/* "OpenRA.app/Contents/Resources/" || exit 3 rm OpenRA.app/Contents/Resources/OpenRA.ico rm OpenRA.app/Contents/Resources/OpenRA.Editor.exe -# Install the stripped down Lua library -cp ../../liblua-osx.dylib OpenRA.app/Contents/Resources/ -cp ../../LuaInterface.dll.config OpenRA.app/Contents/Resources/ - # SDL2 is the only supported renderer rm -rf OpenRA.app/Contents/Resources/cg rm OpenRA.app/Contents/Resources/OpenRA.Renderer.Cg.dll diff --git a/packaging/package-all.sh b/packaging/package-all.sh index 20d6d8ffeb..d64c6e6c98 100755 --- a/packaging/package-all.sh +++ b/packaging/package-all.sh @@ -32,7 +32,7 @@ FILES=('OpenRA.Game.exe' 'OpenRA.Editor.exe' 'OpenRA.Utility.exe' \ 'cg' 'glsl' 'mods/ra' 'mods/cnc' 'mods/d2k' \ 'AUTHORS' 'CHANGELOG' 'COPYING' \ 'README.html' 'CONTRIBUTING.html' 'DOCUMENTATION.html' \ -'global mix database.dat' 'GeoIP.dll' 'GeoIP.dat' 'LuaInterface.dll') +'global mix database.dat' 'GeoIP.dll' 'GeoIP.dat') echo "Copying files..." for i in "${FILES[@]}"; do @@ -57,6 +57,10 @@ cp thirdparty/SDL2\#* packaging/built # Mono.NAT for UPnP support cp thirdparty/Mono.Nat.dll packaging/built +# Lua +cp thirdparty/KopiLua.dll packaging/built +cp thirdparty/NLua.dll packaging/built + # Copy game icon for windows package cp OpenRA.Game/OpenRA.ico packaging/built diff --git a/packaging/windows/OpenRA.nsi b/packaging/windows/OpenRA.nsi index 2c5d64629a..d9d90cc04c 100644 --- a/packaging/windows/OpenRA.nsi +++ b/packaging/windows/OpenRA.nsi @@ -83,8 +83,8 @@ Section "Game" GAME File "${SRCDIR}\global mix database.dat" File "${SRCDIR}\GeoIP.dll" File "${SRCDIR}\GeoIP.dat" - File "${SRCDIR}\LuaInterface.dll" - File lua51.dll + File "${SRCDIR}\KopiLua.dll" + File "${SRCDIR}\NLua.dll" File OpenAL32.dll File SDL.dll File freetype6.dll @@ -203,8 +203,8 @@ Function ${UN}Clean Delete "$INSTDIR\global mix database.dat" Delete $INSTDIR\GeoIP.dat Delete $INSTDIR\GeoIP.dll - Delete $INSTDIR\LuaInterface.dll - Delete $INSTDIR\lua51.dll + Delete $INSTDIR\KopiLua.dll + Delete $INSTDIR\NLua.dll Delete $INSTDIR\OpenAL32.dll Delete $INSTDIR\SDL.dll Delete $INSTDIR\freetype6.dll diff --git a/packaging/windows/lua51.dll b/packaging/windows/lua51.dll deleted file mode 100644 index 07f311f703..0000000000 Binary files a/packaging/windows/lua51.dll and /dev/null differ diff --git a/thirdparty/KopiLua.dll b/thirdparty/KopiLua.dll new file mode 100644 index 0000000000..18497eb8ff Binary files /dev/null and b/thirdparty/KopiLua.dll differ diff --git a/thirdparty/LuaInterface.dll.config b/thirdparty/LuaInterface.dll.config deleted file mode 100644 index 97931b2a89..0000000000 --- a/thirdparty/LuaInterface.dll.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/thirdparty/NLua.dll b/thirdparty/NLua.dll new file mode 100644 index 0000000000..165ead6625 Binary files /dev/null and b/thirdparty/NLua.dll differ diff --git a/thirdparty/liblua-linux32.so b/thirdparty/liblua-linux32.so deleted file mode 100644 index fec8643995..0000000000 Binary files a/thirdparty/liblua-linux32.so and /dev/null differ diff --git a/thirdparty/liblua-linux64.so b/thirdparty/liblua-linux64.so deleted file mode 100644 index dfe43c6115..0000000000 Binary files a/thirdparty/liblua-linux64.so and /dev/null differ diff --git a/thirdparty/liblua-osx.dylib b/thirdparty/liblua-osx.dylib deleted file mode 100644 index 01731e5f56..0000000000 Binary files a/thirdparty/liblua-osx.dylib and /dev/null differ