diff --git a/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs b/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs deleted file mode 100755 index 76ca04846a..0000000000 --- a/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs +++ /dev/null @@ -1,92 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 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 OpenRA.FileFormats; -using OpenRA.Graphics; -using OpenRA.Mods.RA.Activities; -using OpenRA.Mods.RA.Move; -using OpenRA.Traits; - -namespace OpenRA.Mods.RA -{ - class CncShellmapScriptInfo : TraitInfo { } - - class CncShellmapScript : IWorldLoaded, ITick - { - WPos viewportOrigin; - Dictionary actors; - WorldRenderer worldRenderer; - - public void WorldLoaded(World w, WorldRenderer wr) - { - worldRenderer = wr; - var b = w.Map.Bounds; - viewportOrigin = new CPos(b.Left + b.Width / 2, b.Top + b.Height / 2).CenterPosition; - worldRenderer.Viewport.Center(viewportOrigin); - - actors = w.WorldActor.Trait().Actors; - - SetViewport(); - } - - void SetViewport() - { - var t = (ticks + 45) % (360f * speed) * (Math.PI / 180) * 1f / speed; - var offset = new float2(-15360, 4096) * float2.FromAngle((float)t); - worldRenderer.Viewport.Center(viewportOrigin + new WVec((int)offset.X, (int)offset.Y, 0)); - } - - int ticks = 0; - float speed = 4f; - - public void Tick(Actor self) - { - SetViewport(); - - if (ticks == 0) - { - LoopTrack(actors["boat1"], actors["tl1"].Location, actors["tr1"].Location); - LoopTrack(actors["boat3"], actors["tl1"].Location, actors["tr1"].Location); - LoopTrack(actors["boat2"], actors["tl3"].Location, actors["tr3"].Location); - LoopTrack(actors["boat4"], actors["tl3"].Location, actors["tr3"].Location); - CreateUnitsInTransport(actors["lst1"], new string[] { "htnk" }); - CreateUnitsInTransport(actors["lst2"], new string[] { "mcv" }); - CreateUnitsInTransport(actors["lst3"], new string[] { "htnk" }); - LoopTrack(actors["lst1"], actors["tl2"].Location, actors["tr2"].Location); - LoopTrack(actors["lst2"], actors["tl2"].Location, actors["tr2"].Location); - LoopTrack(actors["lst3"], actors["tl2"].Location, actors["tr2"].Location); - } - - ticks++; - } - - void CreateUnitsInTransport(Actor transport, string[] cargo) - { - var f = transport.Trait(); - var c = transport.Trait(); - foreach (var i in cargo) - c.Load(transport, transport.World.CreateActor(false, i.ToLowerInvariant(), new TypeDictionary - { - new OwnerInit(transport.Owner), - new FacingInit(f.Facing), - })); - } - - void LoopTrack(Actor self, CPos left, CPos right) - { - var mobile = self.Trait(); - self.QueueActivity(mobile.ScriptedMove(left)); - self.QueueActivity(new SimpleTeleport(right)); - self.QueueActivity(new CallFunc(() => LoopTrack(self, left, right))); - } - } -} diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 7899ed9238..9c27902df6 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -77,7 +77,6 @@ - diff --git a/mods/cnc/maps/shellmap/map.yaml b/mods/cnc/maps/shellmap/map.yaml index 5ebcbdbeac..d426777033 100644 --- a/mods/cnc/maps/shellmap/map.yaml +++ b/mods/cnc/maps/shellmap/map.yaml @@ -986,24 +986,6 @@ Actors: Location: 65,20 Owner: Nod Facing: 192 - tl1: mpspawn - Location: 8,33 - Owner: Neutral - tr1: mpspawn - Location: 87,33 - Owner: Neutral - tl2: mpspawn - Location: 8,35 - Owner: Neutral - tr2: mpspawn - Location: 87,35 - Owner: Neutral - tl3: mpspawn - Location: 8,37 - Owner: Neutral - tr3: mpspawn - Location: 87,37 - Owner: Neutral Smudges: @@ -1015,7 +997,8 @@ Rules: PlayMusicOnMapLoad: Music: map1 Loop: true - CncShellmapScript: + LuaScriptInterface: + LuaScripts: shellmap.lua LoadWidgetAtGameStart: Widget: MENU_BACKGROUND LST: diff --git a/mods/cnc/maps/shellmap/shellmap.lua b/mods/cnc/maps/shellmap/shellmap.lua new file mode 100644 index 0000000000..94bdc1e711 --- /dev/null +++ b/mods/cnc/maps/shellmap/shellmap.lua @@ -0,0 +1,44 @@ + +ticks = 0 +speed = 5 + +Tick = function() + ticks = ticks + 1 + local t = (ticks + 45) % (360 * speed) * (math.pi / 180) / speed; + OpenRA.SetViewportCenterPosition(WPos.op_Addition(viewportOrigin, MakeVec(-15360 * math.sin(t), 4096 * math.cos(t)))) +end + +WorldLoaded = function() + viewportOrigin = OpenRA.GetViewportCenterPosition() + CreateUnitsInTransport(lst1, { "htnk" }); + CreateUnitsInTransport(lst2, { "mcv" }); + CreateUnitsInTransport(lst3, { "htnk" }); + + local units = { boat1, boat2, boat3, boat4, lst1, lst2, lst3} + for i, unit in ipairs(units) do + LoopTrack(unit, MakePos(8, unit.Location.Y), MakePos(87, unit.Location.Y)) + end +end + +LoopTrack = function(actor, left, right) + Actor.ScriptedMove(actor, left) + Actor.Teleport(actor, right) + Actor.CallFunc(actor, function() LoopTrack(actor, left, right) end) +end + +CreateUnitsInTransport = function(transport, passengerNames) + local cargo = Actor.Trait(transport, "Cargo") + local owner = transport.owner + for i, passengerName in ipairs(passengerNames) do + cargo:Load(transport, Actor.Create(passengerName, { AddToWorld = false, Owner = owner })) + end +end + +-- TODO: The standard library should expose CPos.New() etc +MakePos = function(x, y) + return OpenRA.New("CPos", { {x, "Int32"}, {y, "Int32"} }) +end + +MakeVec = function(x, y) + return OpenRA.New("WVec", { {x, "Int32"}, {y, "Int32"}, {0, "Int32"} }) +end \ No newline at end of file