add stance cycling on 'z'

This commit is contained in:
Chris Forbes
2011-10-11 09:18:31 +13:00
parent 59e4dd666a
commit 7f1918d07b
2 changed files with 34 additions and 1 deletions

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA
public enum UnitStance { HoldFire, ReturnFire, AttackAnything }; public enum UnitStance { HoldFire, ReturnFire, AttackAnything };
public class AutoTarget : INotifyIdle, INotifyDamage, ITick public class AutoTarget : INotifyIdle, INotifyDamage, ITick, IResolveOrder
{ {
readonly AutoTargetInfo Info; readonly AutoTargetInfo Info;
readonly AttackBase attack; readonly AttackBase attack;
@@ -38,6 +38,12 @@ namespace OpenRA.Mods.RA
attack = self.Trait<AttackBase>(); attack = self.Trait<AttackBase>();
} }
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "SetUnitStance")
stance = (UnitStance)order.TargetLocation.X;
}
public void Damaged(Actor self, AttackInfo e) public void Damaged(Actor self, AttackInfo e)
{ {
if (!self.IsIdle) return; if (!self.IsIdle) return;

View File

@@ -27,6 +27,7 @@ namespace OpenRA.Mods.RA.Widgets
public string StopKey = "s"; public string StopKey = "s";
public string ScatterKey = "x"; public string ScatterKey = "x";
public string DeployKey = "f"; public string DeployKey = "f";
public string StanceCycleKey = "z";
public string BaseCycleKey = "backspace"; public string BaseCycleKey = "backspace";
public readonly OrderManager OrderManager; public readonly OrderManager OrderManager;
@@ -38,6 +39,7 @@ namespace OpenRA.Mods.RA.Widgets
public override string GetCursor(int2 pos) { return null; } public override string GetCursor(int2 pos) { return null; }
public override Rectangle GetEventBounds() { return Rectangle.Empty; } public override Rectangle GetEventBounds() { return Rectangle.Empty; }
public override bool HandleKeyPress(KeyInput e) public override bool HandleKeyPress(KeyInput e)
{ {
if (World == null) return false; if (World == null) return false;
@@ -67,6 +69,9 @@ namespace OpenRA.Mods.RA.Widgets
if (e.KeyName == DeployKey) if (e.KeyName == DeployKey)
return PerformDeploy(); return PerformDeploy();
if (e.KeyName == StanceCycleKey)
return PerformStanceCycle();
} }
return false; return false;
@@ -115,6 +120,28 @@ namespace OpenRA.Mods.RA.Widgets
return true; return true;
} }
bool PerformStanceCycle()
{
var actor = World.Selection.Actors
.Where(a => a.Owner == World.LocalPlayer)
.Select(a => Pair.New( a, a.TraitOrDefault<AutoTarget>() ))
.Where(a => a.Second != null).FirstOrDefault();
if (actor.First == null)
return true;
var stances = (UnitStance[])Enum.GetValues(typeof(UnitStance));
var nextStance = stances.Concat(stances).SkipWhile(s => s != actor.Second.stance).Skip(1).First();
PerformKeyboardOrderOnSelection(a =>
new Order("SetUnitStance", a, false) { TargetLocation = new int2((int)nextStance, 0) });
Game.Debug( "Unit stance set to: {0}".F(nextStance) );
return true;
}
bool CycleBases() bool CycleBases()
{ {
var bases = World.ActorsWithTrait<BaseBuilding>() var bases = World.ActorsWithTrait<BaseBuilding>()