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,22 +9,31 @@
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
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 class CreatesShroud : AffectsShroud
{
readonly 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)
{
if (!self.Owner.IsAlliedWith(p))
p.Shroud.AddProjectedShroudGeneration(this, uv);
if (!info.ValidStances.HasStance(p.Stances[self.Owner]))
return;
p.Shroud.AddProjectedShroudGeneration(this, uv);
}
protected override void RemoveCellsFromPlayerShroud(Actor self, Player p) { p.Shroud.RemoveShroudGeneration(this); }

View File

@@ -9,22 +9,31 @@
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
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 class RevealsShroud : AffectsShroud
{
readonly 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)
{
if (self.Owner.IsAlliedWith(p))
p.Shroud.AddProjectedVisibility(this, uv);
if (!info.ValidStances.HasStance(p.Stances[self.Owner]))
return;
p.Shroud.AddProjectedVisibility(this, uv);
}
protected override void RemoveCellsFromPlayerShroud(Actor self, Player p) { p.Shroud.RemoveVisibility(this); }