Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement DetectCloakedMultiplier #16708

Merged
merged 1 commit into from Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Cloak.cs
Expand Up @@ -197,9 +197,9 @@ public bool IsVisible(Actor self, Player viewer)
if (!Cloaked || self.Owner.IsAlliedWith(viewer))
return true;

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

Color IRadarColorModifier.RadarColorOverride(Actor self, Color color)
Expand Down
24 changes: 23 additions & 1 deletion OpenRA.Mods.Common/Traits/DetectCloaked.cs
Expand Up @@ -9,7 +9,9 @@
*/
#endregion

using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;

namespace OpenRA.Mods.Common.Traits
{
Expand All @@ -24,9 +26,29 @@ public class DetectCloakedInfo : ConditionalTraitInfo
public override object Create(ActorInitializer init) { return new DetectCloaked(this); }
}

public class DetectCloaked : ConditionalTrait<DetectCloakedInfo>
public class DetectCloaked : ConditionalTrait<DetectCloakedInfo>, INotifyCreated
{
IDetectCloakedModifier[] rangeModifiers;

public DetectCloaked(DetectCloakedInfo info)
: base(info) { }

void INotifyCreated.Created(Actor self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this explicitly override ConditionalTrait.INotifyCreated.Created and should have been a protected override Created method starting with base.Created with no INotifyCreated interface implementation within this file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.
Should have been

		protected override void Created(Actor self)
		{
			rangeModifiers = self.TraitsImplementing<IDetectCloakedModifier>().ToArray();

			base.Created(self);
		}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a problem for AutoTarget, PrimaryBuilding, GrantConditionOnDeploy, Explodes, KillsSelf, ReloadAmmoPool, ActorSpawnManager, Chronoshiftable, ResourcePurifier.

I am working on a lint check that will prevent this from happening again in the future.

{
rangeModifiers = self.TraitsImplementing<IDetectCloakedModifier>().ToArray();
}

public WDist Range
{
get
{
if (IsTraitDisabled)
return WDist.Zero;

var detectCloakedModifier = rangeModifiers.Select(x => x.GetDetectCloakedModifier());
var range = Util.ApplyPercentageModifiers(Info.Range.Length, detectCloakedModifier);
return new WDist(range);
}
}
}
}
34 changes: 34 additions & 0 deletions OpenRA.Mods.Common/Traits/Multipliers/DetectCloakedMultiplier.cs
@@ -0,0 +1,34 @@
#region Copyright & License Information
/*
* Copyright 2007-2019 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion

namespace OpenRA.Mods.Common.Traits
{
[Desc("Modifies the cloak detection range of this actor.")]
public class DetectCloakedMultiplierInfo : ConditionalTraitInfo
{
[FieldLoader.Require]
[Desc("Percentage modifier to apply.")]
public readonly int Modifier = 100;

public override object Create(ActorInitializer init) { return new DetectCloakedMultiplier(this); }
}

public class DetectCloakedMultiplier : ConditionalTrait<DetectCloakedMultiplierInfo>, IDetectCloakedModifier
{
public DetectCloakedMultiplier(DetectCloakedMultiplierInfo info)
: base(info) { }

int IDetectCloakedModifier.GetDetectCloakedModifier()
{
return IsTraitDisabled ? 100 : Info.Modifier;
}
}
}
3 changes: 1 addition & 2 deletions OpenRA.Mods.Common/Traits/Render/RenderDetectionCircle.cs
Expand Up @@ -51,8 +51,7 @@ IEnumerable<IRenderable> IRenderAboveShroudWhenSelected.RenderAboveShroud(Actor
yield break;

var range = self.TraitsImplementing<DetectCloaked>()
.Where(a => !a.IsTraitDisabled)
.Select(a => a.Info.Range)
.Select(a => a.Range)
.Append(WDist.Zero).Max();

if (range == WDist.Zero)
Expand Down
3 changes: 3 additions & 0 deletions OpenRA.Mods.Common/TraitsInterfaces.cs
Expand Up @@ -385,6 +385,9 @@ public interface ICreatesShroudModifier { int GetCreatesShroudModifier(); }
[RequireExplicitImplementation]
public interface IRevealsShroudModifier { int GetRevealsShroudModifier(); }

[RequireExplicitImplementation]
public interface IDetectCloakedModifier { int GetDetectCloakedModifier(); }

[RequireExplicitImplementation]
public interface ICustomMovementLayer
{
Expand Down