Add MinRange plumbing to attack activities.

This commit is contained in:
Paul Chote
2014-01-13 21:43:26 +13:00
parent f5a44f3c41
commit 887a515e14
12 changed files with 25 additions and 26 deletions

View File

@@ -170,7 +170,8 @@ namespace OpenRA.Traits
Activity MoveTo(CPos cell, int nearEnough);
Activity MoveTo(CPos cell, Actor ignoredActor);
Activity MoveWithinRange(Target target, WRange range);
Activity MoveFollow(Actor self, Target target, WRange range);
Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange);
Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange);
Activity MoveIntoWorld(Actor self, CPos cell);
Activity VisualMove(Actor self, WPos fromPos, WPos toPos);
CPos NearestMoveableCell(CPos target);

View File

@@ -25,13 +25,10 @@ namespace OpenRA.Mods.RA.Activities
const int delayBetweenPathingAttempts = 20;
const int delaySpread = 5;
public Attack(Target target, WRange range)
: this(target, range, true) {}
public Attack(Target target, WRange range, bool allowMovement)
public Attack(Actor self, Target target, WRange minRange, WRange maxRange, bool allowMovement)
{
Target = target;
Range = range;
Range = maxRange;
AllowMovement = allowMovement;
}

View File

@@ -17,13 +17,15 @@ namespace OpenRA.Mods.RA.Activities
{
Target target;
Plane plane;
WRange range;
WRange minRange;
WRange maxRange;
public FlyFollow(Actor self, Target target, WRange range)
public FlyFollow(Actor self, Target target, WRange minRange, WRange maxRange)
{
this.target = target;
plane = self.Trait<Plane>();
this.range = range;
this.minRange = minRange;
this.maxRange = maxRange;
}
public override Activity Tick(Actor self)
@@ -31,13 +33,13 @@ namespace OpenRA.Mods.RA.Activities
if (IsCanceled || !target.IsValidFor(self))
return NextActivity;
if (target.IsInRange(self.CenterPosition, range))
if (target.IsInRange(self.CenterPosition, maxRange) && !target.IsInRange(self.CenterPosition, minRange))
{
Fly.FlyToward(self, plane, plane.Facing, plane.Info.CruiseAltitude);
return this;
}
return Util.SequenceActivities(new Fly(self, target, WRange.Zero, range), this);
return Util.SequenceActivities(new Fly(self, target, minRange, maxRange), this);
}
}
}

View File

@@ -22,11 +22,11 @@ namespace OpenRA.Mods.RA.Activities
const int delayBetweenPathingAttempts = 20;
const int delaySpread = 5;
public Follow(Actor self, Target target, WRange range)
public Follow(Actor self, Target target, WRange minRange, WRange maxRange)
{
this.target = target;
move = self.Trait<IMove>();
this.range = range;
this.range = maxRange;
}
public override Activity Tick(Actor self)

View File

@@ -12,11 +12,10 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
/* non-turreted attack */
public class Heal : Attack
{
public Heal(Target target, WRange range, bool allowMovement)
: base(target, range, allowMovement) { }
public Heal(Actor self, Target target, WRange minRange, WRange maxRange, bool allowMovement)
: base(self, target, minRange, maxRange, allowMovement) { }
protected override Activity InnerTick(Actor self, AttackBase attack)
{

View File

@@ -165,7 +165,7 @@ namespace OpenRA.Mods.RA.Air
public Activity MoveTo(CPos cell, Actor ignoredActor) { return new HeliFly(self, Target.FromCell(cell)); }
public Activity MoveWithinRange(Target target, WRange range) { return new HeliFly(self, target, WRange.Zero, range); }
public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange) { return new HeliFly(self, target, minRange, maxRange); }
public Activity MoveFollow(Actor self, Target target, WRange range) { return new Follow(self, target, range); }
public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new Follow(self, target, minRange, maxRange); }
public CPos NearestMoveableCell(CPos cell) { return cell; }
public Activity MoveIntoWorld(Actor self, CPos cell)

View File

@@ -105,7 +105,7 @@ namespace OpenRA.Mods.RA.Air
public Activity MoveTo(CPos cell, Actor ignoredActor) { return Util.SequenceActivities(new Fly(self, Target.FromCell(cell)), new FlyCircle()); }
public Activity MoveWithinRange(Target target, WRange range) { return Util.SequenceActivities(new Fly(self, target, WRange.Zero, range), new FlyCircle()); }
public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange) { return Util.SequenceActivities(new Fly(self, target, minRange, maxRange), new FlyCircle()); }
public Activity MoveFollow(Actor self, Target target, WRange range) { return new FlyFollow(self, target, range); }
public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new FlyFollow(self, target, minRange, maxRange); }
public CPos NearestMoveableCell(CPos cell) { return cell; }
public Activity MoveIntoWorld(Actor self, CPos cell) { return new Fly(self, Target.FromCell(cell)); }

View File

@@ -80,17 +80,16 @@ namespace OpenRA.Mods.RA
if (self.IsDisabled())
return this;
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */
var weapon = attack.ChooseArmamentForTarget(target);
if (weapon != null)
{
var range = WRange.FromCells(Math.Max(0, weapon.Weapon.Range.Range / 1024 - RangeTolerance));
// Try and sit at least one cell closer than the max range to give some leeway if the target stars moving.
var maxRange = new WRange(Math.Max(weapon.Weapon.MinRange.Range, weapon.Weapon.Range.Range - 1024));
attack.Target = target;
if (move != null)
return Util.SequenceActivities(move.MoveFollow(self, target, range), this);
return Util.SequenceActivities(move.MoveFollow(self, target, weapon.Weapon.MinRange, maxRange), this);
}
return NextActivity;

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA
if (a == null)
return null;
return new Activities.Attack(newTarget, a.Weapon.Range, allowMove);
return new Activities.Attack(self, newTarget, a.Weapon.MinRange, a.Weapon.Range, allowMove);
}
}
}

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA
if (a == null)
return null;
return new Activities.Heal(newTarget, a.Weapon.Range, allowMove);
return new Activities.Heal(self, newTarget, a.Weapon.MinRange, a.Weapon.Range, allowMove);
}
}
}

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA
self.SetTargetLine(target, Color.Yellow);
var range = WRange.FromCells(target.Actor.Info.Traits.Get<GuardableInfo>().Range);
self.QueueActivity(false, new AttackMove.AttackMoveActivity(self, self.Trait<IMove>().MoveFollow(self, target, range)));
self.QueueActivity(false, new AttackMove.AttackMoveActivity(self, self.Trait<IMove>().MoveFollow(self, target, WRange.Zero, range)));
}
public string VoicePhraseForOrder(Actor self, Order order)

View File

@@ -592,7 +592,8 @@ namespace OpenRA.Mods.RA.Move
public Activity MoveTo(CPos cell, int nearEnough) { return new Move(cell, nearEnough); }
public Activity MoveTo(CPos cell, Actor ignoredActor) { return new Move(cell, ignoredActor); }
public Activity MoveWithinRange(Target target, WRange range) { return new Move(target, range); }
public Activity MoveFollow(Actor self, Target target, WRange range) { return new Follow(self, target, range); }
public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange) { return new Move(target, maxRange); }
public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new Follow(self, target, minRange, maxRange); }
public Activity MoveTo(Func<List<CPos>> pathFunc) { return new Move(pathFunc); }
public void OnNotifyBlockingMove(Actor self, Actor blocking)