Merge IOrderTargeter.CanTargetActor and CanTargetLocation.
This commit is contained in:
@@ -96,11 +96,9 @@ namespace OpenRA.Orders
|
||||
modifiers |= TargetModifiers.ForceMove;
|
||||
|
||||
string cursor = null;
|
||||
if (underCursor != null)
|
||||
if (o.Order.CanTargetActor(self, underCursor, modifiers, ref cursor))
|
||||
return new UnitOrderResult(self, o.Order, o.Trait, cursor, Target.FromActor(underCursor));
|
||||
if (o.Order.CanTargetLocation(self, xy, actorsAt, modifiers, ref cursor))
|
||||
return new UnitOrderResult(self, o.Order, o.Trait, cursor, Target.FromCell(xy));
|
||||
var target = underCursor != null ? Target.FromActor(underCursor) : Target.FromCell(xy);
|
||||
if (o.Order.CanTarget(self, target, actorsAt, modifiers, ref cursor))
|
||||
return new UnitOrderResult(self, o.Order, o.Trait, cursor, target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,7 @@ namespace OpenRA.Traits
|
||||
{
|
||||
string OrderID { get; }
|
||||
int OrderPriority { get; }
|
||||
bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor);
|
||||
bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, TargetModifiers modifiers, ref string cursor);
|
||||
bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, TargetModifiers modifiers, ref string cursor);
|
||||
bool IsQueued { get; }
|
||||
}
|
||||
|
||||
|
||||
@@ -217,15 +217,13 @@ namespace OpenRA.Mods.RA.Air
|
||||
public string OrderID { get { return "Move"; } }
|
||||
public int OrderPriority { get { return 4; } }
|
||||
|
||||
public 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)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (target.Type != TargetType.Terrain)
|
||||
return false;
|
||||
|
||||
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
|
||||
cursor = self.World.Map.IsInMap(location) ? "move" : "move-blocked";
|
||||
cursor = self.World.Map.IsInMap(target.CenterPosition.ToCPos()) ? "move" : "move-blocked";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace OpenRA.Mods.RA
|
||||
public string OrderID { get; private set; }
|
||||
public int OrderPriority { get; private set; }
|
||||
|
||||
public bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
|
||||
|
||||
@@ -192,7 +192,7 @@ namespace OpenRA.Mods.RA
|
||||
return self.Owner.Stances[target.Owner] == targetableRelationship;
|
||||
}
|
||||
|
||||
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, TargetModifiers modifiers, ref string cursor)
|
||||
bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (!self.World.Map.IsInMap(location))
|
||||
return false;
|
||||
@@ -214,6 +214,17 @@ namespace OpenRA.Mods.RA
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (target.Type == TargetType.Actor)
|
||||
return CanTargetActor(self, target.Actor, modifiers, ref cursor);
|
||||
|
||||
if (target.Type == TargetType.Terrain)
|
||||
return CanTargetLocation(self, target.CenterPosition.ToCPos(), othersAtTarget, modifiers, ref cursor);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsQueued { get; protected set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,9 +96,6 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (!base.CanTargetActor(self, target, modifiers, ref cursor))
|
||||
return false;
|
||||
|
||||
var canTargetActor = useCaptureCursor(target);
|
||||
cursor = canTargetActor ? "ability" : "move-blocked";
|
||||
|
||||
|
||||
@@ -59,9 +59,6 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (!base.CanTargetActor(self, target, modifiers, ref cursor))
|
||||
return false;
|
||||
|
||||
if (!target.HasTrait<EngineerRepairable>())
|
||||
return false;
|
||||
|
||||
|
||||
@@ -419,16 +419,15 @@ namespace OpenRA.Mods.RA
|
||||
public int OrderPriority { get { return 10; } }
|
||||
public bool IsQueued { get; protected set; }
|
||||
|
||||
public 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)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (target.Type != TargetType.Terrain)
|
||||
return false;
|
||||
|
||||
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (modifiers.HasModifier(TargetModifiers.ForceMove))
|
||||
return false;
|
||||
|
||||
var location = target.CenterPosition.ToCPos();
|
||||
// Don't leak info about resources under the shroud
|
||||
if (!self.Owner.Shroud.IsExplored(location))
|
||||
return false;
|
||||
|
||||
@@ -95,9 +95,6 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (!base.CanTargetActor(self, target, modifiers, ref cursor))
|
||||
return false;
|
||||
|
||||
if (!target.HasTrait<IAcceptInfiltrator>())
|
||||
return false;
|
||||
|
||||
|
||||
@@ -94,8 +94,6 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (!base.CanTargetActor(self, target, modifiers, ref cursor)) return false;
|
||||
|
||||
var canTargetActor = useCaptureCursor(target);
|
||||
|
||||
if (canTargetActor)
|
||||
|
||||
@@ -156,21 +156,21 @@ namespace OpenRA.Mods.RA
|
||||
public string OrderID { get { return "BeginMinefield"; } }
|
||||
public int OrderPriority { get { return 5; } }
|
||||
|
||||
public 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)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (target.Type != TargetType.Terrain)
|
||||
return false;
|
||||
|
||||
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
var location = target.CenterPosition.ToCPos();
|
||||
if (!self.World.Map.IsInMap(location))
|
||||
return false;
|
||||
|
||||
cursor = "ability";
|
||||
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
|
||||
|
||||
return (actorsAtLocation.Count == 0 && modifiers.HasModifier(TargetModifiers.ForceAttack));
|
||||
return !othersAtTarget.Any() && modifiers.HasModifier(TargetModifiers.ForceAttack);
|
||||
}
|
||||
|
||||
public bool IsQueued { get; protected set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,13 +494,12 @@ namespace OpenRA.Mods.RA.Move
|
||||
public int OrderPriority { get { return 4; } }
|
||||
public bool IsQueued { get; protected set; }
|
||||
|
||||
public 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)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!target.IsValid)
|
||||
return false;
|
||||
|
||||
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
var location = target.CenterPosition.ToCPos();
|
||||
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
|
||||
cursor = "move";
|
||||
|
||||
|
||||
@@ -35,16 +35,15 @@ namespace OpenRA.Mods.RA.Orders
|
||||
public string OrderID { get; private set; }
|
||||
public int OrderPriority { get; private set; }
|
||||
|
||||
public 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;
|
||||
|
||||
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
|
||||
cursor = useDeployCursor() ? "deploy" : "deploy-blocked";
|
||||
return self == target;
|
||||
}
|
||||
|
||||
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
return false;
|
||||
return self == target.Actor;
|
||||
}
|
||||
|
||||
public bool IsQueued { get; protected set; }
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Orders
|
||||
@@ -28,9 +29,6 @@ namespace OpenRA.Mods.RA.Orders
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (!base.CanTargetActor(self, target, modifiers, ref cursor))
|
||||
return false;
|
||||
|
||||
if (!target.HasTrait<T>())
|
||||
return false;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Orders
|
||||
{
|
||||
public class UnitOrderTargeter : IOrderTargeter
|
||||
public abstract class UnitOrderTargeter : IOrderTargeter
|
||||
{
|
||||
readonly string cursor;
|
||||
readonly bool targetEnemyUnits, targetAllyUnits;
|
||||
@@ -33,27 +33,24 @@ namespace OpenRA.Mods.RA.Orders
|
||||
public int OrderPriority { get; private set; }
|
||||
public bool? ForceAttack = null;
|
||||
|
||||
public virtual bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
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( self == null ) throw new ArgumentNullException( "self" );
|
||||
if( target == null ) throw new ArgumentNullException( "target" );
|
||||
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.Owner];
|
||||
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 true;
|
||||
}
|
||||
|
||||
public virtual bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
return false;
|
||||
return CanTargetActor(self, target.Actor, modifiers, ref cursor);
|
||||
}
|
||||
|
||||
public virtual bool IsQueued { get; protected set; }
|
||||
@@ -71,9 +68,6 @@ namespace OpenRA.Mods.RA.Orders
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (!base.CanTargetActor(self, target, modifiers, ref cursor))
|
||||
return false;
|
||||
|
||||
if (!target.TraitsImplementing<ITargetable>().Any(t => t.TargetTypes.Contains(targetType)))
|
||||
return false;
|
||||
|
||||
|
||||
@@ -58,13 +58,12 @@ namespace OpenRA.Mods.RA
|
||||
public string OrderID { get { return "SetRallyPoint"; } }
|
||||
public int OrderPriority { get { return 0; } }
|
||||
|
||||
public 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)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (target.Type != TargetType.Terrain)
|
||||
return false;
|
||||
|
||||
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
var location = target.CenterPosition.ToCPos();
|
||||
if (self.World.Map.IsInMap(location))
|
||||
{
|
||||
cursor = "ability";
|
||||
|
||||
@@ -71,9 +71,6 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (!base.CanTargetActor(self, target, modifiers, ref cursor))
|
||||
return false;
|
||||
|
||||
var bridge = target.TraitOrDefault<BridgeHut>();
|
||||
if (bridge == null)
|
||||
return false;
|
||||
|
||||
@@ -72,9 +72,6 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (!base.CanTargetActor(self, target, modifiers, ref cursor))
|
||||
return false;
|
||||
|
||||
if (target.AppearsHostileTo(self))
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user