diff --git a/OpenRa.Game/Traits/AttackTurreted.cs b/OpenRa.Game/Traits/AttackTurreted.cs index b3aa485a3c..5e2118739a 100755 --- a/OpenRa.Game/Traits/AttackTurreted.cs +++ b/OpenRa.Game/Traits/AttackTurreted.cs @@ -82,18 +82,27 @@ namespace OpenRa.Game.Traits public readonly Actor Attacker; public readonly Actor Target; + const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */ + public AttackOrder( Actor attacker, Actor target ) { this.Attacker = attacker; this.Target = target; } + public override void Apply() { var mobile = Attacker.traits.GetOrDefault(); if (mobile != null) { + var weapon = Attacker.unitInfo.Primary ?? Attacker.unitInfo.Secondary; + /* todo: choose the appropriate weapon, when only one works against this target */ + var range = Rules.WeaponInfo[weapon].Range; + mobile.Cancel(Attacker); - mobile.QueueActivity(new Mobile.MoveTo(Target, 3)); /* todo: get range properly */ + mobile.QueueActivity( + new Mobile.MoveTo(Target, + Math.Max(0, (int)range - RangeTolerance))); } Attacker.traits.Get().target = Target;