diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 4a421431f5..e6d782a0e4 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -64,8 +64,6 @@ - - @@ -87,7 +85,6 @@ - @@ -102,10 +99,6 @@ - - - - diff --git a/OpenRA.Mods.RA/UnitStances/AssignUnitStance.cs b/OpenRA.Mods.RA/UnitStances/AssignUnitStance.cs deleted file mode 100644 index 29e03ebb1d..0000000000 --- a/OpenRA.Mods.RA/UnitStances/AssignUnitStance.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using OpenRA.Traits; - -namespace OpenRA.Mods.RA.UnitStances -{ - public class AssignUnitStanceInfo : TraitInfo - { - - } - - public class AssignUnitStance : INotifyProduction - { - public void UnitProduced(Actor self, Actor other, int2 exit) - { - var stance = UnitStance.GetActive(self); - if (stance == null) - return; - - var target = other.TraitsImplementing().Where(t => t.GetType() == stance.GetType()).FirstOrDefault(); - if (target == null) - return; - - target.Activate(other); - } - } -} diff --git a/OpenRA.Mods.RA/UnitStances/UnitStance.cs b/OpenRA.Mods.RA/UnitStances/UnitStance.cs deleted file mode 100644 index 4caf306b9e..0000000000 --- a/OpenRA.Mods.RA/UnitStances/UnitStance.cs +++ /dev/null @@ -1,313 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using OpenRA.Graphics; -using OpenRA.Traits; - -namespace OpenRA.Mods.RA -{ - - public class UnitStanceInfo : ITraitInfo, ITraitPrerequisite - { - public readonly bool Default = false; - public readonly int ScanDelayMin = 12; - public readonly int ScanDelayMax = 24; - #region ITraitInfo Members - - public virtual object Create(ActorInitializer init) - { - throw new Exception("UnitStanceInfo: Override me!"); - } - - #endregion - } - - public abstract class UnitStance : ITick, IResolveOrder, ISelectionColorModifier, IPostRenderSelection, ISync - { - [Sync] - public int NextScanTime; - - public UnitStanceInfo Info { get; protected set; } - public abstract Color SelectionColor { get; } - - [Sync] - public bool AllowMultiTrigger { get; protected set; } - - #region ITick Members - - protected UnitStance(Actor self, UnitStanceInfo info) - { - Info = info; - Active = Info.Default; - } - - public virtual void Tick(Actor self) - { - if (!Active) return; - - TickScan(self); - - OnTick(self); - } - - protected virtual void OnTick(Actor self) - { - - } - - private void TickScan(Actor self) - { - NextScanTime--; - - if (NextScanTime <= 0) - { - NextScanTime = GetNextScanTime(self); - OnScan(self); - } - } - - private int GetNextScanTime(Actor self) - { - return self.World.SharedRandom.Next(Info.ScanDelayMin, Info.ScanDelayMax+1); - } - - #endregion - - #region IUnitStance Members - - public bool Active { get; set; } - - public virtual bool IsDefault - { - get { return Info.Default; } - } - - public virtual void Activate(Actor self) - { - if (Active && !AllowMultiTrigger) return; - - Active = true; - NextScanTime = 0; - DeactivateOthers(self); - OnActivate(self); - } - - public virtual void Deactivate(Actor self) - { - if (Active) - { - Active = false; - } - } - - #endregion - - public virtual void DeactivateOthers(Actor self) - { - DeactivateOthers(self, this); - } - - public static bool IsActive(Actor self) where T : UnitStance - { - var stance = self.TraitOrDefault(); - - return stance != null && stance.Active; - } - - public static void DeactivateOthers(Actor self, UnitStance stance) - { - self.TraitsImplementing().Where(t => t != stance).Do(t => t.Deactivate(self)); - } - - public abstract string OrderString { get; } - - public static bool ReturnFire(Actor self, AttackInfo e, bool allowActivity, bool allowTargetSwitch, bool holdStill) - { - if (!self.IsIdle && !allowActivity) return false; - if (e.Attacker.Destroyed) return false; - - var attack = self.TraitOrDefault(); - - // this unit cannot fight back at all (no guns) - if (attack == null) return false; - - // if attacking already and force was used, return (ie to respond to attacks while moving around) - if (attack.IsAttacking && (!allowTargetSwitch)) return false; - - // don't fight back if we dont have the guns to do so - if (!attack.HasAnyValidWeapons(Target.FromActor(e.Attacker))) return false; - - // don't retaliate against allies - if (self.Owner.Stances[e.Attacker.Owner] == Stance.Ally) return false; - - // don't retaliate against healers - if (e.Damage < 0) return false; - - // perform the attack - AttackTarget(self, e.Attacker, holdStill); - - return true; - } - - public static bool ReturnFire(Actor self, AttackInfo e, bool allowActivity, bool allowTargetSwitch) - { - return ReturnFire(self, e, allowActivity, allowTargetSwitch, false); - } - - public static bool ReturnFire(Actor self, AttackInfo e, bool allowActivity) - { - return ReturnFire(self, e, allowActivity, false); - } - - public static UnitStance GetActive(Actor self) - { - return self.TraitsImplementing().Where(t => t.Active).FirstOrDefault(); - } - - public static void AttackTarget(Actor self, Actor target, bool holdStill) - { - if (target != null) - self.Trait().AttackTarget(Target.FromActor(target), false, !holdStill); - } - - public static void StopAttack(Actor self) - { - if (self.GetCurrentActivity() is Activities.Attack) - self.GetCurrentActivity().Cancel(self); - } - - /// - /// Called when on the first tick after the stance has been activated - /// - /// - protected virtual void OnScan(Actor self) - { - } - - /// - /// Called when on the first tick after the stance has been activated - /// - /// - protected virtual void OnActivate(Actor self) - { - } - - public static Actor ScanForTarget(Actor self) - { - return self.Trait().ScanForTarget(self, null); - } - - public void ResolveOrder(Actor self, Order order) - { - if (order.OrderString == OrderString) - { - // Its our order, activate the stance - Activate(self); - return; // Do not call OnOrder on our own stance order - } - - if (!Active) return; - - OnOrder(self, order); - } - - protected virtual void OnOrder(Actor self, Order order) - { - - } - - public static void OrderStance(Actor self, UnitStance stance) - { - self.World.IssueOrder(new Order(stance.OrderString, self, false)); - } - - public Color GetSelectionColorModifier(Actor self, Color defaultColor) - { - - if (self.World.LocalPlayer != null && self.Owner.Stances[self.World.LocalPlayer] != Stance.Ally) - return defaultColor; - - return Active ? SelectionColor : defaultColor; - } - - public void RenderAfterWorld(WorldRenderer wr, Actor self) - { - if (!Active) return; - if (!self.IsInWorld) return; - if (self.World.LocalPlayer != null && self.Owner.Stances[self.World.LocalPlayer] != Stance.Ally) - return; - - RenderStance(self); - } - - protected virtual string Shape - { - get { return "xxxx\nx x\nx x\nxxxx"; } - } - - private void RenderStance(Actor self) - { - var bounds = self.GetBounds(false); - var loc = new float2(bounds.Left, bounds.Top) + new float2(0, 1); - var max = Math.Max(bounds.Height, bounds.Width); - - var shape = Shape; - - // 'Resize' for large actors - if (max >= Game.CellSize) - { - shape = shape.Replace(" ", " "); - shape = shape.Replace("x", "xx"); - } - var color = Color.FromArgb(125, Color.Black); - - - int y = 0; - var shapeLines = shape.Split('\n'); - - foreach (var shapeLine in shapeLines) - { - for (int yt = 0; yt < ((max >= Game.CellSize) ? 2 : 1); yt++) - { - int x = 0; - - foreach (var shapeKey in shapeLine) - { - if (shapeKey == 'x') - { - Game.Renderer.LineRenderer.DrawLine(loc + new float2(x, y), loc + new float2(x + 1f, y), color, color); - } - - x++; - } - y++; - } - } - - - y = 0; - shapeLines = shape.Split('\n'); - - color = SelectionColor; - foreach (var shapeLine in shapeLines) - { - for (int yt = 0; yt < ((max >= Game.CellSize) ? 2 : 1); yt++) - { - int x = 0; - - foreach (var shapeKey in shapeLine) - { - if (shapeKey == 'x') - { - Game.Renderer.LineRenderer.DrawLine(loc + new float2(x + 1, y + 1), loc + new float2(x + 1 + 1f, y + 1), color, color); - } - - x++; - } - y++; - } - } - } - } -} \ No newline at end of file diff --git a/OpenRA.Mods.RA/UnitStances/UnitStanceAggressive.cs b/OpenRA.Mods.RA/UnitStances/UnitStanceAggressive.cs deleted file mode 100644 index ae13556943..0000000000 --- a/OpenRA.Mods.RA/UnitStances/UnitStanceAggressive.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using OpenRA.Graphics; -using OpenRA.Traits; - -namespace OpenRA.Mods.RA -{ - public class UnitStanceAggressiveInfo : UnitStanceInfo - { - public override object Create(ActorInitializer init) { return new UnitStanceAggressive(init.self, this); } - } - - /// - /// Inherits the Return Fire damage handler! - /// - public class UnitStanceAggressive : UnitStance, INotifyDamage - { - public UnitStanceAggressive(Actor self, UnitStanceAggressiveInfo info) - : base(self, info) - { - RankAnim = new Animation("rank"); - RankAnim.PlayFetchIndex("rank", () => 3 - 1); - - } - - protected Animation RankAnim { get; set; } - - public override string OrderString - { - get { return "StanceAggressive"; } - } - - protected override void OnScan(Actor self) - { - if (!self.IsIdle) return; - if (!self.HasTrait()) return; - - var target = ScanForTarget(self); - if (target == null) - return; - - AttackTarget(self, target, false); - } - - protected override void OnActivate(Actor self) - { - if (!self.HasTrait()) return; - - if (self.Trait().IsAttacking) - StopAttack(self); - } - - public virtual void Damaged(Actor self, AttackInfo e) - { - if (!Active) return; - if (!self.HasTrait()) return; - - ReturnFire(self, e, false); // only triggers when standing still - } - - public override Color SelectionColor - { - get { return Color.Red; } - } - - protected override string Shape - { - get { return "x x\n xx \n xx \nx x"; } - } - } -} \ No newline at end of file diff --git a/OpenRA.Mods.RA/UnitStances/UnitStanceDefensive.cs b/OpenRA.Mods.RA/UnitStances/UnitStanceDefensive.cs deleted file mode 100644 index af82f306ae..0000000000 --- a/OpenRA.Mods.RA/UnitStances/UnitStanceDefensive.cs +++ /dev/null @@ -1,163 +0,0 @@ -using System; -using System.Drawing; -using OpenRA.Mods.RA.Move; -using OpenRA.Traits; - -namespace OpenRA.Mods.RA -{ - public class UnitStanceDefensiveInfo : UnitStanceInfo - { - public override object Create(ActorInitializer init) { return new UnitStanceDefensive(init.self, this); } - public readonly int MaxDistance = 5; - } - - /// - /// Return Fire - /// - /// Will fire only when fired upon - /// - public class UnitStanceDefensive : UnitStance, INotifyDamage, ISync - { - public enum ETargetType - { - None, - Location, - Actor - } - - [Sync] public int MaxDistance; - public Target DefendTarget = Target.None; - public ETargetType TargetType = ETargetType.None; - public bool WaitingForIdle = false; - [Sync] - public bool IsReturning { get; protected set; } - - public UnitStanceDefensive(Actor self, UnitStanceDefensiveInfo info) - : base(self, info) - { - MaxDistance = info.MaxDistance; - - base.AllowMultiTrigger = true; - } - - protected override void OnActivate(Actor self) - { - DefendThis(self.CenterLocation); - - if (!self.IsIdle) - WaitForIdle(); - } - - protected void DefendThis(int2 target) - { - DefendTarget = Target.FromPos(target); - TargetType = ETargetType.Location; - } - - protected void DefendThis(Actor target) - { - DefendTarget = Target.FromActor(target); - TargetType = ETargetType.Actor; - } - - protected override void OnScan(Actor self) - { - if (TargetType == ETargetType.None) return; - if (IsReturning) return; - if (!self.IsIdle) return; - if (!self.HasTrait()) return; - - var target = ScanForTarget(self); - if (target == null) - return; - - AttackTarget(self, target, false); - } - - protected override void OnTick(Actor self) - { - if (!self.HasTrait()) return; - - // when the unit is doing nothing or the target actor is gone, tell him to defend the current location - if ((WaitingForIdle && self.IsIdle) || (self.IsIdle && (TargetType == ETargetType.Actor && !DefendTarget.IsValid))) - { - IsReturning = false; - WaitingForIdle = false; - DefendThis(self.CenterLocation); - - return; - } - if (IsReturning && self.IsIdle) - { - IsReturning = false; - } - - if (TargetType != ETargetType.None) - { - if ((self.CenterLocation - DefendTarget.CenterLocation).Length > MaxDistance * Game.CellSize) - { - Return(self); - } - } - } - - protected override void OnOrder(Actor self, Order order) - { - WaitForIdle(); - } - - private void WaitForIdle() - { - // could be an attack or move order ... => 'disable' the stance for now (invalidate the target) - DefendTarget = Target.None; - TargetType = ETargetType.None; - WaitingForIdle = true; - } - - public void Damaged(Actor self, AttackInfo e) - { - if (!Active) return; - if (TargetType == ETargetType.None) return; - if (IsReturning) return; - if (!self.HasTrait()) return; - - ReturnFire(self, e, false); // only triggers when standing still - } - - public override string OrderString - { - get { return "StanceDefensive"; } - } - - public override Color SelectionColor - { - get { return Color.LightGoldenrodYellow; } - } - - protected override string Shape - { - get { return "xxxx\nxxxx"; } - } - - protected void Return(Actor self) - { - if ((TargetType == ETargetType.None) || (!DefendTarget.IsValid && (TargetType == ETargetType.Actor && !DefendTarget.IsValid))) return; - IsReturning = true; - - var attackBase = self.TraitOrDefault(); - - - - // Reset the attack target => otherwise it will not pick up enemies anymore! - - // This should result in unsetting the target (could do it directly, this seems more 'valid') - self.World.AddFrameEndTask(w => - { - self.CancelActivity(); - attackBase.ResolveOrder(self, new Order("Stop", self, false)); - self.QueueActivity(self.Trait().MoveWithinRange(DefendTarget, 1)); - WaitForIdle(); - }); - } - } -} \ No newline at end of file diff --git a/OpenRA.Mods.RA/UnitStances/UnitStanceHoldFire.cs b/OpenRA.Mods.RA/UnitStances/UnitStanceHoldFire.cs deleted file mode 100644 index 0f75b24b80..0000000000 --- a/OpenRA.Mods.RA/UnitStances/UnitStanceHoldFire.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Drawing; -using OpenRA.Traits; - -namespace OpenRA.Mods.RA -{ - public class UnitStanceHoldFireInfo : UnitStanceInfo - { - public override object Create(ActorInitializer init) { return new UnitStanceHoldFire(init.self, this); } - } - - /// - /// Hold Fire - /// - /// Will not perform any attacks automaticly - /// - public class UnitStanceHoldFire : UnitStance, ISelectionColorModifier - { - public UnitStanceHoldFire(Actor self, UnitStanceHoldFireInfo info) - : base(self, info) - { - - } - - public override string OrderString - { - get { return "StanceHoldFire"; } - } - - protected override void OnActivate(Actor self) - { - if (!self.HasTrait()) return; - - if (self.Trait().IsAttacking) - StopAttack(self); - } - - public override Color SelectionColor - { - get { return Color.SpringGreen; } - } - - protected override string Shape - { - get { return " xx \nxxxx\n xx "; } - } - } -} \ No newline at end of file diff --git a/OpenRA.Mods.RA/UnitStances/UnitStanceHoldGround.cs b/OpenRA.Mods.RA/UnitStances/UnitStanceHoldGround.cs deleted file mode 100644 index 0901d45205..0000000000 --- a/OpenRA.Mods.RA/UnitStances/UnitStanceHoldGround.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Drawing; -using OpenRA.Mods.RA.Move; -using OpenRA.Traits; - -namespace OpenRA.Mods.RA -{ - public class UnitStanceHoldGroundInfo : UnitStanceInfo - { - public override object Create(ActorInitializer init) { return new UnitStanceHoldGround(init.self, this); } - } - - public class UnitStanceHoldGround : UnitStance, INotifyDamage - { - public UnitStanceHoldGround(Actor self, UnitStanceHoldGroundInfo info) - : base(self, info) - { - - } - - - public override string OrderString - { - get { return "StanceHoldGround"; } - } - - protected override void OnScan(Actor self) - { - if (!self.IsIdle) return; - if (!self.HasTrait()) return; - - var target = ScanForTarget(self); - if (target == null) - return; - - AttackTarget(self, target, true); - } - - protected override void OnActivate(Actor self) - { - if (!self.HasTrait()) return; - - if (self.Trait().IsAttacking) - StopAttack(self); - } - - public void Damaged(Actor self, AttackInfo e) - { - if (!Active) return; - if (!self.HasTrait()) return; - - ReturnFire(self, e, false, false, true); // only triggers when standing still - } - - public override Color SelectionColor - { - get { return Color.Yellow; } - } - - protected override string Shape - { - get { return "xxx\nx x\nx x\nxxx"; } - } - } -} \ No newline at end of file diff --git a/OpenRA.Mods.RA/UnitStances/UnitStanceReturnFire.cs b/OpenRA.Mods.RA/UnitStances/UnitStanceReturnFire.cs deleted file mode 100644 index c62b74cf84..0000000000 --- a/OpenRA.Mods.RA/UnitStances/UnitStanceReturnFire.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Drawing; -using OpenRA.Traits; - -namespace OpenRA.Mods.RA -{ - public class UnitStanceReturnFireInfo : UnitStanceInfo - { - public override object Create(ActorInitializer init) { return new UnitStanceReturnFire(init.self, this); } - } - - /// - /// Return Fire - /// - /// Will fire only when fired upon - /// - public class UnitStanceReturnFire : UnitStance, INotifyDamage, ISelectionColorModifier - { - public UnitStanceReturnFire(Actor self, UnitStanceReturnFireInfo info) - : base(self, info) - { - - } - - public void Damaged(Actor self, AttackInfo e) - { - if (!Active) return; - if (!self.HasTrait()) return; - - ReturnFire(self, e, false); // only triggers when standing still - } - - public override string OrderString - { - get { return "StanceReturnFire"; } - } - - public override Color SelectionColor - { - get { return Color.Orange; } - } - protected override string Shape - { - get { return "xxx\nxxx\nxxx\n x \n x \n\nxxx \nxxx "; } - } - } -} \ No newline at end of file diff --git a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs index d7c0165bac..8e08bdf11a 100644 --- a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs +++ b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs @@ -14,11 +14,6 @@ namespace OpenRA.Mods.RA.Widgets public char AttackMoveKey = 'a'; public char StopKey = 's'; - public char HoldGroundKey = 'g'; // Hold (G)round - public char DefensiveKey = 'd'; // (D)efensive - public char AggressiveKey = 'a'; // (A)ggressive - public char ReturnFireKey = 'r'; // (R)eturn Fire - public char HoldFireKey = 'h'; // (h)old fire public readonly OrderManager OrderManager; [ObjectCreator.UseCtor] @@ -52,56 +47,10 @@ namespace OpenRA.Mods.RA.Widgets if (e.KeyChar == StopKey) return PerformStop(); } - -/* // command: GuardStance - if (e.KeyChar == HoldGroundKey && (e.Modifiers.HasModifier(Modifiers.Alt))) - { - return EnableStance(); - } - - // command: AggressiveStance - if (e.KeyChar == AggressiveKey && (e.Modifiers.HasModifier(Modifiers.Alt))) - { - return EnableStance(); - } - - // stance: Return Fire - // description: Fires only when fired upon, stops firing if no longer under attack - if (e.KeyChar == ReturnFireKey && (e.Modifiers.HasModifier(Modifiers.Alt))) - { - return EnableStance(); - } - - // stance: Hold Fire - // description: Prevents attacking (ie no autotarget is being done) - if (e.KeyChar == HoldFireKey && (e.Modifiers.HasModifier(Modifiers.Alt))) - { - return EnableStance(); - } - - // stance: Defensive - if (e.KeyChar == DefensiveKey && (e.Modifiers.HasModifier(Modifiers.Alt))) - { - return EnableStance(); - } */ return false; } - //bool EnableStance() where T : UnitStance - //{ - // if (World.Selection.Actors.Count() == 0) - // return false; - - // var traits = - // World.Selection.Actors.Where(a => !a.Destroyed && a.Owner == World.LocalPlayer && a.TraitOrDefault() != null && !UnitStance.IsActive(a)). - // Select(a => new Pair(a, a.TraitOrDefault()) ); - - // World.AddFrameEndTask(w => traits.Do(p => UnitStance.OrderStance(p.First, p.Second))); - - // return traits.Any(); - //} - bool PerformAttackMove() { World.OrderGenerator = new GenericSelectTarget(World.Selection.Actors, "AttackMove",