From 20c4db914cf3345b30f3cdc8e7ebd7e734862751 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 10 Oct 2011 18:42:18 +1300 Subject: [PATCH] implement selectable rules of engagement for AutoTarget --- OpenRA.Mods.RA/AutoTarget.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.RA/AutoTarget.cs b/OpenRA.Mods.RA/AutoTarget.cs index 127742bf83..b09d09c28a 100644 --- a/OpenRA.Mods.RA/AutoTarget.cs +++ b/OpenRA.Mods.RA/AutoTarget.cs @@ -22,13 +22,15 @@ namespace OpenRA.Mods.RA public object Create(ActorInitializer init) { return new AutoTarget(init.self, this); } } + public enum UnitStance { HoldFire, ReturnFire, AttackAnything }; + public class AutoTarget : INotifyIdle, INotifyDamage, ITick { readonly AutoTargetInfo Info; readonly AttackBase attack; - [Sync] - int nextScanTime = 0; + [Sync] int nextScanTime = 0; + [Sync] public UnitStance stance = UnitStance.AttackAnything; public AutoTarget(Actor self, AutoTargetInfo info) { @@ -41,6 +43,8 @@ namespace OpenRA.Mods.RA if (!self.IsIdle) return; if (e.Attacker.Destroyed) return; + if (stance < UnitStance.ReturnFire) return; + // not a lot we can do about things we can't hurt... although maybe we should automatically run away? var attack = self.Trait(); if (!attack.HasAnyValidWeapons(Target.FromActor(e.Attacker))) return; @@ -55,6 +59,8 @@ namespace OpenRA.Mods.RA public void TickIdle(Actor self) { + if (stance < UnitStance.AttackAnything) return; + var target = ScanForTarget(self, null); if (target != null) {