implement selectable rules of engagement for AutoTarget
This commit is contained in:
@@ -22,13 +22,15 @@ namespace OpenRA.Mods.RA
|
|||||||
public object Create(ActorInitializer init) { return new AutoTarget(init.self, this); }
|
public object Create(ActorInitializer init) { return new AutoTarget(init.self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum UnitStance { HoldFire, ReturnFire, AttackAnything };
|
||||||
|
|
||||||
public class AutoTarget : INotifyIdle, INotifyDamage, ITick
|
public class AutoTarget : INotifyIdle, INotifyDamage, ITick
|
||||||
{
|
{
|
||||||
readonly AutoTargetInfo Info;
|
readonly AutoTargetInfo Info;
|
||||||
readonly AttackBase attack;
|
readonly AttackBase attack;
|
||||||
|
|
||||||
[Sync]
|
[Sync] int nextScanTime = 0;
|
||||||
int nextScanTime = 0;
|
[Sync] public UnitStance stance = UnitStance.AttackAnything;
|
||||||
|
|
||||||
public AutoTarget(Actor self, AutoTargetInfo info)
|
public AutoTarget(Actor self, AutoTargetInfo info)
|
||||||
{
|
{
|
||||||
@@ -41,6 +43,8 @@ namespace OpenRA.Mods.RA
|
|||||||
if (!self.IsIdle) return;
|
if (!self.IsIdle) return;
|
||||||
if (e.Attacker.Destroyed) 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?
|
// not a lot we can do about things we can't hurt... although maybe we should automatically run away?
|
||||||
var attack = self.Trait<AttackBase>();
|
var attack = self.Trait<AttackBase>();
|
||||||
if (!attack.HasAnyValidWeapons(Target.FromActor(e.Attacker))) return;
|
if (!attack.HasAnyValidWeapons(Target.FromActor(e.Attacker))) return;
|
||||||
@@ -55,6 +59,8 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
public void TickIdle(Actor self)
|
public void TickIdle(Actor self)
|
||||||
{
|
{
|
||||||
|
if (stance < UnitStance.AttackAnything) return;
|
||||||
|
|
||||||
var target = ScanForTarget(self, null);
|
var target = ScanForTarget(self, null);
|
||||||
if (target != null)
|
if (target != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user