Expose passenger enter/exit notifications to Lua

This commit is contained in:
Taryn Hill
2016-03-29 07:00:01 -05:00
parent 6d4e365af5
commit c6265527b2
2 changed files with 61 additions and 2 deletions

View File

@@ -12,6 +12,7 @@
using System;
using System.Collections.Generic;
using Eluant;
using OpenRA.Mods.Common.Traits;
using OpenRA.Scripting;
using OpenRA.Traits;
@@ -21,7 +22,8 @@ namespace OpenRA.Mods.Common.Scripting
{
OnIdle, OnDamaged, OnKilled, OnProduction, OnOtherProduction, OnPlayerWon, OnPlayerLost,
OnObjectiveAdded, OnObjectiveCompleted, OnObjectiveFailed, OnCapture, OnInfiltrated,
OnAddedToWorld, OnRemovedFromWorld, OnDiscovered, OnPlayerDiscovered
OnAddedToWorld, OnRemovedFromWorld, OnDiscovered, OnPlayerDiscovered,
OnPassengerEntered, OnPassengerExited
}
[Desc("Allows map scripts to attach triggers to this actor via the Triggers global.")]
@@ -31,7 +33,8 @@ namespace OpenRA.Mods.Common.Scripting
}
public sealed class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction, INotifyOtherProduction,
INotifyObjectivesUpdated, INotifyCapture, INotifyInfiltrated, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyDiscovered, INotifyActorDisposing
INotifyObjectivesUpdated, INotifyCapture, INotifyInfiltrated, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyDiscovered, INotifyActorDisposing,
INotifyPassengerEntered, INotifyPassengerExited
{
readonly World world;
readonly Actor self;
@@ -421,6 +424,48 @@ namespace OpenRA.Mods.Common.Scripting
}
}
void INotifyPassengerEntered.OnPassengerEntered(Actor self, Actor passenger)
{
if (world.Disposing)
return;
foreach (var f in Triggerables(Trigger.OnPassengerEntered))
{
try
{
using (var trans = self.ToLuaValue(f.Context))
using (var pass = passenger.ToLuaValue(f.Context))
f.Function.Call(trans, pass).Dispose();
}
catch (Exception ex)
{
f.Context.FatalError(ex.Message);
return;
}
}
}
void INotifyPassengerExited.OnPassengerExited(Actor self, Actor passenger)
{
if (world.Disposing)
return;
foreach (var f in Triggerables(Trigger.OnPassengerExited))
{
try
{
using (var trans = self.ToLuaValue(f.Context))
using (var pass = passenger.ToLuaValue(f.Context))
f.Function.Call(trans, pass).Dispose();
}
catch (Exception ex)
{
f.Context.FatalError(ex.Message);
return;
}
}
}
public void Clear(Trigger trigger)
{
world.AddFrameEndTask(w =>