added pathing debug
This commit is contained in:
@@ -40,10 +40,13 @@ namespace OpenRa.Game
|
|||||||
Dest = dest;
|
Dest = dest;
|
||||||
Weapon = Rules.WeaponInfo[weapon];
|
Weapon = Rules.WeaponInfo[weapon];
|
||||||
Projectile = Rules.ProjectileInfo[Weapon.Projectile];
|
Projectile = Rules.ProjectileInfo[Weapon.Projectile];
|
||||||
Warhead = Rules.WarheadInfo[Weapon.Warhead];
|
Warhead = Rules.WarheadInfo[Weapon.Warhead];
|
||||||
|
|
||||||
anim = new Animation(Projectile.Image);
|
if (Projectile.Image != null && Projectile.Image != "none")
|
||||||
anim.PlayRepeating("idle");
|
{
|
||||||
|
anim = new Animation(Projectile.Image);
|
||||||
|
anim.PlayRepeating("idle");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; }
|
int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; }
|
||||||
@@ -69,12 +72,13 @@ namespace OpenRa.Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Pair<Sprite, float2>> Render()
|
public IEnumerable<Pair<Sprite, float2>> Render()
|
||||||
{
|
{
|
||||||
yield return Pair.New(anim.Image,
|
if (anim != null)
|
||||||
float2.Lerp(
|
yield return Pair.New(anim.Image,
|
||||||
Src.ToFloat2(),
|
float2.Lerp(
|
||||||
Dest.ToFloat2(),
|
Src.ToFloat2(),
|
||||||
(float)t / TotalTime()) - 0.5f * anim.Image.size);
|
Dest.ToFloat2(),
|
||||||
|
(float)t / TotalTime()) - 0.5f * anim.Image.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetMaximumSpread()
|
float GetMaximumSpread()
|
||||||
|
|||||||
@@ -11,7 +11,18 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
class Controller
|
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;
|
float2 dragStart, dragEnd;
|
||||||
public void HandleMouseInput(MouseInput mi)
|
public void HandleMouseInput(MouseInput mi)
|
||||||
@@ -21,11 +32,8 @@ namespace OpenRa.Game
|
|||||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down)
|
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down)
|
||||||
{
|
{
|
||||||
if (!(orderGenerator is PlaceBuilding))
|
if (!(orderGenerator is PlaceBuilding))
|
||||||
dragStart = dragEnd = xy;
|
dragStart = dragEnd = xy;
|
||||||
|
ApplyOrders(xy, true);
|
||||||
if (orderGenerator != null)
|
|
||||||
foreach (var order in orderGenerator.Order(xy.ToInt2(), true))
|
|
||||||
order.Apply();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Move)
|
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
|
/* update the cursor to reflect the thing under us - note this
|
||||||
* needs to also happen when the *thing* changes, so per-frame hook */
|
* needs to also happen when the *thing* changes, so per-frame hook */
|
||||||
dragStart = dragEnd = xy;
|
dragStart = dragEnd = xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down )
|
if (mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down)
|
||||||
if( orderGenerator != null )
|
ApplyOrders(xy, false);
|
||||||
foreach( var order in orderGenerator.Order( xy.ToInt2(), false ) )
|
|
||||||
order.Apply();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pair<float2, float2>? SelectionBox
|
public Pair<float2, float2>? SelectionBox
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using IjwFramework.Types;
|
using IjwFramework.Types;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using OpenRa.Game.Traits;
|
||||||
|
|
||||||
namespace OpenRa.Game.Graphics
|
namespace OpenRa.Game.Graphics
|
||||||
{
|
{
|
||||||
@@ -11,7 +12,9 @@ namespace OpenRa.Game.Graphics
|
|||||||
public readonly SpriteRenderer spriteRenderer;
|
public readonly SpriteRenderer spriteRenderer;
|
||||||
public readonly LineRenderer lineRenderer;
|
public readonly LineRenderer lineRenderer;
|
||||||
public readonly Region region;
|
public readonly Region region;
|
||||||
public readonly UiOverlay uiOverlay;
|
public readonly UiOverlay uiOverlay;
|
||||||
|
|
||||||
|
public static bool ShowUnitPaths = false;
|
||||||
|
|
||||||
public WorldRenderer(Renderer renderer)
|
public WorldRenderer(Renderer renderer)
|
||||||
{
|
{
|
||||||
@@ -146,6 +149,25 @@ namespace OpenRa.Game.Graphics
|
|||||||
lineRenderer.DrawLine(xy + new float2(0, -4),
|
lineRenderer.DrawLine(xy + new float2(0, -4),
|
||||||
z + new float2(0, -4),
|
z + new float2(0, -4),
|
||||||
healthColor2, healthColor2);
|
healthColor2, healthColor2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ShowUnitPaths)
|
||||||
|
{
|
||||||
|
var mobile = selectedUnit.traits.GetOrDefault<Mobile>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ namespace OpenRa.Game
|
|||||||
renderer = new Renderer(this, GetResolution(settings), windowed);
|
renderer = new Renderer(this, GetResolution(settings), windowed);
|
||||||
SheetBuilder.Initialize(renderer);
|
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),
|
Game.Initialize(settings.GetValue("map", "scg11eb.ini"), renderer, new int2(ClientSize),
|
||||||
settings.GetValue("player", 1));
|
settings.GetValue("player", 1));
|
||||||
|
|||||||
@@ -2,44 +2,44 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRa.Game.Traits;
|
using OpenRa.Game.Traits;
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
abstract class Order
|
abstract class Order
|
||||||
{
|
{
|
||||||
public abstract void Apply();
|
public abstract void Apply(bool doVoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
class MoveOrder : Order
|
class MoveOrder : Order
|
||||||
{
|
{
|
||||||
public readonly Actor Unit;
|
public readonly Actor Unit;
|
||||||
public readonly int2 Destination;
|
public readonly int2 Destination;
|
||||||
|
|
||||||
public MoveOrder( Actor unit, int2 destination )
|
public MoveOrder(Actor unit, int2 destination)
|
||||||
{
|
{
|
||||||
this.Unit = unit;
|
this.Unit = unit;
|
||||||
this.Destination = destination;
|
this.Destination = destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
string GetVoiceSuffix()
|
string GetVoiceSuffix()
|
||||||
{
|
{
|
||||||
var suffixes = new[] { ".r01", ".r03" };
|
var suffixes = new[] { ".r01", ".r03" };
|
||||||
return suffixes[Unit.traits.Get<Traits.Mobile>().Voice];
|
return suffixes[Unit.traits.Get<Traits.Mobile>().Voice];
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Apply()
|
public override void Apply(bool doVoice)
|
||||||
{
|
{
|
||||||
if (Game.LocalPlayer == Unit.Owner)
|
if (doVoice && Game.LocalPlayer == Unit.Owner)
|
||||||
Game.PlaySound(Game.SovietVoices.First.GetNext() + GetVoiceSuffix(), false);
|
Game.PlaySound(Game.SovietVoices.First.GetNext() + GetVoiceSuffix(), false);
|
||||||
|
|
||||||
var mobile = Unit.traits.Get<Mobile>();
|
var mobile = Unit.traits.Get<Mobile>();
|
||||||
mobile.Cancel(Unit);
|
mobile.Cancel(Unit);
|
||||||
mobile.QueueActivity( new Mobile.MoveTo( Destination ) );
|
mobile.QueueActivity(new Mobile.MoveTo(Destination));
|
||||||
|
|
||||||
var attackBase = Unit.traits.WithInterface<AttackBase>().FirstOrDefault();
|
var attackBase = Unit.traits.WithInterface<AttackBase>().FirstOrDefault();
|
||||||
if (attackBase != null)
|
if (attackBase != null)
|
||||||
attackBase.target = null; /* move cancels attack order */
|
attackBase.target = null; /* move cancels attack order */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace OpenRa.Game
|
|||||||
this.xy = xy;
|
this.xy = xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Apply()
|
public override void Apply(bool doVoice)
|
||||||
{
|
{
|
||||||
Game.world.AddFrameEndTask( _ =>
|
Game.world.AddFrameEndTask( _ =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace OpenRa.Game.Traits
|
|||||||
var weapon = Rules.WeaponInfo[ weaponName ];
|
var weapon = Rules.WeaponInfo[ weaponName ];
|
||||||
if( weapon.Range * weapon.Range < ( target.Location - self.Location ).LengthSquared ) return false;
|
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,
|
Game.world.Add( new Bullet( weaponName, self.Owner, self,
|
||||||
self.CenterLocation.ToInt2(),
|
self.CenterLocation.ToInt2(),
|
||||||
@@ -90,7 +90,7 @@ namespace OpenRa.Game.Traits
|
|||||||
this.Target = target;
|
this.Target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Apply()
|
public override void Apply( bool doVoice )
|
||||||
{
|
{
|
||||||
var mobile = Attacker.traits.GetOrDefault<Mobile>();
|
var mobile = Attacker.traits.GetOrDefault<Mobile>();
|
||||||
if (mobile != null)
|
if (mobile != null)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRa.Game.Traits
|
|||||||
Location = location;
|
Location = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Apply()
|
public override void Apply( bool doVoice )
|
||||||
{
|
{
|
||||||
var mobile = Unit.traits.Get<Mobile>();
|
var mobile = Unit.traits.Get<Mobile>();
|
||||||
mobile.QueueActivity( new Mobile.Turn( 96 ) );
|
mobile.QueueActivity( new Mobile.Turn( 96 ) );
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ namespace OpenRa.Game.Traits
|
|||||||
public CurrentActivity NextActivity { get; set; }
|
public CurrentActivity NextActivity { get; set; }
|
||||||
|
|
||||||
int2? destination;
|
int2? destination;
|
||||||
List<int2> path;
|
public List<int2> path;
|
||||||
Func<Actor, Mobile, List<int2>> getPath;
|
Func<Actor, Mobile, List<int2>> getPath;
|
||||||
|
|
||||||
MovePart move;
|
MovePart move;
|
||||||
@@ -313,6 +313,13 @@ namespace OpenRa.Game.Traits
|
|||||||
path.Clear();
|
path.Clear();
|
||||||
NextActivity = null;
|
NextActivity = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<int2> GetCurrentPath()
|
||||||
|
{
|
||||||
|
var move = currentActivity as MoveTo;
|
||||||
|
if (move == null || move.path == null) return new int2[] { };
|
||||||
|
return Enumerable.Reverse(move.path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user