AttackFrontal's FacingTolerance is now in effect

This commit is contained in:
forcecore
2017-06-20 10:04:29 -05:00
committed by abcdefg30
parent d949e17b88
commit d1328212c6
3 changed files with 24 additions and 9 deletions

View File

@@ -18,7 +18,13 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Unit got to face the target")]
public class AttackFrontalInfo : AttackBaseInfo, Requires<IFacingInfo>
{
public readonly int FacingTolerance = 1;
public readonly int FacingTolerance = 0;
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
if (FacingTolerance < 0 || FacingTolerance > 128)
throw new YamlException("Facing tolerance must be in range of [0, 128], 128 covers 360 degrees.");
}
public override object Create(ActorInitializer init) { return new AttackFrontal(init.Self, this); }
}
@@ -38,21 +44,19 @@ namespace OpenRA.Mods.Common.Traits
if (!base.CanAttack(self, target))
return false;
var f = facing.Facing;
var pos = self.CenterPosition;
var targetedPosition = GetTargetPosition(pos, target);
var delta = targetedPosition - pos;
var facingToTarget = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : f;
if (Math.Abs(facingToTarget - f) % 256 > info.FacingTolerance)
return false;
if (delta.HorizontalLengthSquared == 0)
return true;
return true;
return Util.FacingWithinTolerance(facing.Facing, delta.Yaw.Facing, info.FacingTolerance);
}
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack)
{
return new Activities.Attack(self, newTarget, allowMove, forceAttack);
return new Activities.Attack(self, newTarget, allowMove, forceAttack, info.FacingTolerance);
}
}
}