Merge pull request #7116 from reaperrr/attackmove-split

Splits AttackMove into trait and activity
This commit is contained in:
obrakmann
2014-12-12 21:29:13 +01:00
10 changed files with 98 additions and 74 deletions

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Activities
var destination = rp != null ? rp.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));
}
}
}

View 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;
}
}
}

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Activities
return this;
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),
this);
}

View File

@@ -8,6 +8,7 @@
*/
#endregion
using OpenRA.Mods.RA.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.RA

View File

@@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
@@ -36,7 +37,7 @@ namespace OpenRA.Mods.RA
self.SetTargetLine(target, Color.Yellow);
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)

View File

@@ -13,6 +13,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;

View File

@@ -99,6 +99,7 @@
<Compile Include="AI\HackyAI.cs" />
<Compile Include="AcceptsSupplies.cs" />
<Compile Include="Activities\Attack.cs" />
<Compile Include="Activities\AttackMoveActivity.cs" />
<Compile Include="Activities\CallFunc.cs" />
<Compile Include="Activities\ExternalCaptureActor.cs" />
<Compile Include="Activities\DeliverResources.cs" />
@@ -141,7 +142,7 @@
<Compile Include="AI\RushFuzzy.cs" />
<Compile Include="AI\StateMachine.cs" />
<Compile Include="AppearsOnRadar.cs" />
<Compile Include="AttackMove.cs" />
<Compile Include="Traits\AttackMove.cs" />
<Compile Include="Attack\AttackBase.cs" />
<Compile Include="Attack\AttackFrontal.cs" />
<Compile Include="Attack\AttackLeap.cs" />
@@ -494,4 +495,4 @@ copy "FuzzyLogicLibrary.dll" "$(SolutionDir)"
cd "$(SolutionDir)"</PostBuildEvent>
</PropertyGroup>
<ItemGroup />
</Project>
</Project>

View File

@@ -13,6 +13,7 @@ using System.Drawing;
using System.Linq;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Traits;
using OpenRA.Primitives;
@@ -89,7 +90,7 @@ namespace OpenRA.Mods.RA
if (exitinfo.MoveIntoWorld)
{
newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit));
newUnit.QueueActivity(new AttackMove.AttackMoveActivity(
newUnit.QueueActivity(new AttackMoveActivity(
newUnit, move.MoveTo(exitLocation, 1)));
}
}

View File

@@ -12,6 +12,7 @@ using Eluant;
using System;
using System.Linq;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Traits;
using OpenRA.Scripting;
using OpenRA.Traits;
@@ -41,7 +42,7 @@ namespace OpenRA.Mods.RA.Scripting
"close enough to complete the activity.")]
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]
@@ -51,7 +52,7 @@ namespace OpenRA.Mods.RA.Scripting
{
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));
}

View File

@@ -10,9 +10,10 @@
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Mods.RA.Activities;
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.")]
class AttackMoveInfo : ITraitInfo
@@ -63,70 +64,5 @@ namespace OpenRA.Mods.RA
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;
}
}
}
}