Add generation counting to Actor and Target

This allows us to invalidate targets based on arbitrary conditions,
just by bumping the actor's generation number.

The next patches will use this.
This commit is contained in:
Chris Forbes
2013-06-13 09:38:07 +12:00
parent a9b6a94ade
commit 5bc47f4834
2 changed files with 5 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ namespace OpenRA.Traits
Player owner;
PPos pos;
bool valid;
int generation;
public static Target FromActor(Actor a)
{
@@ -25,7 +26,8 @@ namespace OpenRA.Traits
{
actor = a,
valid = (a != null),
owner = (a != null) ? a.Owner : null
owner = (a != null) ? a.Owner : null,
generation = a.Generation,
};
}
public static Target FromPos(PPos p) { return new Target { pos = p, valid = true }; }
@@ -39,7 +41,7 @@ namespace OpenRA.Traits
public static readonly Target None = new Target();
public bool IsValid { get { return valid && (actor == null || (actor.IsInWorld && !actor.IsDead() && actor.Owner == owner)); } }
public bool IsValid { get { return valid && (actor == null || (actor.IsInWorld && !actor.IsDead() && actor.Owner == owner && actor.Generation == generation)); } }
public PPos PxPosition { get { return IsActor ? actor.Trait<IHasLocation>().PxPosition : pos; } }
public PPos CenterLocation { get { return PxPosition; } }