Allow opportunity fire for aircraft.

This commit is contained in:
tovl
2019-03-31 22:09:43 +02:00
committed by reaperrr
parent f16ff9eaa0
commit 9abf715fd7
19 changed files with 114 additions and 92 deletions

View File

@@ -39,6 +39,17 @@ namespace OpenRA.Mods.Common.Traits
[VoiceReference] public readonly string Voice = "Action";
[Desc("Tolerance for attack angle. Range [0, 128], 128 covers 360 degrees.")]
public readonly int FacingTolerance = 128;
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
base.RulesetLoaded(rules, ai);
if (FacingTolerance < 0 || FacingTolerance > 128)
throw new YamlException("Facing tolerance must be in range of [0, 128], 128 covers 360 degrees.");
}
public override abstract object Create(ActorInitializer init);
}
@@ -101,6 +112,21 @@ namespace OpenRA.Mods.Common.Traits
return () => armaments;
}
public bool TargetInFiringArc(Actor self, Target target, int facingTolerance)
{
if (facing == null)
return true;
var pos = self.CenterPosition;
var targetedPosition = GetTargetPosition(pos, target);
var delta = targetedPosition - pos;
if (delta.HorizontalLengthSquared == 0)
return true;
return Util.FacingWithinTolerance(facing.Facing, delta.Yaw.Facing, facingTolerance);
}
protected virtual bool CanAttack(Actor self, Target target)
{
if (!self.IsInWorld || IsTraitDisabled || IsTraitPaused)