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:
@@ -76,9 +76,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
minRange = armaments.Max(a => a.Weapon.MinRange);
|
minRange = armaments.Max(a => a.Weapon.MinRange);
|
||||||
maxRange = armaments.Min(a => a.MaxRange());
|
maxRange = armaments.Min(a => a.MaxRange());
|
||||||
|
|
||||||
// Try to move within range
|
if (!Target.IsInRange(self.CenterPosition, maxRange) || Target.IsInRange(self.CenterPosition, minRange))
|
||||||
if (move != null && (!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);
|
return ActivityUtils.SequenceActivities(move.MoveWithinRange(Target, minRange, maxRange), this);
|
||||||
|
}
|
||||||
|
|
||||||
var desiredFacing = (Target.CenterPosition - self.CenterPosition).Yaw.Facing;
|
var desiredFacing = (Target.CenterPosition - self.CenterPosition).Yaw.Facing;
|
||||||
if (facing.Facing != desiredFacing)
|
if (facing.Facing != desiredFacing)
|
||||||
|
|||||||
@@ -58,16 +58,20 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
readonly IMove move;
|
readonly IMove move;
|
||||||
readonly Target target;
|
readonly Target target;
|
||||||
readonly bool forceAttack;
|
readonly bool forceAttack;
|
||||||
|
readonly bool onRailsHack;
|
||||||
|
|
||||||
public AttackActivity(Actor self, Target target, bool allowMove, bool forceAttack)
|
public AttackActivity(Actor self, Target target, bool allowMove, bool forceAttack)
|
||||||
{
|
{
|
||||||
attack = self.Trait<AttackFollow>();
|
attack = self.Trait<AttackFollow>();
|
||||||
move = allowMove ? self.TraitOrDefault<IMove>() : null;
|
move = allowMove ? self.TraitOrDefault<IMove>() : null;
|
||||||
|
|
||||||
// HACK: Mobile.OnRails is horrible
|
// HACK: Mobile.OnRails is horrible. Blergh.
|
||||||
var mobile = move as Mobile;
|
var mobile = move as Mobile;
|
||||||
if (mobile != null && mobile.Info.OnRails)
|
if (mobile != null && mobile.Info.OnRails)
|
||||||
|
{
|
||||||
move = null;
|
move = null;
|
||||||
|
onRailsHack = true;
|
||||||
|
}
|
||||||
|
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.forceAttack = forceAttack;
|
this.forceAttack = forceAttack;
|
||||||
@@ -96,8 +100,15 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
if (move != null)
|
if (move != null)
|
||||||
return ActivityUtils.SequenceActivities(move.MoveFollow(self, target, weapon.Weapon.MinRange, maxRange), this);
|
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;
|
return NextActivity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user