Add plumbing for issuing orders against frozen actors.

This commit is contained in:
Paul Chote
2013-08-08 18:47:54 +12:00
parent 40a9caddc7
commit 3e605b1ee9
9 changed files with 92 additions and 41 deletions

View File

@@ -24,8 +24,20 @@ namespace OpenRA.Orders
.OrderByDescending(a => a.Info.SelectionPriority()) .OrderByDescending(a => a.Info.SelectionPriority())
.FirstOrDefault(); .FirstOrDefault();
Target target;
if (underCursor != null)
target = Target.FromActor(underCursor);
else
{
var frozen = world.FindFrozenActorsAtMouse(mi.Location)
.Where(a => a.Info.Traits.Contains<ITargetableInfo>())
.OrderByDescending(a => a.Info.SelectionPriority())
.FirstOrDefault();
target = frozen != null ? Target.FromFrozenActor(frozen) : Target.FromCell(xy);
}
var orders = world.Selection.Actors var orders = world.Selection.Actors
.Select(a => OrderForUnit(a, xy, mi, underCursor)) .Select(a => OrderForUnit(a, target, mi))
.Where(o => o != null) .Where(o => o != null)
.ToArray(); .ToArray();
@@ -61,8 +73,20 @@ namespace OpenRA.Orders
useSelect = true; useSelect = true;
} }
Target target;
if (underCursor != null)
target = Target.FromActor(underCursor);
else
{
var frozen = world.FindFrozenActorsAtMouse(mi.Location)
.Where(a => a.Info.Traits.Contains<ITargetableInfo>())
.OrderByDescending(a => a.Info.SelectionPriority())
.FirstOrDefault();
target = frozen != null ? Target.FromFrozenActor(frozen) : Target.FromCell(xy);
}
var orders = world.Selection.Actors var orders = world.Selection.Actors
.Select(a => OrderForUnit(a, xy, mi, underCursor)) .Select(a => OrderForUnit(a, target, mi))
.Where(o => o != null) .Where(o => o != null)
.ToArray(); .ToArray();
@@ -70,12 +94,12 @@ namespace OpenRA.Orders
return cursorName ?? (useSelect ? "select" : "default"); return cursorName ?? (useSelect ? "select" : "default");
} }
static UnitOrderResult OrderForUnit(Actor self, CPos xy, MouseInput mi, Actor underCursor) static UnitOrderResult OrderForUnit(Actor self, Target target, MouseInput mi)
{ {
if (self.Owner != self.World.LocalPlayer) if (self.Owner != self.World.LocalPlayer)
return null; return null;
if (self.Destroyed) if (self.Destroyed || target.Type == TargetType.Invalid)
return null; return null;
if (mi.Button == Game.mouseButtonPreference.Action) if (mi.Button == Game.mouseButtonPreference.Action)
@@ -85,7 +109,7 @@ namespace OpenRA.Orders
.Select(x => new { Trait = trait, Order = x } )) .Select(x => new { Trait = trait, Order = x } ))
.OrderByDescending(x => x.Order.OrderPriority)) .OrderByDescending(x => x.Order.OrderPriority))
{ {
var actorsAt = self.World.ActorMap.GetUnitsAt(xy).ToList(); var actorsAt = self.World.ActorMap.GetUnitsAt(target.CenterPosition.ToCPos()).ToList();
var modifiers = TargetModifiers.None; var modifiers = TargetModifiers.None;
if (mi.Modifiers.HasModifier(Modifiers.Ctrl)) if (mi.Modifiers.HasModifier(Modifiers.Ctrl))
@@ -96,7 +120,6 @@ namespace OpenRA.Orders
modifiers |= TargetModifiers.ForceMove; modifiers |= TargetModifiers.ForceMove;
string cursor = null; string cursor = null;
var target = underCursor != null ? Target.FromActor(underCursor) : Target.FromCell(xy);
if (o.Order.CanTarget(self, target, actorsAt, modifiers, ref cursor)) if (o.Order.CanTarget(self, target, actorsAt, modifiers, ref cursor))
return new UnitOrderResult(self, o.Order, o.Trait, cursor, target); return new UnitOrderResult(self, o.Order, o.Trait, cursor, target);
} }

View File

@@ -98,13 +98,12 @@ namespace OpenRA.Mods.RA
{ {
var canTargetActor = useCaptureCursor(target); var canTargetActor = useCaptureCursor(target);
cursor = canTargetActor ? "ability" : "move-blocked"; cursor = canTargetActor ? "ability" : "move-blocked";
return canTargetActor;
if (canTargetActor)
{
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
return true;
} }
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
// TODO: Not yet supported
return false; return false;
} }
} }

View File

@@ -65,13 +65,17 @@ namespace OpenRA.Mods.RA
if (self.Owner.Stances[target.Owner] != Stance.Ally) if (self.Owner.Stances[target.Owner] != Stance.Ally)
return false; return false;
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
if (target.GetDamageState() == DamageState.Undamaged) if (target.GetDamageState() == DamageState.Undamaged)
cursor = "goldwrench-blocked"; cursor = "goldwrench-blocked";
return true; return true;
} }
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
// TODO: Not yet supported
return false;
}
} }
} }

View File

@@ -103,6 +103,12 @@ namespace OpenRA.Mods.RA
return true; return true;
} }
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
// TODO: Not yet supported
return false;
}
} }
} }
} }

View File

@@ -104,13 +104,18 @@ namespace OpenRA.Mods.RA
cursor = lowEnoughHealth ? "enter" : "capture"; cursor = lowEnoughHealth ? "enter" : "capture";
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
return true; return true;
} }
cursor = "enter-blocked"; cursor = "enter-blocked";
return false; return false;
} }
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
// TODO: Not yet supported
return false;
}
} }
} }
} }

View File

@@ -29,15 +29,17 @@ 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 (!target.HasTrait<T>()) if (!target.HasTrait<T>() || !canTarget(target))
return false;
if (!canTarget(target))
return false; return false;
cursor = useEnterCursor(target) ? "enter" : "enter-blocked"; cursor = useEnterCursor(target) ? "enter" : "enter-blocked";
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
return true; return true;
} }
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
// TODO: Not yet supported
return false;
}
} }
} }

View File

@@ -34,23 +34,32 @@ namespace OpenRA.Mods.RA.Orders
public bool? ForceAttack = null; public bool? ForceAttack = null;
public abstract 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 abstract bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor);
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, 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) var type = target.Type;
if (type != TargetType.Actor && type != TargetType.FrozenActor)
return false; 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.Actor.Owner]; var owner = type == TargetType.FrozenActor ? target.FrozenActor.Owner : target.Actor.Owner;
var playerRelationship = self.Owner.Stances[owner];
if (!modifiers.HasModifier(TargetModifiers.ForceAttack) && playerRelationship == Stance.Ally && !targetAllyUnits) return false; if (!modifiers.HasModifier(TargetModifiers.ForceAttack) && playerRelationship == Stance.Ally && !targetAllyUnits)
if (!modifiers.HasModifier(TargetModifiers.ForceAttack) && playerRelationship == Stance.Enemy && !targetEnemyUnits) return false; return false;
return CanTargetActor(self, target.Actor, modifiers, ref cursor); if (!modifiers.HasModifier(TargetModifiers.ForceAttack) && playerRelationship == Stance.Enemy && !targetEnemyUnits)
return false;
return type == TargetType.FrozenActor ?
CanTargetFrozenActor(self, target.FrozenActor, modifiers, ref cursor) :
CanTargetActor(self, target.Actor, modifiers, ref cursor);
} }
public virtual bool IsQueued { get; protected set; } public virtual bool IsQueued { get; protected set; }
@@ -68,12 +77,12 @@ 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 (!target.TraitsImplementing<ITargetable>().Any(t => t.TargetTypes.Contains(targetType))) return target.TraitsImplementing<ITargetable>().Any(t => t.TargetTypes.Contains(targetType));
return false; }
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue); public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
return true; return target.Info.Traits.WithInterface<ITargetableInfo>().Any(t => t.GetTargetTypes().Contains(targetType));
} }
} }
} }

View File

@@ -80,14 +80,18 @@ namespace OpenRA.Mods.RA
if (!modifiers.HasModifier(TargetModifiers.ForceAttack) && damage != DamageState.Dead) if (!modifiers.HasModifier(TargetModifiers.ForceAttack) && damage != DamageState.Dead)
return false; return false;
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
// Can't repair an undamaged bridge // Can't repair an undamaged bridge
if (damage == DamageState.Undamaged) if (damage == DamageState.Undamaged)
cursor = "goldwrench-blocked"; cursor = "goldwrench-blocked";
return true; return true;
} }
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
// TODO: Bridges don't yet support FrozenUnderFog.
return false;
}
} }
} }
} }

View File

@@ -72,14 +72,13 @@ 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 (target.AppearsHostileTo(self)) return target.HasTrait<AcceptsSupplies>();
return false; }
if (!target.HasTrait<AcceptsSupplies>()) public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
// TODO: Not yet supported
return false; return false;
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
return true;
} }
} }
} }