From ff26bd38c749a877bbb055d0f1e96ebec7f2b78b Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 27 Oct 2009 08:22:54 +1300 Subject: [PATCH] added pathing debug --- OpenRa.Game/Bullet.cs | 24 +++++---- OpenRa.Game/Controller.cs | 30 ++++++----- OpenRa.Game/Graphics/WorldRenderer.cs | 26 +++++++++- OpenRa.Game/MainWindow.cs | 3 +- OpenRa.Game/MoveOrder.cs | 72 +++++++++++++-------------- OpenRa.Game/PlaceBuildingOrder.cs | 2 +- OpenRa.Game/Traits/AttackTurreted.cs | 4 +- OpenRa.Game/Traits/McvDeploy.cs | 2 +- OpenRa.Game/Traits/Mobile.cs | 11 +++- 9 files changed, 107 insertions(+), 67 deletions(-) diff --git a/OpenRa.Game/Bullet.cs b/OpenRa.Game/Bullet.cs index 90cede7c64..2c54b7dc88 100644 --- a/OpenRa.Game/Bullet.cs +++ b/OpenRa.Game/Bullet.cs @@ -40,10 +40,13 @@ namespace OpenRa.Game Dest = dest; Weapon = Rules.WeaponInfo[weapon]; Projectile = Rules.ProjectileInfo[Weapon.Projectile]; - Warhead = Rules.WarheadInfo[Weapon.Warhead]; - - anim = new Animation(Projectile.Image); - anim.PlayRepeating("idle"); + Warhead = Rules.WarheadInfo[Weapon.Warhead]; + + if (Projectile.Image != null && Projectile.Image != "none") + { + anim = new Animation(Projectile.Image); + anim.PlayRepeating("idle"); + } } int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; } @@ -69,12 +72,13 @@ namespace OpenRa.Game } public IEnumerable> Render() - { - yield return Pair.New(anim.Image, - float2.Lerp( - Src.ToFloat2(), - Dest.ToFloat2(), - (float)t / TotalTime()) - 0.5f * anim.Image.size); + { + if (anim != null) + yield return Pair.New(anim.Image, + float2.Lerp( + Src.ToFloat2(), + Dest.ToFloat2(), + (float)t / TotalTime()) - 0.5f * anim.Image.size); } float GetMaximumSpread() diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index cc6bef5aca..c0c7422cec 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -11,7 +11,18 @@ namespace OpenRa.Game { class Controller { - public IOrderGenerator orderGenerator; + public IOrderGenerator orderGenerator; + + void ApplyOrders(float2 xy, bool left) + { + var doVoice = true; + if (orderGenerator != null) + foreach (var order in orderGenerator.Order(xy.ToInt2(), left)) + { + order.Apply(doVoice); + doVoice = false; + } + } float2 dragStart, dragEnd; public void HandleMouseInput(MouseInput mi) @@ -21,11 +32,8 @@ namespace OpenRa.Game if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down) { if (!(orderGenerator is PlaceBuilding)) - dragStart = dragEnd = xy; - - if (orderGenerator != null) - foreach (var order in orderGenerator.Order(xy.ToInt2(), true)) - order.Apply(); + dragStart = dragEnd = xy; + ApplyOrders(xy, true); } if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Move) @@ -51,12 +59,10 @@ namespace OpenRa.Game /* update the cursor to reflect the thing under us - note this * needs to also happen when the *thing* changes, so per-frame hook */ dragStart = dragEnd = xy; - } - - if( mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down ) - if( orderGenerator != null ) - foreach( var order in orderGenerator.Order( xy.ToInt2(), false ) ) - order.Apply(); + } + + if (mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down) + ApplyOrders(xy, false); } public Pair? SelectionBox diff --git a/OpenRa.Game/Graphics/WorldRenderer.cs b/OpenRa.Game/Graphics/WorldRenderer.cs index abbc26f950..63f9c2980c 100644 --- a/OpenRa.Game/Graphics/WorldRenderer.cs +++ b/OpenRa.Game/Graphics/WorldRenderer.cs @@ -2,7 +2,8 @@ using System.Drawing; using System.Linq; using System.Windows.Forms; using IjwFramework.Types; -using System.Collections.Generic; +using System.Collections.Generic; +using OpenRa.Game.Traits; namespace OpenRa.Game.Graphics { @@ -11,7 +12,9 @@ namespace OpenRa.Game.Graphics public readonly SpriteRenderer spriteRenderer; public readonly LineRenderer lineRenderer; public readonly Region region; - public readonly UiOverlay uiOverlay; + public readonly UiOverlay uiOverlay; + + public static bool ShowUnitPaths = false; public WorldRenderer(Renderer renderer) { @@ -146,6 +149,25 @@ namespace OpenRa.Game.Graphics lineRenderer.DrawLine(xy + new float2(0, -4), z + new float2(0, -4), healthColor2, healthColor2); + } + + if (ShowUnitPaths) + { + var mobile = selectedUnit.traits.GetOrDefault(); + if (mobile != null) + { + var path = mobile.GetCurrentPath(); + var start = selectedUnit.Location; + + foreach (var step in path) + { + lineRenderer.DrawLine( + Game.CellSize * start + new float2(12, 12), + Game.CellSize * step + new float2(12, 12), + Color.Red, Color.Red); + start = step; + } + } } } } diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 6f0acbd5af..a509ba8e5e 100755 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -50,7 +50,8 @@ namespace OpenRa.Game renderer = new Renderer(this, GetResolution(settings), windowed); SheetBuilder.Initialize(renderer); - UiOverlay.ShowUnitDebug = settings.GetValue("udebug", false); + UiOverlay.ShowUnitDebug = settings.GetValue("udebug", false); + WorldRenderer.ShowUnitPaths = settings.GetValue("pathdebug", false); Game.Initialize(settings.GetValue("map", "scg11eb.ini"), renderer, new int2(ClientSize), settings.GetValue("player", 1)); diff --git a/OpenRa.Game/MoveOrder.cs b/OpenRa.Game/MoveOrder.cs index c4257f3f61..57bbfeac5b 100644 --- a/OpenRa.Game/MoveOrder.cs +++ b/OpenRa.Game/MoveOrder.cs @@ -2,44 +2,44 @@ using System; using System.Collections.Generic; using System.Text; using System.Linq; -using OpenRa.Game.Traits; - -namespace OpenRa.Game -{ - abstract class Order - { - public abstract void Apply(); - } - - class MoveOrder : Order - { - public readonly Actor Unit; - public readonly int2 Destination; - - public MoveOrder( Actor unit, int2 destination ) - { - this.Unit = unit; - this.Destination = destination; - } - - string GetVoiceSuffix() - { - var suffixes = new[] { ".r01", ".r03" }; - return suffixes[Unit.traits.Get().Voice]; - } - - public override void Apply() - { - if (Game.LocalPlayer == Unit.Owner) - Game.PlaySound(Game.SovietVoices.First.GetNext() + GetVoiceSuffix(), false); - +using OpenRa.Game.Traits; + +namespace OpenRa.Game +{ + abstract class Order + { + public abstract void Apply(bool doVoice); + } + + class MoveOrder : Order + { + public readonly Actor Unit; + public readonly int2 Destination; + + public MoveOrder(Actor unit, int2 destination) + { + this.Unit = unit; + this.Destination = destination; + } + + string GetVoiceSuffix() + { + var suffixes = new[] { ".r01", ".r03" }; + return suffixes[Unit.traits.Get().Voice]; + } + + public override void Apply(bool doVoice) + { + if (doVoice && Game.LocalPlayer == Unit.Owner) + Game.PlaySound(Game.SovietVoices.First.GetNext() + GetVoiceSuffix(), false); + var mobile = Unit.traits.Get(); - mobile.Cancel(Unit); - mobile.QueueActivity( new Mobile.MoveTo( Destination ) ); + mobile.Cancel(Unit); + mobile.QueueActivity(new Mobile.MoveTo(Destination)); var attackBase = Unit.traits.WithInterface().FirstOrDefault(); if (attackBase != null) - attackBase.target = null; /* move cancels attack order */ - } - } + attackBase.target = null; /* move cancels attack order */ + } + } } diff --git a/OpenRa.Game/PlaceBuildingOrder.cs b/OpenRa.Game/PlaceBuildingOrder.cs index 931bac5888..a5de59a3f6 100644 --- a/OpenRa.Game/PlaceBuildingOrder.cs +++ b/OpenRa.Game/PlaceBuildingOrder.cs @@ -16,7 +16,7 @@ namespace OpenRa.Game this.xy = xy; } - public override void Apply() + public override void Apply(bool doVoice) { Game.world.AddFrameEndTask( _ => { diff --git a/OpenRa.Game/Traits/AttackTurreted.cs b/OpenRa.Game/Traits/AttackTurreted.cs index 5e2118739a..2b0f92e3f8 100755 --- a/OpenRa.Game/Traits/AttackTurreted.cs +++ b/OpenRa.Game/Traits/AttackTurreted.cs @@ -41,7 +41,7 @@ namespace OpenRa.Game.Traits var weapon = Rules.WeaponInfo[ weaponName ]; if( weapon.Range * weapon.Range < ( target.Location - self.Location ).LengthSquared ) return false; - fireDelay = 25 * weapon.ROF / 15; + fireDelay = weapon.ROF; Game.world.Add( new Bullet( weaponName, self.Owner, self, self.CenterLocation.ToInt2(), @@ -90,7 +90,7 @@ namespace OpenRa.Game.Traits this.Target = target; } - public override void Apply() + public override void Apply( bool doVoice ) { var mobile = Attacker.traits.GetOrDefault(); if (mobile != null) diff --git a/OpenRa.Game/Traits/McvDeploy.cs b/OpenRa.Game/Traits/McvDeploy.cs index b64ba7fd3e..5b63fa10f8 100644 --- a/OpenRa.Game/Traits/McvDeploy.cs +++ b/OpenRa.Game/Traits/McvDeploy.cs @@ -34,7 +34,7 @@ namespace OpenRa.Game.Traits Location = location; } - public override void Apply() + public override void Apply( bool doVoice ) { var mobile = Unit.traits.Get(); mobile.QueueActivity( new Mobile.Turn( 96 ) ); diff --git a/OpenRa.Game/Traits/Mobile.cs b/OpenRa.Game/Traits/Mobile.cs index 61f739dea1..9258d8229a 100644 --- a/OpenRa.Game/Traits/Mobile.cs +++ b/OpenRa.Game/Traits/Mobile.cs @@ -121,7 +121,7 @@ namespace OpenRa.Game.Traits public CurrentActivity NextActivity { get; set; } int2? destination; - List path; + public List path; Func> getPath; MovePart move; @@ -313,6 +313,13 @@ namespace OpenRa.Game.Traits path.Clear(); NextActivity = null; } - } + } + + public IEnumerable GetCurrentPath() + { + var move = currentActivity as MoveTo; + if (move == null || move.path == null) return new int2[] { }; + return Enumerable.Reverse(move.path); + } } }