Merge pull request #7116 from reaperrr/attackmove-split
Splits AttackMove into trait and activity
This commit is contained in:
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
var destination = rp != null ? rp.Location :
|
var destination = rp != null ? rp.Location :
|
||||||
(hasHost ? self.World.Map.CellContaining(host.CenterPosition) : self.Location);
|
(hasHost ? self.World.Map.CellContaining(host.CenterPosition) : self.Location);
|
||||||
|
|
||||||
return new AttackMove.AttackMoveActivity(self, self.Trait<IMove>().MoveTo(destination, 1));
|
return new AttackMoveActivity(self, self.Trait<IMove>().MoveTo(destination, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
82
OpenRA.Mods.RA/Activities/AttackMoveActivity.cs
Normal file
82
OpenRA.Mods.RA/Activities/AttackMoveActivity.cs
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using OpenRA.Mods.RA.Move;
|
||||||
|
using OpenRA.Mods.RA.Traits;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA.Activities
|
||||||
|
{
|
||||||
|
public class AttackMoveActivity : Activity
|
||||||
|
{
|
||||||
|
const int ScanInterval = 7;
|
||||||
|
|
||||||
|
int scanTicks;
|
||||||
|
bool hasMoved;
|
||||||
|
Activity inner;
|
||||||
|
AutoTarget autoTarget;
|
||||||
|
|
||||||
|
public AttackMoveActivity(Actor self, Activity inner)
|
||||||
|
{
|
||||||
|
this.inner = inner;
|
||||||
|
autoTarget = self.TraitOrDefault<AutoTarget>();
|
||||||
|
hasMoved = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Activity Tick(Actor self)
|
||||||
|
{
|
||||||
|
if (autoTarget != null)
|
||||||
|
{
|
||||||
|
// If the actor hasn't moved since the activity was issued
|
||||||
|
if (!hasMoved)
|
||||||
|
autoTarget.ResetScanTimer();
|
||||||
|
|
||||||
|
if (--scanTicks <= 0)
|
||||||
|
{
|
||||||
|
var attackActivity = autoTarget.ScanAndAttack(self);
|
||||||
|
if (attackActivity != null)
|
||||||
|
{
|
||||||
|
if (!hasMoved)
|
||||||
|
return attackActivity;
|
||||||
|
|
||||||
|
self.QueueActivity(false, attackActivity);
|
||||||
|
}
|
||||||
|
scanTicks = ScanInterval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hasMoved = true;
|
||||||
|
|
||||||
|
if (inner == null)
|
||||||
|
return NextActivity;
|
||||||
|
|
||||||
|
inner = Util.RunActivity(self, inner);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Cancel(Actor self)
|
||||||
|
{
|
||||||
|
if (inner != null)
|
||||||
|
inner.Cancel(self);
|
||||||
|
|
||||||
|
base.Cancel(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<Target> GetTargets(Actor self)
|
||||||
|
{
|
||||||
|
if (inner != null)
|
||||||
|
return inner.GetTargets(self);
|
||||||
|
|
||||||
|
return Target.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
return this;
|
return this;
|
||||||
|
|
||||||
return Util.SequenceActivities(
|
return Util.SequenceActivities(
|
||||||
new AttackMove.AttackMoveActivity(self, new Move.Move(self, target.Location, WRange.FromCells(2))),
|
new AttackMoveActivity(self, new Move.Move(self, target.Location, WRange.FromCells(2))),
|
||||||
new Wait(25),
|
new Wait(25),
|
||||||
this);
|
this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using OpenRA.Mods.RA.Traits;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using System.Collections.Generic;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.RA.Activities;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
@@ -36,7 +37,7 @@ namespace OpenRA.Mods.RA
|
|||||||
self.SetTargetLine(target, Color.Yellow);
|
self.SetTargetLine(target, Color.Yellow);
|
||||||
|
|
||||||
var range = WRange.FromCells(target.Actor.Info.Traits.Get<GuardableInfo>().Range);
|
var range = WRange.FromCells(target.Actor.Info.Traits.Get<GuardableInfo>().Range);
|
||||||
self.QueueActivity(false, new AttackMove.AttackMoveActivity(self, self.Trait<IMove>().MoveFollow(self, target, WRange.Zero, range)));
|
self.QueueActivity(false, new AttackMoveActivity(self, self.Trait<IMove>().MoveFollow(self, target, WRange.Zero, range)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public string VoicePhraseForOrder(Actor self, Order order)
|
public string VoicePhraseForOrder(Actor self, Order order)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.RA.Activities;
|
using OpenRA.Mods.RA.Activities;
|
||||||
|
using OpenRA.Mods.RA.Traits;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
|||||||
@@ -99,6 +99,7 @@
|
|||||||
<Compile Include="AI\HackyAI.cs" />
|
<Compile Include="AI\HackyAI.cs" />
|
||||||
<Compile Include="AcceptsSupplies.cs" />
|
<Compile Include="AcceptsSupplies.cs" />
|
||||||
<Compile Include="Activities\Attack.cs" />
|
<Compile Include="Activities\Attack.cs" />
|
||||||
|
<Compile Include="Activities\AttackMoveActivity.cs" />
|
||||||
<Compile Include="Activities\CallFunc.cs" />
|
<Compile Include="Activities\CallFunc.cs" />
|
||||||
<Compile Include="Activities\ExternalCaptureActor.cs" />
|
<Compile Include="Activities\ExternalCaptureActor.cs" />
|
||||||
<Compile Include="Activities\DeliverResources.cs" />
|
<Compile Include="Activities\DeliverResources.cs" />
|
||||||
@@ -141,7 +142,7 @@
|
|||||||
<Compile Include="AI\RushFuzzy.cs" />
|
<Compile Include="AI\RushFuzzy.cs" />
|
||||||
<Compile Include="AI\StateMachine.cs" />
|
<Compile Include="AI\StateMachine.cs" />
|
||||||
<Compile Include="AppearsOnRadar.cs" />
|
<Compile Include="AppearsOnRadar.cs" />
|
||||||
<Compile Include="AttackMove.cs" />
|
<Compile Include="Traits\AttackMove.cs" />
|
||||||
<Compile Include="Attack\AttackBase.cs" />
|
<Compile Include="Attack\AttackBase.cs" />
|
||||||
<Compile Include="Attack\AttackFrontal.cs" />
|
<Compile Include="Attack\AttackFrontal.cs" />
|
||||||
<Compile Include="Attack\AttackLeap.cs" />
|
<Compile Include="Attack\AttackLeap.cs" />
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common;
|
using OpenRA.Mods.Common;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
|
using OpenRA.Mods.RA.Activities;
|
||||||
using OpenRA.Mods.RA.Move;
|
using OpenRA.Mods.RA.Move;
|
||||||
using OpenRA.Mods.RA.Traits;
|
using OpenRA.Mods.RA.Traits;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
@@ -89,7 +90,7 @@ namespace OpenRA.Mods.RA
|
|||||||
if (exitinfo.MoveIntoWorld)
|
if (exitinfo.MoveIntoWorld)
|
||||||
{
|
{
|
||||||
newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit));
|
newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit));
|
||||||
newUnit.QueueActivity(new AttackMove.AttackMoveActivity(
|
newUnit.QueueActivity(new AttackMoveActivity(
|
||||||
newUnit, move.MoveTo(exitLocation, 1)));
|
newUnit, move.MoveTo(exitLocation, 1)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using Eluant;
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.RA.Activities;
|
using OpenRA.Mods.RA.Activities;
|
||||||
|
using OpenRA.Mods.RA.Traits;
|
||||||
using OpenRA.Scripting;
|
using OpenRA.Scripting;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
"close enough to complete the activity.")]
|
"close enough to complete the activity.")]
|
||||||
public void AttackMove(CPos cell, int closeEnough = 0)
|
public void AttackMove(CPos cell, int closeEnough = 0)
|
||||||
{
|
{
|
||||||
self.QueueActivity(new AttackMove.AttackMoveActivity(self, move.MoveTo(cell, closeEnough)));
|
self.QueueActivity(new AttackMoveActivity(self, move.MoveTo(cell, closeEnough)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[ScriptActorPropertyActivity]
|
[ScriptActorPropertyActivity]
|
||||||
@@ -51,7 +52,7 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
{
|
{
|
||||||
foreach (var wpt in waypoints)
|
foreach (var wpt in waypoints)
|
||||||
{
|
{
|
||||||
self.QueueActivity(new AttackMove.AttackMoveActivity(self, move.MoveTo(wpt, 2)));
|
self.QueueActivity(new AttackMoveActivity(self, move.MoveTo(wpt, 2)));
|
||||||
self.QueueActivity(new Wait(wait));
|
self.QueueActivity(new Wait(wait));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,10 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using OpenRA.Mods.RA.Activities;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA.Traits
|
||||||
{
|
{
|
||||||
[Desc("Provides access to the attack-move command, which will make the actor automatically engage viable targets while moving to the destination.")]
|
[Desc("Provides access to the attack-move command, which will make the actor automatically engage viable targets while moving to the destination.")]
|
||||||
class AttackMoveInfo : ITraitInfo
|
class AttackMoveInfo : ITraitInfo
|
||||||
@@ -63,70 +64,5 @@ namespace OpenRA.Mods.RA
|
|||||||
Activate(self);
|
Activate(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AttackMoveActivity : Activity
|
|
||||||
{
|
|
||||||
const int ScanInterval = 7;
|
|
||||||
|
|
||||||
int scanTicks;
|
|
||||||
bool hasMoved;
|
|
||||||
Activity inner;
|
|
||||||
AutoTarget autoTarget;
|
|
||||||
|
|
||||||
public AttackMoveActivity(Actor self, Activity inner)
|
|
||||||
{
|
|
||||||
this.inner = inner;
|
|
||||||
autoTarget = self.TraitOrDefault<AutoTarget>();
|
|
||||||
hasMoved = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
|
||||||
{
|
|
||||||
if (autoTarget != null)
|
|
||||||
{
|
|
||||||
// If the actor hasn't moved since the activity was issued
|
|
||||||
if (!hasMoved)
|
|
||||||
autoTarget.ResetScanTimer();
|
|
||||||
|
|
||||||
if (--scanTicks <= 0)
|
|
||||||
{
|
|
||||||
var attackActivity = autoTarget.ScanAndAttack(self);
|
|
||||||
if (attackActivity != null)
|
|
||||||
{
|
|
||||||
if (!hasMoved)
|
|
||||||
return attackActivity;
|
|
||||||
|
|
||||||
self.QueueActivity(false, attackActivity);
|
|
||||||
}
|
|
||||||
scanTicks = ScanInterval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hasMoved = true;
|
|
||||||
|
|
||||||
if (inner == null)
|
|
||||||
return NextActivity;
|
|
||||||
|
|
||||||
inner = Util.RunActivity(self, inner);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Cancel(Actor self)
|
|
||||||
{
|
|
||||||
if (inner != null)
|
|
||||||
inner.Cancel(self);
|
|
||||||
|
|
||||||
base.Cancel(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override IEnumerable<Target> GetTargets(Actor self)
|
|
||||||
{
|
|
||||||
if (inner != null)
|
|
||||||
return inner.GetTargets(self);
|
|
||||||
|
|
||||||
return Target.None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user