80 lines
2.6 KiB
C#
Executable File
80 lines
2.6 KiB
C#
Executable File
#region Copyright & License Information
|
|
/*
|
|
* Copyright 2007-2011 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;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using OpenRA.Traits;
|
|
|
|
namespace OpenRA.Mods.RA.Orders
|
|
{
|
|
public abstract class UnitOrderTargeter : IOrderTargeter
|
|
{
|
|
readonly string cursor;
|
|
readonly bool targetEnemyUnits, targetAllyUnits;
|
|
|
|
public UnitOrderTargeter( string order, int priority, string cursor, bool targetEnemyUnits, bool targetAllyUnits )
|
|
{
|
|
this.OrderID = order;
|
|
this.OrderPriority = priority;
|
|
this.cursor = cursor;
|
|
this.targetEnemyUnits = targetEnemyUnits;
|
|
this.targetAllyUnits = targetAllyUnits;
|
|
}
|
|
|
|
public string OrderID { get; private set; }
|
|
public int OrderPriority { get; private set; }
|
|
public bool? ForceAttack = null;
|
|
|
|
public abstract bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor);
|
|
|
|
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, TargetModifiers modifiers, ref string cursor)
|
|
{
|
|
if (target.Type != TargetType.Actor)
|
|
return false;
|
|
|
|
cursor = this.cursor;
|
|
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
|
|
|
|
if (ForceAttack != null && modifiers.HasModifier(TargetModifiers.ForceAttack) != ForceAttack) return false;
|
|
|
|
var playerRelationship = self.Owner.Stances[target.Actor.Owner];
|
|
|
|
if (!modifiers.HasModifier(TargetModifiers.ForceAttack) && playerRelationship == Stance.Ally && !targetAllyUnits) return false;
|
|
if (!modifiers.HasModifier(TargetModifiers.ForceAttack) && playerRelationship == Stance.Enemy && !targetEnemyUnits) return false;
|
|
|
|
return CanTargetActor(self, target.Actor, modifiers, ref cursor);
|
|
}
|
|
|
|
public virtual bool IsQueued { get; protected set; }
|
|
}
|
|
|
|
public class TargetTypeOrderTargeter : UnitOrderTargeter
|
|
{
|
|
string targetType;
|
|
|
|
public TargetTypeOrderTargeter(string targetType, string order, int priority, string cursor, bool targetEnemyUnits, bool targetAllyUnits)
|
|
: base(order, priority, cursor, targetEnemyUnits, targetAllyUnits)
|
|
{
|
|
this.targetType = targetType;
|
|
}
|
|
|
|
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
|
{
|
|
if (!target.TraitsImplementing<ITargetable>().Any(t => t.TargetTypes.Contains(targetType)))
|
|
return false;
|
|
|
|
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|