Add INotify(Activity)StanceChanged interfaces.
This commit is contained in:
@@ -171,6 +171,20 @@ namespace OpenRA.Activities
|
||||
act = act.childActivity;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<T> ActivitiesImplementing<T>() where T : IActivityInterface
|
||||
{
|
||||
if (childActivity != null)
|
||||
foreach (var a in childActivity.ActivitiesImplementing<T>())
|
||||
yield return a;
|
||||
|
||||
if (this is T)
|
||||
yield return (T)(object)this;
|
||||
|
||||
if (NextActivity != null)
|
||||
foreach (var a in NextActivity.ActivitiesImplementing<T>())
|
||||
yield return a;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ActivityExts
|
||||
|
||||
@@ -350,6 +350,8 @@ namespace OpenRA.Traits
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1302:InterfaceNamesMustBeginWithI", Justification = "Not a real interface, but more like a tag.")]
|
||||
public interface Requires<T> where T : class, ITraitInfoInterface { }
|
||||
|
||||
public interface IActivityInterface { }
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
public interface INotifySelected { void Selected(Actor self); }
|
||||
[RequireExplicitImplementation]
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -18,6 +19,18 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public enum UnitStance { HoldFire, ReturnFire, Defend, AttackAnything }
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
public interface IActivityNotifyStanceChanged : IActivityInterface
|
||||
{
|
||||
void StanceChanged(Actor self, AutoTarget autoTarget, UnitStance oldStance, UnitStance newStance);
|
||||
}
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
public interface INotifyStanceChanged
|
||||
{
|
||||
void StanceChanged(Actor self, AutoTarget autoTarget, UnitStance oldStance, UnitStance newStance);
|
||||
}
|
||||
|
||||
[Desc("The actor will automatically engage the enemy when it is in range.")]
|
||||
public class AutoTargetInfo : ConditionalTraitInfo, Requires<AttackBaseInfo>, IEditorActorOptions
|
||||
{
|
||||
@@ -126,6 +139,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
UnitStance stance;
|
||||
ConditionManager conditionManager;
|
||||
IDisableAutoTarget[] disableAutoTarget;
|
||||
INotifyStanceChanged[] notifyStanceChanged;
|
||||
IEnumerable<AutoTargetPriorityInfo> activeTargetPriorities;
|
||||
int conditionToken = ConditionManager.InvalidConditionToken;
|
||||
|
||||
@@ -134,8 +148,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (stance == value)
|
||||
return;
|
||||
|
||||
var oldStance = stance;
|
||||
stance = value;
|
||||
ApplyStanceCondition(self);
|
||||
|
||||
foreach (var nsc in notifyStanceChanged)
|
||||
nsc.StanceChanged(self, this, oldStance, stance);
|
||||
|
||||
if (self.CurrentActivity != null)
|
||||
foreach (var a in self.CurrentActivity.ActivitiesImplementing<IActivityNotifyStanceChanged>())
|
||||
a.StanceChanged(self, this, oldStance, stance);
|
||||
}
|
||||
|
||||
void ApplyStanceCondition(Actor self)
|
||||
@@ -176,6 +198,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||
disableAutoTarget = self.TraitsImplementing<IDisableAutoTarget>().ToArray();
|
||||
notifyStanceChanged = self.TraitsImplementing<INotifyStanceChanged>().ToArray();
|
||||
ApplyStanceCondition(self);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user