Pass CaptureTypes through the INotifyCapture interface.

Also make it require explicit implementation.
This commit is contained in:
Paul Chote
2018-10-26 18:35:45 +00:00
committed by abcdefg30
parent 4ea3e8382d
commit 7e67ce0139
12 changed files with 23 additions and 15 deletions

View File

@@ -99,7 +99,7 @@ namespace OpenRA.Mods.Common.Activities
actor.ChangeOwnerSync(self.Owner);
foreach (var t in actor.TraitsImplementing<INotifyCapture>())
t.OnCapture(actor, self, oldOwner, self.Owner);
t.OnCapture(actor, self, oldOwner, self.Owner, captures.Info.CaptureTypes);
if (self.Owner.Stances[oldOwner].HasStance(captures.Info.PlayerExperienceStances))
{

View File

@@ -278,7 +278,7 @@ namespace OpenRA.Mods.Common.Scripting
}
}
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner, BitSet<CaptureType> captureTypes)
{
if (world.Disposing)
return;

View File

@@ -16,6 +16,7 @@ using OpenRA.Activities;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Effects;
using OpenRA.Mods.Common.Traits.Render;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -161,7 +162,7 @@ namespace OpenRA.Mods.Common.Traits
playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
}
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner, BitSet<CaptureType> captureTypes)
{
// Steal any docked harv too
if (dockedHarv != null)

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits
captureManager = self.Trait<CaptureManager>();
}
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner, BitSet<CaptureType> captureTypes)
{
if (Info.CancelActivity)
{

View File

@@ -161,7 +161,7 @@ namespace OpenRA.Mods.Common.Traits
return null;
}
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner, BitSet<CaptureType> captureTypes)
{
BeingCaptured = true;
self.World.AddFrameEndTask(w => BeingCaptured = false);

View File

@@ -9,11 +9,10 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Effects;
using OpenRA.Traits;
using OpenRA.Primitives;
namespace OpenRA.Mods.Common.Traits
{
@@ -45,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits
this.info = info;
}
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner, BitSet<CaptureType> captureTypes)
{
if (IsTraitDisabled || !IsValidCaptor(captor))
return;

View File

@@ -10,6 +10,7 @@
#endregion
using System.Collections.Generic;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -18,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits
public class ProximityCaptorInfo : TraitInfo<ProximityCaptor>
{
[FieldLoader.Require]
public readonly HashSet<string> Types = new HashSet<string>();
public readonly BitSet<CaptureType> Types = default(BitSet<CaptureType>);
}
public class ProximityCaptor { }

View File

@@ -15,6 +15,7 @@ using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Effects;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -26,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly WDist Range = WDist.FromCells(5);
[Desc("Allowed ProximityCaptor actors to capture this actor.")]
public readonly HashSet<string> CaptorTypes = new HashSet<string> { "Vehicle", "Tank", "Infantry" };
public readonly BitSet<CaptureType> CaptorTypes = new BitSet<CaptureType>("Vehicle", "Tank", "Infantry");
[Desc("If set, the capturing process stops immediately after another player comes into Range.")]
public readonly bool MustBeClear = false;
@@ -182,8 +183,9 @@ namespace OpenRA.Mods.Common.Traits
if (self.Owner == self.World.LocalPlayer)
w.Add(new FlashTarget(self));
var pc = captor.Info.TraitInfoOrDefault<ProximityCaptorInfo>();
foreach (var t in self.TraitsImplementing<INotifyCapture>())
t.OnCapture(self, captor, previousOwner, captor.Owner);
t.OnCapture(self, captor, previousOwner, captor.Owner, pc.Types);
});
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Sound
@@ -40,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits.Sound
this.info = info;
}
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner, BitSet<CaptureType> captureTypes)
{
var faction = info.NewOwnerVoice ? newOwner.Faction.InternalName : oldOwner.Faction.InternalName;
Game.Sound.PlayNotification(self.World.Map.Rules, newOwner, "Speech", info.Notification, faction);

View File

@@ -11,6 +11,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -50,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
player = newOwner.PlayerActor.Trait<PlayerResources>();
}
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner, BitSet<CaptureType> captureTypes)
{
var resources = Stored;
oldOwner.PlayerActor.Trait<PlayerResources>().TakeResources(resources);

View File

@@ -12,6 +12,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -40,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
}
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner, BitSet<CaptureType> captureTypes)
{
if (!IsValidCaptor(captor))
return;

View File

@@ -138,7 +138,9 @@ namespace OpenRA.Mods.Common.Traits
public interface INotifyDelivery { void IncomingDelivery(Actor self); void Delivered(Actor self); }
public interface INotifyDocking { void Docked(Actor self, Actor harvester); void Undocked(Actor self, Actor harvester); }
public interface INotifyParachute { void OnParachute(Actor self); void OnLanded(Actor self, Actor ignore); }
public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); }
[RequireExplicitImplementation]
public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner, BitSet<CaptureType> captureTypes); }
public interface INotifyDiscovered { void OnDiscovered(Actor self, Player discoverer, bool playNotification); }
public interface IRenderActorPreviewInfo : ITraitInfo { IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init); }
public interface ICruiseAltitudeInfo : ITraitInfo { WDist GetCruiseAltitude(); }