Moves Attack, Armament, Move, Air traits and activities as well as anything required by them to Mods.Common.
Extracts Exit from Production into its own trait.
This commit is contained in:
50
OpenRA.Mods.Common/Activities/Move/Follow.cs
Normal file
50
OpenRA.Mods.Common/Activities/Move/Follow.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
#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 OpenRA.Activities;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
public class Follow : Activity
|
||||
{
|
||||
readonly Target target;
|
||||
readonly WRange minRange;
|
||||
readonly WRange maxRange;
|
||||
readonly IMove move;
|
||||
|
||||
public Follow(Actor self, Target target, WRange minRange, WRange maxRange)
|
||||
{
|
||||
this.target = target;
|
||||
this.minRange = minRange;
|
||||
this.maxRange = maxRange;
|
||||
|
||||
move = self.Trait<IMove>();
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled || !target.IsValidFor(self))
|
||||
return NextActivity;
|
||||
|
||||
var cachedPosition = target.CenterPosition;
|
||||
var path = move.MoveWithinRange(target, minRange, maxRange);
|
||||
|
||||
// We are already in range, so wait until the target moves before doing anything
|
||||
if (target.IsInRange(self.CenterPosition, maxRange) && !target.IsInRange(self.CenterPosition, minRange))
|
||||
{
|
||||
var wait = new WaitFor(() => !target.IsValidFor(self) || target.CenterPosition != cachedPosition);
|
||||
return Util.SequenceActivities(wait, path, this);
|
||||
}
|
||||
|
||||
return Util.SequenceActivities(path, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user