Remove the hardcoded cloak reference from activities
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Activities;
|
using OpenRA.Activities;
|
||||||
using OpenRA.Mods.Cnc.Traits;
|
using OpenRA.Mods.Cnc.Traits;
|
||||||
using OpenRA.Mods.Common.Activities;
|
using OpenRA.Mods.Common.Activities;
|
||||||
@@ -21,14 +22,14 @@ namespace OpenRA.Mods.Cnc.Activities
|
|||||||
{
|
{
|
||||||
readonly Actor target;
|
readonly Actor target;
|
||||||
readonly Infiltrates infiltrates;
|
readonly Infiltrates infiltrates;
|
||||||
readonly Cloak cloak;
|
readonly INotifyInfiltration[] notifiers;
|
||||||
|
|
||||||
public Infiltrate(Actor self, Actor target, Infiltrates infiltrate)
|
public Infiltrate(Actor self, Actor target, Infiltrates infiltrate)
|
||||||
: base(self, target, infiltrate.Info.EnterBehaviour)
|
: base(self, target, infiltrate.Info.EnterBehaviour)
|
||||||
{
|
{
|
||||||
this.target = target;
|
this.target = target;
|
||||||
infiltrates = infiltrate;
|
infiltrates = infiltrate;
|
||||||
cloak = self.TraitOrDefault<Cloak>();
|
notifiers = self.TraitsImplementing<INotifyInfiltration>().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnInside(Actor self)
|
protected override void OnInside(Actor self)
|
||||||
@@ -40,8 +41,8 @@ namespace OpenRA.Mods.Cnc.Activities
|
|||||||
if (!infiltrates.Info.ValidStances.HasStance(stance))
|
if (!infiltrates.Info.ValidStances.HasStance(stance))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (cloak != null && cloak.Info.UncloakOn.HasFlag(UncloakType.Infiltrate))
|
foreach (var ini in notifiers)
|
||||||
cloak.Uncloak();
|
ini.Infiltrating(self);
|
||||||
|
|
||||||
foreach (var t in target.TraitsImplementing<INotifyInfiltrated>())
|
foreach (var t in target.TraitsImplementing<INotifyInfiltrated>())
|
||||||
t.Infiltrated(target, self);
|
t.Infiltrated(target, self);
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
readonly int flashesDelay;
|
readonly int flashesDelay;
|
||||||
readonly int flashInterval;
|
readonly int flashInterval;
|
||||||
readonly int flashDuration;
|
readonly int flashDuration;
|
||||||
|
readonly INotifyDemolition[] notifiers;
|
||||||
readonly Cloak cloak;
|
|
||||||
|
|
||||||
public Demolish(Actor self, Actor target, EnterBehaviour enterBehaviour, int delay,
|
public Demolish(Actor self, Actor target, EnterBehaviour enterBehaviour, int delay,
|
||||||
int flashes, int flashesDelay, int flashInterval, int flashDuration)
|
int flashes, int flashesDelay, int flashInterval, int flashDuration)
|
||||||
@@ -35,12 +34,12 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
this.target = target;
|
this.target = target;
|
||||||
demolishables = target.TraitsImplementing<IDemolishable>().ToArray();
|
demolishables = target.TraitsImplementing<IDemolishable>().ToArray();
|
||||||
|
notifiers = self.TraitsImplementing<INotifyDemolition>().ToArray();
|
||||||
this.delay = delay;
|
this.delay = delay;
|
||||||
this.flashes = flashes;
|
this.flashes = flashes;
|
||||||
this.flashesDelay = flashesDelay;
|
this.flashesDelay = flashesDelay;
|
||||||
this.flashInterval = flashInterval;
|
this.flashInterval = flashInterval;
|
||||||
this.flashDuration = flashDuration;
|
this.flashDuration = flashDuration;
|
||||||
cloak = self.TraitOrDefault<Cloak>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool CanReserve(Actor self)
|
protected override bool CanReserve(Actor self)
|
||||||
@@ -55,12 +54,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (target.IsDead)
|
if (target.IsDead)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (cloak != null && cloak.Info.UncloakOn.HasFlag(UncloakType.Demolish))
|
foreach (var ind in notifiers)
|
||||||
cloak.Uncloak();
|
ind.Demolishing(self);
|
||||||
|
|
||||||
var building = target.TraitOrDefault<Building>();
|
|
||||||
if (building != null)
|
|
||||||
building.Lock();
|
|
||||||
|
|
||||||
for (var f = 0; f < flashes; f++)
|
for (var f = 0; f < flashes; f++)
|
||||||
w.Add(new DelayedAction(flashesDelay + f * flashInterval, () =>
|
w.Add(new DelayedAction(flashesDelay + f * flashInterval, () =>
|
||||||
|
|||||||
@@ -23,14 +23,14 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly Cargo cargo;
|
readonly Cargo cargo;
|
||||||
readonly Cloak[] cloaks;
|
readonly INotifyUnload[] notifiers;
|
||||||
readonly bool unloadAll;
|
readonly bool unloadAll;
|
||||||
|
|
||||||
public UnloadCargo(Actor self, bool unloadAll)
|
public UnloadCargo(Actor self, bool unloadAll)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
cargo = self.Trait<Cargo>();
|
cargo = self.Trait<Cargo>();
|
||||||
cloaks = self.TraitsImplementing<Cloak>().ToArray();
|
notifiers = self.TraitsImplementing<INotifyUnload>().ToArray();
|
||||||
this.unloadAll = unloadAll;
|
this.unloadAll = unloadAll;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,9 +60,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (IsCanceled || cargo.IsEmpty(self))
|
if (IsCanceled || cargo.IsEmpty(self))
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
foreach (var cloak in cloaks)
|
foreach (var inu in notifiers)
|
||||||
if (cloak.Info.UncloakOn.HasFlag(UncloakType.Unload))
|
inu.Unloading(self);
|
||||||
cloak.Uncloak();
|
|
||||||
|
|
||||||
var actor = cargo.Peek(self);
|
var actor = cargo.Peek(self);
|
||||||
var spawn = self.CenterPosition;
|
var spawn = self.CenterPosition;
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class Building : IOccupySpace, ITargetableCells, INotifySold, INotifyTransform, ISync, INotifyCreated,
|
public class Building : IOccupySpace, ITargetableCells, INotifySold, INotifyTransform, ISync, INotifyCreated,
|
||||||
INotifyAddedToWorld, INotifyRemovedFromWorld
|
INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyDemolition
|
||||||
{
|
{
|
||||||
public readonly bool SkipMakeAnimation;
|
public readonly bool SkipMakeAnimation;
|
||||||
public readonly BuildingInfo Info;
|
public readonly BuildingInfo Info;
|
||||||
@@ -331,6 +331,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
notify.BuildingComplete(self);
|
notify.BuildingComplete(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void INotifyDemolition.Demolishing(Actor self)
|
||||||
|
{
|
||||||
|
Lock();
|
||||||
|
}
|
||||||
|
|
||||||
void INotifySold.Selling(Actor self)
|
void INotifySold.Selling(Actor self)
|
||||||
{
|
{
|
||||||
if (Info.RemoveSmudgesOnSell)
|
if (Info.RemoveSmudgesOnSell)
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public override object Create(ActorInitializer init) { return new Cloak(this); }
|
public override object Create(ActorInitializer init) { return new Cloak(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Cloak : ConditionalTrait<CloakInfo>, IRenderModifier, INotifyDamage,
|
public class Cloak : ConditionalTrait<CloakInfo>, IRenderModifier, INotifyDamage, INotifyUnload, INotifyDemolition, INotifyInfiltration,
|
||||||
INotifyAttack, ITick, IVisibilityModifier, IRadarColorModifier, INotifyCreated, INotifyHarvesterAction
|
INotifyAttack, ITick, IVisibilityModifier, IRadarColorModifier, INotifyCreated, INotifyHarvesterAction
|
||||||
{
|
{
|
||||||
[Sync] int remainingTime;
|
[Sync] int remainingTime;
|
||||||
bool isDocking;
|
bool isDocking;
|
||||||
@@ -212,5 +212,23 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
isDocking = false;
|
isDocking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void INotifyUnload.Unloading(Actor self)
|
||||||
|
{
|
||||||
|
if (Info.UncloakOn.HasFlag(UncloakType.Unload))
|
||||||
|
Uncloak();
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyDemolition.Demolishing(Actor self)
|
||||||
|
{
|
||||||
|
if (Info.UncloakOn.HasFlag(UncloakType.Demolish))
|
||||||
|
Uncloak();
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyInfiltration.Infiltrating(Actor self)
|
||||||
|
{
|
||||||
|
if (Info.UncloakOn.HasFlag(UncloakType.Infiltrate))
|
||||||
|
Uncloak();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,6 +148,24 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
void Undocked();
|
void Undocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RequireExplicitImplementation]
|
||||||
|
public interface INotifyUnload
|
||||||
|
{
|
||||||
|
void Unloading(Actor self);
|
||||||
|
}
|
||||||
|
|
||||||
|
[RequireExplicitImplementation]
|
||||||
|
public interface INotifyDemolition
|
||||||
|
{
|
||||||
|
void Demolishing(Actor self);
|
||||||
|
}
|
||||||
|
|
||||||
|
[RequireExplicitImplementation]
|
||||||
|
public interface INotifyInfiltration
|
||||||
|
{
|
||||||
|
void Infiltrating(Actor self);
|
||||||
|
}
|
||||||
|
|
||||||
public interface ITechTreePrerequisiteInfo : ITraitInfo { }
|
public interface ITechTreePrerequisiteInfo : ITraitInfo { }
|
||||||
public interface ITechTreePrerequisite
|
public interface ITechTreePrerequisite
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user