From 01a3fc5c62108b08cf0feeb681a6c6ab0b2e69cf Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 27 Oct 2009 00:32:11 +1300 Subject: [PATCH] move to range actually uses weapon's range now --- OpenRa.Game/Traits/AttackTurreted.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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;