Unacquire invalid AI targets.
This commit is contained in:
@@ -38,11 +38,14 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public static Target FromActor(Actor a)
|
public static Target FromActor(Actor a)
|
||||||
{
|
{
|
||||||
|
if (a == null)
|
||||||
|
return Target.Invalid;
|
||||||
|
|
||||||
return new Target
|
return new Target
|
||||||
{
|
{
|
||||||
actor = a,
|
actor = a,
|
||||||
targetable = a != null ? a.TraitOrDefault<ITargetable>() : null,
|
targetable = a.TraitOrDefault<ITargetable>(),
|
||||||
type = a != null ? TargetType.Actor : TargetType.Invalid,
|
type = TargetType.Actor,
|
||||||
generation = a.Generation,
|
generation = a.Generation,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -73,7 +76,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public bool IsValidFor(Actor targeter)
|
public bool IsValidFor(Actor targeter)
|
||||||
{
|
{
|
||||||
if (Type == TargetType.Invalid)
|
if (targeter == null || Type == TargetType.Invalid)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (targetable != null && !targetable.TargetableBy(actor, targeter))
|
if (targetable != null && !targetable.TargetableBy(actor, targeter))
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
HackyAI bot;
|
HackyAI bot;
|
||||||
XRandom random;
|
XRandom random;
|
||||||
|
|
||||||
Actor target;
|
Target target;
|
||||||
StateMachine fsm;
|
StateMachine fsm;
|
||||||
|
|
||||||
//fuzzy
|
//fuzzy
|
||||||
@@ -113,7 +113,8 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
this.world = bot.world;
|
this.world = bot.world;
|
||||||
this.random = bot.random;
|
this.random = bot.random;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.target = target;
|
this.target = Traits.Target.FromActor(target);
|
||||||
|
|
||||||
fsm = new StateMachine(this);
|
fsm = new StateMachine(this);
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
@@ -144,14 +145,13 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
|
|
||||||
public Actor Target
|
public Actor Target
|
||||||
{
|
{
|
||||||
get { return target; }
|
get { return target.Actor; }
|
||||||
set { target = value; }
|
set { target = Traits.Target.FromActor(value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TargetIsValid
|
public bool TargetIsValid
|
||||||
{
|
{
|
||||||
get { return (target != null && !target.IsDead() && !target.Destroyed
|
get { return target.IsValidFor(units.FirstOrDefault()) && !target.Actor.HasTrait<Husk>(); }
|
||||||
&& target.IsInWorld && !target.HasTrait<Husk>()); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//**********************************************************************************
|
//**********************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user