Skip to content

Commit

Permalink
make repath much less aggressive while attacking, to fix perf
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisforbes committed Dec 27, 2010
1 parent 59fdbe8 commit 888fe35
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
24 changes: 17 additions & 7 deletions OpenRA.Mods.RA/Activities/Attack.cs
Expand Up @@ -23,6 +23,11 @@ public class Attack : CancelableActivity
int Range;
bool AllowMovement;

int nextPathTime;

const int delayBetweenPathingAttempts = 20;
const int delaySpread = 5;

public Attack(Target target, int range, bool allowMovement)
{
Target = target;
Expand All @@ -33,10 +38,7 @@ public Attack(Target target, int range, bool allowMovement)
AllowMovement = allowMovement;
}

public Attack(Target target, int range) : this(target, range, true)
{

}
public Attack(Target target, int range) : this(target, range, true) {}

public override IActivity Tick( Actor self )
{
Expand All @@ -56,9 +58,17 @@ protected virtual IActivity InnerTick( Actor self, AttackBase attack )

if (targetable != null && !targetable.TargetableBy(Target.Actor, self))
return NextActivity;

if (!Combat.IsInRange(self.CenterLocation, Range, Target))
return (AllowMovement) ? Util.SequenceActivities(self.Trait<Mobile>().MoveWithinRange(Target, Range), this) : NextActivity;

if (!Combat.IsInRange(self.CenterLocation, Range, Target))
{
if (--nextPathTime > 0)
return this;

nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread,
delayBetweenPathingAttempts + delaySpread);

return (AllowMovement) ? Util.SequenceActivities(self.Trait<Mobile>().MoveWithinRange(Target, Range), this) : NextActivity;
}

var desiredFacing = Util.GetFacing(Target.CenterLocation - self.CenterLocation, 0);
if (facing.Facing != desiredFacing)
Expand Down
10 changes: 9 additions & 1 deletion OpenRA.Mods.RA/Activities/Follow.cs
Expand Up @@ -18,6 +18,10 @@ public class Follow : CancelableActivity
{
Target Target;
int Range;
int nextPathTime;

const int delayBetweenPathingAttempts = 20;
const int delaySpread = 5;

public Follow(Target target, int range)
{
Expand All @@ -33,8 +37,12 @@ public override IActivity Tick( Actor self )
var inRange = ( Util.CellContaining( Target.CenterLocation ) - self.Location ).LengthSquared < Range * Range;

if( inRange ) return this;
if (--nextPathTime > 0) return this;

nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread,
delayBetweenPathingAttempts + delaySpread);

var mobile = self.Trait<Mobile>();
var mobile = self.Trait<Mobile>();
return Util.SequenceActivities( mobile.MoveWithinRange( Target, Range ), this );
}
}
Expand Down

0 comments on commit 888fe35

Please sign in to comment.