Move ScaredyCat, TakeCover, RenderInfantry, WithBuildingExplosion and SpawnMPUnits as well as Hunt activity to Mods.Common.

This commit is contained in:
reaperrr
2015-01-04 16:41:37 +01:00
parent d07db9c6a9
commit b7a3b9fdbf
9 changed files with 13 additions and 20 deletions

View File

@@ -0,0 +1,51 @@
#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 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.Actors.Where(a => self != a && !a.IsDead && a.IsInWorld && a.AppearsHostileTo(self)
&& a.HasTrait<Huntable>() && IsTargetable(a, self) && attack.HasAnyValidWeapons(Target.FromActor(a)));
}
bool IsTargetable(Actor self, Actor viewer)
{
var targetable = self.TraitOrDefault<ITargetable>();
return targetable != null && targetable.TargetableBy(self, viewer);
}
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, WRange.FromCells(2))),
new Wait(25),
this);
}
}
}