From 89025a3042b8e0e64c7e5d7da3165cc0aabbe745 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 25 Apr 2012 21:05:49 +1200 Subject: [PATCH] make attackmove on spawn work properly for things that cant attackmove --- OpenRA.Mods.RA/AttackMove.cs | 14 +++++++++----- OpenRA.Mods.RA/Production.cs | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/OpenRA.Mods.RA/AttackMove.cs b/OpenRA.Mods.RA/AttackMove.cs index 7b959bac35..22feb397a7 100644 --- a/OpenRA.Mods.RA/AttackMove.cs +++ b/OpenRA.Mods.RA/AttackMove.cs @@ -42,11 +42,10 @@ namespace OpenRA.Mods.RA return null; } - void Activate(Actor self) { self.CancelActivity(); - self.QueueActivity(new AttackMoveActivity(mobile.MoveTo(TargetLocation.Value, 1))); + self.QueueActivity(new AttackMoveActivity(self, mobile.MoveTo(TargetLocation.Value, 1))); self.SetTargetLine(Target.FromCell(TargetLocation.Value), Color.Red); } @@ -75,16 +74,21 @@ namespace OpenRA.Mods.RA { Activity inner; int scanTicks; + AutoTarget autoTarget; const int ScanInterval = 7; - public AttackMoveActivity( Activity inner ) { this.inner = inner; } + public AttackMoveActivity( Actor self, Activity inner ) + { + this.inner = inner; + this.autoTarget = self.TraitOrDefault(); + } public override Activity Tick( Actor self ) { - if (--scanTicks <= 0) + if (autoTarget != null && --scanTicks <= 0) { - self.Trait().ScanAndAttack(self); + autoTarget.ScanAndAttack(self); scanTicks = ScanInterval; } diff --git a/OpenRA.Mods.RA/Production.cs b/OpenRA.Mods.RA/Production.cs index fa97de499f..443dcf02a9 100755 --- a/OpenRA.Mods.RA/Production.cs +++ b/OpenRA.Mods.RA/Production.cs @@ -87,7 +87,8 @@ namespace OpenRA.Mods.RA var mobile = newUnit.TraitOrDefault(); if (mobile != null) { - newUnit.QueueActivity(new AttackMove.AttackMoveActivity(mobile.MoveTo(rp.rallyPoint, 1))); + newUnit.QueueActivity(new AttackMove.AttackMoveActivity( + newUnit, mobile.MoveTo(rp.rallyPoint, 1))); return rp.rallyPoint; }