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