Make RevealsShroud and CreatesShroud use stances

Instead of hardcoded (!)IsAlliedWith checks.
This commit is contained in:
reaperrr
2016-10-25 15:56:12 +02:00
parent 6b5e7b8c12
commit cafd50ef43
2 changed files with 24 additions and 6 deletions

View File

@@ -9,21 +9,30 @@
*/ */
#endregion #endregion
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
public class CreatesShroudInfo : AffectsShroudInfo public class CreatesShroudInfo : AffectsShroudInfo
{ {
[Desc("Stance the watching player needs to see the generated shroud.")]
public readonly Stance ValidStances = Stance.Neutral | Stance.Enemy;
public override object Create(ActorInitializer init) { return new CreatesShroud(init.Self, this); } public override object Create(ActorInitializer init) { return new CreatesShroud(init.Self, this); }
} }
public class CreatesShroud : AffectsShroud public class CreatesShroud : AffectsShroud
{ {
readonly CreatesShroudInfo info;
public CreatesShroud(Actor self, CreatesShroudInfo info) public CreatesShroud(Actor self, CreatesShroudInfo info)
: base(self, info) { } : base(self, info) { this.info = info; }
protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv) protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv)
{ {
if (!self.Owner.IsAlliedWith(p)) if (!info.ValidStances.HasStance(p.Stances[self.Owner]))
return;
p.Shroud.AddProjectedShroudGeneration(this, uv); p.Shroud.AddProjectedShroudGeneration(this, uv);
} }

View File

@@ -9,21 +9,30 @@
*/ */
#endregion #endregion
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
public class RevealsShroudInfo : AffectsShroudInfo public class RevealsShroudInfo : AffectsShroudInfo
{ {
[Desc("Stance the watching player needs to see the shroud removed.")]
public readonly Stance ValidStances = Stance.Ally;
public override object Create(ActorInitializer init) { return new RevealsShroud(init.Self, this); } public override object Create(ActorInitializer init) { return new RevealsShroud(init.Self, this); }
} }
public class RevealsShroud : AffectsShroud public class RevealsShroud : AffectsShroud
{ {
readonly RevealsShroudInfo info;
public RevealsShroud(Actor self, RevealsShroudInfo info) public RevealsShroud(Actor self, RevealsShroudInfo info)
: base(self, info) { } : base(self, info) { this.info = info; }
protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv) protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv)
{ {
if (self.Owner.IsAlliedWith(p)) if (!info.ValidStances.HasStance(p.Stances[self.Owner]))
return;
p.Shroud.AddProjectedVisibility(this, uv); p.Shroud.AddProjectedVisibility(this, uv);
} }