Skip to content

Commit

Permalink
Add logic to reveal cloaked units, when they are only units left.
Browse files Browse the repository at this point in the history
I'm not sure about IPositionable check but that was the easiest way to
get it ignore upgrades, generals powers and player actor.
  • Loading branch information
MustaphaTR committed Sep 5, 2018
1 parent a2e4679 commit 624ea81
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions OpenRA.Mods.Common/Traits/Cloak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public class CloakInfo : ConditionalTraitInfo
[GrantedConditionReference]
[Desc("The condition to grant to self while cloaked.")]
public readonly string CloakedCondition = null;

[Desc("This units uncloaks if only units of the player are cloakable.")]
public readonly bool UncloakWhenAlone = true;

public override object Create(ActorInitializer init) { return new Cloak(this); }
}
Expand Down Expand Up @@ -187,6 +190,9 @@ public bool IsVisible(Actor self, Player viewer)
if (!Cloaked || self.Owner.IsAlliedWith(viewer))
return true;

if ((Info.UncloakWhenAlone && !self.World.Actors.Where(a => a.Owner == self.Owner && a.IsInWorld && a.TraitsImplementing<IPositionable>().Any() && !a.TraitsImplementing<Cloak>().Where(t => !t.IsTraitDisabled).Any()).Any()))
return true;

return self.World.ActorsWithTrait<DetectCloaked>().Any(a => !a.Trait.IsTraitDisabled && a.Actor.Owner.IsAlliedWith(viewer)
&& Info.CloakTypes.Overlaps(a.Trait.Info.CloakTypes)
&& (self.CenterPosition - a.Actor.CenterPosition).LengthSquared <= a.Trait.Info.Range.LengthSquared);
Expand Down

0 comments on commit 624ea81

Please sign in to comment.