Added: forceQueue to IOrderTarget' CanTargetUnit / CanTargetLocation

Added: forceQueue to all related methods
Added: Only shows the select cursor IF hovering over a unit AND the orders return the 'default' icon
This commit is contained in:
geckosoft
2010-11-13 01:25:31 +01:00
committed by Bob
parent 8df47f5a60
commit 622f9bfe71
12 changed files with 72 additions and 40 deletions

View File

@@ -98,7 +98,9 @@ namespace OpenRA.Orders
} }
public string GetCursor( World world, int2 xy, MouseInput mi ) public string GetCursor( World world, int2 xy, MouseInput mi )
{ {
bool useSelect = false;
var custom = world.WorldActor.TraitOrDefault<ICustomUnitOrderGenerator>(); var custom = world.WorldActor.TraitOrDefault<ICustomUnitOrderGenerator>();
if (custom != null) if (custom != null)
{ {
@@ -108,20 +110,21 @@ namespace OpenRA.Orders
var underCursor = world.FindUnitsAtMouse(mi.Location) var underCursor = world.FindUnitsAtMouse(mi.Location)
.Where(a => a.HasTrait<ITargetable>()) .Where(a => a.HasTrait<ITargetable>())
.OrderByDescending(a => a.Info.Traits.Contains<SelectableInfo>() ? a.Info.Traits.Get<SelectableInfo>().Priority : int.MinValue) .OrderByDescending(a => a.Info.Traits.Contains<SelectableInfo>() ? a.Info.Traits.Get<SelectableInfo>().Priority : int.MinValue)
.FirstOrDefault(); .FirstOrDefault();
if( mi.Modifiers.HasModifier( Modifiers.Shift ) || !world.Selection.Actors.Any() )
if( underCursor != null ) if (mi.Modifiers.HasModifier(Modifiers.Shift) || !world.Selection.Actors.Any())
return "select"; if (underCursor != null)
useSelect = true;
var orders = world.Selection.Actors var orders = world.Selection.Actors
.Select(a => OrderForUnit(a, xy, mi, underCursor)) .Select(a => OrderForUnit(a, xy, mi, underCursor))
.Where(o => o != null) .Where(o => o != null)
.ToArray(); .ToArray();
if( orders.Length == 0 ) return "default"; if( orders.Length == 0 ) return (useSelect) ? "select" : "default";
return orders[ 0 ].cursor ?? "default"; return orders[0].cursor ?? ((useSelect) ? "select" : "default");
} }
static UnitOrderResult OrderForUnit( Actor self, int2 xy, MouseInput mi, Actor underCursor ) static UnitOrderResult OrderForUnit( Actor self, int2 xy, MouseInput mi, Actor underCursor )
@@ -154,9 +157,9 @@ namespace OpenRA.Orders
string cursor = null; string cursor = null;
if( underCursor != null ) if( underCursor != null )
if( o.Order.CanTargetUnit( self, underCursor, mi.Modifiers.HasModifier( Modifiers.Ctrl ), mi.Modifiers.HasModifier( Modifiers.Alt ), ref cursor ) ) if (o.Order.CanTargetUnit(self, underCursor, mi.Modifiers.HasModifier(Modifiers.Ctrl), mi.Modifiers.HasModifier(Modifiers.Alt), mi.Modifiers.HasModifier(Modifiers.Shift), ref cursor))
return new UnitOrderResult( self, o.Order, o.Trait, cursor, Target.FromActor( underCursor ) ); return new UnitOrderResult( self, o.Order, o.Trait, cursor, Target.FromActor( underCursor ) );
if( o.Order.CanTargetLocation( self, xy, actorsAt, mi.Modifiers.HasModifier( Modifiers.Ctrl ), mi.Modifiers.HasModifier( Modifiers.Alt ), ref cursor ) ) if (o.Order.CanTargetLocation(self, xy, actorsAt, mi.Modifiers.HasModifier(Modifiers.Ctrl), mi.Modifiers.HasModifier(Modifiers.Alt), mi.Modifiers.HasModifier(Modifiers.Shift), ref cursor))
return new UnitOrderResult( self, o.Order, o.Trait, cursor, Target.FromCell( xy ) ); return new UnitOrderResult( self, o.Order, o.Trait, cursor, Target.FromCell( xy ) );
} }
} }

View File

@@ -45,9 +45,10 @@ namespace OpenRA.Traits
{ {
string OrderID { get; } string OrderID { get; }
int OrderPriority { get; } int OrderPriority { get; }
bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor ); bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueue, ref string cursor );
bool CanTargetLocation( Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, ref string cursor ); bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueue, bool forceMove, ref string cursor);
} bool IsQueued { get; }
}
public interface IResolveOrder { void ResolveOrder(Actor self, Order order); } public interface IResolveOrder { void ResolveOrder(Actor self, Order order); }
public interface IValidateOrder { bool OrderValidation(OrderManager orderManager, World world, int clientId, Order order); public interface IValidateOrder { bool OrderValidation(OrderManager orderManager, World world, int clientId, Order order);
} }

View File

@@ -142,15 +142,17 @@ 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 CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor ) public bool CanTargetUnit(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
return false; return false;
} }
public bool CanTargetLocation( Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, ref string cursor ) public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
IsQueued = forceQueued;
cursor = "move"; cursor = "move";
return true; return true;
} }
public bool IsQueued { get; protected set; }
} }
} }

View File

@@ -261,8 +261,10 @@ 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 CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor ) public bool CanTargetUnit(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
IsQueued = forceQueued;
cursor = isHeal ? "heal" : "attack"; cursor = isHeal ? "heal" : "attack";
if( self == target ) return false; if( self == target ) return false;
if( !self.Trait<AttackBase>().HasAnyValidWeapons( Target.FromActor( target ) ) ) return false; if( !self.Trait<AttackBase>().HasAnyValidWeapons( Target.FromActor( target ) ) ) return false;
@@ -276,8 +278,10 @@ namespace OpenRA.Mods.RA
return playerRelationship == Stance.Enemy || forceAttack; return playerRelationship == Stance.Enemy || forceAttack;
} }
public bool CanTargetLocation( Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, ref string cursor ) public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
IsQueued = forceQueued;
cursor = isHeal ? "heal" : "attack"; cursor = isHeal ? "heal" : "attack";
if( isHeal ) return false; if( isHeal ) return false;
if( !self.Trait<AttackBase>().HasAnyValidWeapons( Target.FromCell( location ) ) ) return false; if( !self.Trait<AttackBase>().HasAnyValidWeapons( Target.FromCell( location ) ) ) return false;
@@ -288,6 +292,8 @@ namespace OpenRA.Mods.RA
return false; return false;
} }
public bool IsQueued { get; protected set; }
} }
} }
} }

View File

@@ -70,9 +70,11 @@ namespace OpenRA.Mods.RA
{ {
} }
public override bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor ) public override bool CanTargetUnit(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
if( !base.CanTargetUnit( self, target, forceAttack, forceMove, ref cursor ) ) return false; if( !base.CanTargetUnit( self, target, forceAttack, forceMove, forceQueued, ref cursor ) ) return false;
IsQueued = forceQueued;
if( target.GetDamageState() == DamageState.Undamaged ) if( target.GetDamageState() == DamageState.Undamaged )
cursor = "goldwrench-blocked"; cursor = "goldwrench-blocked";

View File

@@ -218,15 +218,15 @@ namespace OpenRA.Mods.RA
public string OrderID { get { return "Harvest";}} public string OrderID { get { return "Harvest";}}
public int OrderPriority { get { return 10; } } public int OrderPriority { get { return 10; } }
public bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor ) public bool CanTargetUnit(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
return false; return false;
} }
public bool CanTargetLocation( Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, ref string cursor ) public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
// Don't leak info about resources under the shroud // Don't leak info about resources under the shroud
if( !self.World.LocalPlayer.Shroud.IsExplored( location ) ) return false; if (!self.World.LocalPlayer.Shroud.IsExplored(location)) return false;
var res = self.World.WorldActor.Trait<ResourceLayer>().GetResource( location ); var res = self.World.WorldActor.Trait<ResourceLayer>().GetResource( location );
var info = self.Info.Traits.Get<HarvesterInfo>(); var info = self.Info.Traits.Get<HarvesterInfo>();
@@ -234,8 +234,11 @@ namespace OpenRA.Mods.RA
if( res == null ) return false; if( res == null ) return false;
if( !info.Resources.Contains( res.info.Name ) ) return false; if( !info.Resources.Contains( res.info.Name ) ) return false;
cursor = "attackmove"; cursor = "attackmove";
IsQueued = forceQueued;
return true; return true;
} }
public bool IsQueued { get; protected set; }
} }
} }
} }

View File

@@ -152,16 +152,19 @@ 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 CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor ) public bool CanTargetUnit(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
return false; return false;
} }
public bool CanTargetLocation( Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, ref string cursor ) public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
cursor = "ability"; cursor = "ability";
IsQueued = forceQueued;
return ( actorsAtLocation.Count == 0 && forceAttack ); return ( actorsAtLocation.Count == 0 && forceAttack );
} }
public bool IsQueued { get; protected set; }
} }
} }
} }

View File

@@ -360,14 +360,16 @@ namespace OpenRA.Mods.RA.Move
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 IsQueued { get; protected set; }
public bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor ) public bool CanTargetUnit(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
return false; return false;
} }
public bool CanTargetLocation( Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, ref string cursor ) public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
IsQueued = forceQueued;
cursor = "move"; cursor = "move";
if( self.World.LocalPlayer.Shroud.IsVisible( location ) && !self.Trait<Mobile>().CanEnterCell( location ) ) if( self.World.LocalPlayer.Shroud.IsVisible( location ) && !self.Trait<Mobile>().CanEnterCell( location ) )
cursor = "move-blocked"; cursor = "move-blocked";

View File

@@ -25,15 +25,18 @@ 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 CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor ) public bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor )
{ {
IsQueued = forceQueued;
cursor = useDeployCursor() ? "deploy" : "deploy-blocked"; cursor = useDeployCursor() ? "deploy" : "deploy-blocked";
return self == target; return self == target;
} }
public bool CanTargetLocation( Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, ref string cursor ) public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
return false; return false;
} }
public bool IsQueued { get; protected set; }
} }
} }

View File

@@ -25,11 +25,12 @@ namespace OpenRA.Mods.RA.Orders
this.useEnterCursor = useEnterCursor; this.useEnterCursor = useEnterCursor;
} }
public override bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor ) public override bool CanTargetUnit(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
if( !base.CanTargetUnit( self, target, forceAttack, forceMove, ref cursor ) ) return false; if( !base.CanTargetUnit( self, target, forceAttack, forceMove, forceQueued, ref cursor ) ) return false;
if( !canTarget( target ) ) return false; if( !canTarget( target ) ) return false;
cursor = useEnterCursor( target ) ? "enter" : "enter-blocked"; cursor = useEnterCursor(target) ? "enter" : "enter-blocked";
IsQueued = forceQueued;
return true; return true;
} }
} }

View File

@@ -31,12 +31,13 @@ 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 virtual bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor ) public virtual bool CanTargetUnit(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
if( self == null ) throw new ArgumentNullException( "self" ); if( self == null ) throw new ArgumentNullException( "self" );
if( target == null ) throw new ArgumentNullException( "target" ); if( target == null ) throw new ArgumentNullException( "target" );
cursor = this.cursor; cursor = this.cursor;
IsQueued = forceQueued;
var playerRelationship = self.Owner.Stances[ target.Owner ]; var playerRelationship = self.Owner.Stances[ target.Owner ];
@@ -46,10 +47,11 @@ namespace OpenRA.Mods.RA.Orders
return true; return true;
} }
public virtual bool CanTargetLocation( Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, ref string cursor ) public virtual bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
return false; return false;
} }
public virtual bool IsQueued { get; protected set; }
} }
public class UnitTraitOrderTargeter<T> : UnitOrderTargeter public class UnitTraitOrderTargeter<T> : UnitOrderTargeter
@@ -59,11 +61,13 @@ namespace OpenRA.Mods.RA.Orders
{ {
} }
public override bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor ) public override bool CanTargetUnit(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
if( !base.CanTargetUnit( self, target, forceAttack, forceMove, ref cursor ) ) return false; if( !base.CanTargetUnit( self, target, forceAttack, forceMove, forceQueued, ref cursor ) ) return false;
if( !target.HasTrait<T>() ) return false; if( !target.HasTrait<T>() ) return false;
IsQueued = forceQueued;
return true; return true;
} }
} }

View File

@@ -69,15 +69,17 @@ 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 CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor ) public bool CanTargetUnit(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
return false; return false;
} }
public bool CanTargetLocation( Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, ref string cursor ) public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{ {
return true; return true;
} }
public bool IsQueued { get { return false; } } // unused
} }
} }
} }