Files
OpenRA/OpenRA.Mods.Common/Activities/Hunt.cs
RoosterDragon dcf375a412 Store Targetables in Actor.
This can be used to avoid several lookups for these traits, as well as allow Actor to provide specialised methods to deal with target types efficiently. This also reduces some code duplication.
2015-12-12 20:55:17 +00:00

46 lines
1.2 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2015 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 System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities
{
public class Hunt : Activity
{
readonly IEnumerable<Actor> targets;
public Hunt(Actor self)
{
var attack = self.Trait<AttackBase>();
targets = self.World.ActorsHavingTrait<Huntable>().Where(
a => self != a && !a.IsDead && a.IsInWorld && a.AppearsHostileTo(self)
&& a.IsTargetableBy(self) && attack.HasAnyValidWeapons(Target.FromActor(a)));
}
public override Activity Tick(Actor self)
{
if (IsCanceled)
return NextActivity;
var target = targets.ClosestTo(self);
if (target == null)
return this;
return Util.SequenceActivities(
new AttackMoveActivity(self, new Move(self, target.Location, WDist.FromCells(2))),
new Wait(25),
this);
}
}
}