Track visibility modifiers on FrozenActors.

This commit is contained in:
Paul Chote
2018-12-10 20:44:03 +00:00
committed by Oliver Brakmann
parent 5f79c31a57
commit 224377f078
5 changed files with 42 additions and 21 deletions

View File

@@ -46,7 +46,17 @@ namespace OpenRA.Traits
public DamageState DamageState { get; private set; }
readonly IHealth health;
// The Visible flag is tied directly to the actor visibility under the fog.
// If Visible is true, the actor is made invisible (via FrozenUnderFog/IDefaultVisibility)
// and this FrozenActor is rendered instead.
// The Hidden flag covers the edge case that occurs when the backing actor was last "seen"
// to be cloaked or otherwise not CanBeViewedByPlayer()ed. Setting Visible to true when
// the actor is hidden under the fog would leak the actors position via the tooltips and
// AutoTargetability, and keeping Visible as false would cause the actor to be rendered
// under the fog.
public bool Visible = true;
public bool Hidden = false;
public bool Shrouded { get; private set; }
public bool NeedRenderables { get; set; }
public IRenderable[] Renderables = NoRenderables;
@@ -101,6 +111,7 @@ namespace OpenRA.Traits
{
Owner = actor.Owner;
TargetTypes = actor.GetEnabledTargetTypes();
Hidden = !actor.CanBeViewedByPlayer(viewer);
if (health != null)
{
@@ -145,6 +156,11 @@ namespace OpenRA.Traits
NeedRenderables |= Visible && !wasVisible;
}
public void Invalidate()
{
Owner = null;
}
public void Flash()
{
flashTicks = 5;

View File

@@ -80,13 +80,21 @@ namespace OpenRA.Traits
public bool IsValidFor(Actor targeter)
{
if (targeter == null || Type == TargetType.Invalid)
if (targeter == null)
return false;
if (actor != null && !actor.IsTargetableBy(targeter))
return false;
return true;
switch (Type)
{
case TargetType.Actor:
return actor.IsTargetableBy(targeter);
case TargetType.FrozenActor:
return frozen.IsValid && frozen.Visible && !frozen.Hidden;
case TargetType.Invalid:
return false;
default:
case TargetType.Terrain:
return true;
}
}
// Currently all or nothing.