Merge pull request #6379 from Mailaender/allies-02-new-lua

Ported Allies 02 to the new Lua API
This commit is contained in:
Paul Chote
2014-10-06 19:47:43 +13:00
7 changed files with 202 additions and 75 deletions

View File

@@ -539,6 +539,7 @@
<Compile Include="Scripting\Properties\UpgradeProperties.cs" />
<Compile Include="UpgradeActorsNear.cs" />
<Compile Include="WithRangeCircle.cs" />
<Compile Include="Scripting\Properties\TransformProperties.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">

View File

@@ -171,6 +171,27 @@ namespace OpenRA.Mods.RA.Scripting
GetScriptTriggers(a).RegisterCallback(Trigger.OnRemovedFromWorld, func, context);
}
[Desc("Call a function when all of the actors in a group have been removed from the world. " +
"The callback function will be called as func().")]
public void OnAllRemovedFromWorld(Actor[] actors, LuaFunction func)
{
var group = actors.ToList();
var copy = (LuaFunction)func.CopyReference();
Action<Actor> OnMemberRemoved = m =>
{
group.Remove(m);
if (!group.Any())
{
copy.Call().Dispose();
copy.Dispose();
}
};
foreach (var a in group)
GetScriptTriggers(a).OnRemovedInternal += OnMemberRemoved;
}
[Desc("Call a function when this actor is captured. The callback function " +
"will be called as func(Actor self, Actor captor, Player oldOwner, Player newOwner).")]
public void OnCapture(Actor a, LuaFunction func)

View File

@@ -0,0 +1,34 @@
#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 OpenRA.Scripting;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Scripting
{
[ScriptPropertyGroup("Transform")]
public class TransformProperties : ScriptActorProperties, Requires<TransformsInfo>
{
readonly Transforms transforms;
public TransformProperties(ScriptContext context, Actor self)
: base(context, self)
{
transforms = self.Trait<Transforms>();
}
[ScriptActorPropertyActivity]
[Desc("Queue a new transformation.")]
public void Deploy()
{
transforms.DeployTransform(true);
}
}
}

View File

@@ -26,7 +26,8 @@ namespace OpenRA.Mods.RA.Scripting
public sealed class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction, INotifyObjectivesUpdated, INotifyCapture, INotifyAddedToWorld, INotifyRemovedFromWorld, IDisposable
{
public event Action<Actor> OnKilledInternal = _ => {};
public event Action<Actor> OnKilledInternal = _ => { };
public event Action<Actor> OnRemovedInternal = _ => { };
public Dictionary<Trigger, List<Pair<LuaFunction, ScriptContext>>> Triggers = new Dictionary<Trigger, List<Pair<LuaFunction, ScriptContext>>>();
@@ -58,7 +59,7 @@ namespace OpenRA.Mods.RA.Scripting
public void Killed(Actor self, AttackInfo e)
{
// Run lua callbacks
// Run Lua callbacks
foreach (var f in Triggers[Trigger.OnKilled])
using (var a = self.ToLuaValue(f.Second))
using (var b = e.Attacker.ToLuaValue(f.Second))
@@ -133,9 +134,13 @@ namespace OpenRA.Mods.RA.Scripting
public void RemovedFromWorld(Actor self)
{
// Run Lua callbacks
foreach (var f in Triggers[Trigger.OnRemovedFromWorld])
using (var a = self.ToLuaValue(f.Second))
f.First.Call(a).Dispose();
// Run any internally bound callbacks
OnRemovedInternal(self);
}
public void Clear(Trigger trigger)