Merge pull request #10750 from obrakmann/drop-invalid-target

Fixed not dropping targets that are out of range if the attacker cannot move
This commit is contained in:
reaperrr
2016-02-18 17:02:48 +01:00
2 changed files with 18 additions and 3 deletions

View File

@@ -76,9 +76,13 @@ namespace OpenRA.Mods.Common.Activities
minRange = armaments.Max(a => a.Weapon.MinRange);
maxRange = armaments.Min(a => a.MaxRange());
// Try to move within range
if (move != null && (!Target.IsInRange(self.CenterPosition, maxRange) || Target.IsInRange(self.CenterPosition, minRange)))
if (!Target.IsInRange(self.CenterPosition, maxRange) || Target.IsInRange(self.CenterPosition, minRange))
{
// Try to move within range, drop the target otherwise
if (move == null)
return NextActivity;
return ActivityUtils.SequenceActivities(move.MoveWithinRange(Target, minRange, maxRange), this);
}
var desiredFacing = (Target.CenterPosition - self.CenterPosition).Yaw.Facing;
if (facing.Facing != desiredFacing)

View File

@@ -58,16 +58,20 @@ namespace OpenRA.Mods.Common.Traits
readonly IMove move;
readonly Target target;
readonly bool forceAttack;
readonly bool onRailsHack;
public AttackActivity(Actor self, Target target, bool allowMove, bool forceAttack)
{
attack = self.Trait<AttackFollow>();
move = allowMove ? self.TraitOrDefault<IMove>() : null;
// HACK: Mobile.OnRails is horrible
// HACK: Mobile.OnRails is horrible. Blergh.
var mobile = move as Mobile;
if (mobile != null && mobile.Info.OnRails)
{
move = null;
onRailsHack = true;
}
this.target = target;
this.forceAttack = forceAttack;
@@ -96,8 +100,15 @@ namespace OpenRA.Mods.Common.Traits
if (move != null)
return ActivityUtils.SequenceActivities(move.MoveFollow(self, target, weapon.Weapon.MinRange, maxRange), this);
if (!onRailsHack &&
target.IsInRange(self.CenterPosition, weapon.MaxRange()) &&
!target.IsInRange(self.CenterPosition, weapon.Weapon.MinRange))
return this;
}
if (!onRailsHack)
attack.Target = Target.Invalid;
return NextActivity;
}
}