make repath much less aggressive while attacking, to fix perf

This commit is contained in:
Chris Forbes
2010-12-27 19:17:02 +13:00
parent 59fdbe8725
commit 888fe35f08
2 changed files with 26 additions and 8 deletions

View File

@@ -23,6 +23,11 @@ namespace OpenRA.Mods.RA.Activities
int Range; int Range;
bool AllowMovement; bool AllowMovement;
int nextPathTime;
const int delayBetweenPathingAttempts = 20;
const int delaySpread = 5;
public Attack(Target target, int range, bool allowMovement) public Attack(Target target, int range, bool allowMovement)
{ {
Target = target; Target = target;
@@ -33,10 +38,7 @@ namespace OpenRA.Mods.RA.Activities
AllowMovement = 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 ) public override IActivity Tick( Actor self )
{ {
@@ -58,7 +60,15 @@ namespace OpenRA.Mods.RA.Activities
return NextActivity; return NextActivity;
if (!Combat.IsInRange(self.CenterLocation, Range, Target)) 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; return (AllowMovement) ? Util.SequenceActivities(self.Trait<Mobile>().MoveWithinRange(Target, Range), this) : NextActivity;
}
var desiredFacing = Util.GetFacing(Target.CenterLocation - self.CenterLocation, 0); var desiredFacing = Util.GetFacing(Target.CenterLocation - self.CenterLocation, 0);
if (facing.Facing != desiredFacing) if (facing.Facing != desiredFacing)

View File

@@ -18,6 +18,10 @@ namespace OpenRA.Mods.RA.Activities
{ {
Target Target; Target Target;
int Range; int Range;
int nextPathTime;
const int delayBetweenPathingAttempts = 20;
const int delaySpread = 5;
public Follow(Target target, int range) public Follow(Target target, int range)
{ {
@@ -33,6 +37,10 @@ namespace OpenRA.Mods.RA.Activities
var inRange = ( Util.CellContaining( Target.CenterLocation ) - self.Location ).LengthSquared < Range * Range; var inRange = ( Util.CellContaining( Target.CenterLocation ) - self.Location ).LengthSquared < Range * Range;
if( inRange ) return this; 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 ); return Util.SequenceActivities( mobile.MoveWithinRange( Target, Range ), this );