Merge pull request #9465 from huwpascoe/CombatOverlay

Added warhead visualization to combat debug overlay.
This commit is contained in:
atlimit8
2015-10-01 22:14:18 -05:00
8 changed files with 109 additions and 4 deletions

View File

@@ -528,6 +528,7 @@
<Compile Include="Traits\World\SpawnMPUnits.cs" />
<Compile Include="Traits\World\StartGameNotification.cs" />
<Compile Include="Traits\World\TerrainGeometryOverlay.cs" />
<Compile Include="Traits\World\WarheadDebugOverlay.cs" />
<Compile Include="Traits\World\WeatherOverlay.cs" />
<Compile Include="UtilityCommands\CheckYaml.cs" />
<Compile Include="UtilityCommands\CheckCodeStyle.cs" />

View File

@@ -0,0 +1,87 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Part of the combat overlay from DeveloperMode. Attach this to the world actor.")]
public class WarheadDebugOverlayInfo : ITraitInfo
{
public readonly int DisplayDuration = 25;
public object Create(ActorInitializer init) { return new WarheadDebugOverlay(this); }
}
public class WarheadDebugOverlay : IPostRender
{
class WHImpact
{
public readonly WPos CenterPosition;
public readonly WDist[] Range;
public int Time;
public WDist OuterRange
{
get { return Range[Range.Length - 1]; }
}
public WHImpact(WPos pos, WDist[] range, int time)
{
CenterPosition = pos;
Range = range;
Time = time;
}
}
readonly WarheadDebugOverlayInfo info;
readonly List<WHImpact> impacts = new List<WHImpact>();
public WarheadDebugOverlay(WarheadDebugOverlayInfo info)
{
this.info = info;
}
public void AddImpact(WPos pos, WDist[] range)
{
impacts.Add(new WHImpact(pos, range, info.DisplayDuration));
}
public void RenderAfterWorld(WorldRenderer wr, Actor self)
{
foreach (var i in impacts)
{
var alpha = 255.0f * i.Time / info.DisplayDuration;
var rangeStep = alpha / i.Range.Length;
wr.DrawRangeCircle(i.CenterPosition, i.OuterRange, Color.FromArgb((int)alpha, Color.Red));
foreach (var r in i.Range)
{
var tl = wr.ScreenPosition(i.CenterPosition - new WVec(r.Length, r.Length, 0));
var br = wr.ScreenPosition(i.CenterPosition + new WVec(r.Length, r.Length, 0));
var rect = RectangleF.FromLTRB(tl.X, tl.Y, br.X, br.Y);
Game.Renderer.WorldLineRenderer.FillEllipse(rect, Color.FromArgb((int)alpha, Color.Red));
alpha -= rangeStep;
}
if (!wr.World.Paused)
i.Time--;
}
impacts.RemoveAll(i => i.Time == 0);
}
}
}

View File

@@ -10,6 +10,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Warheads
@@ -22,6 +23,14 @@ namespace OpenRA.Mods.Common.Warheads
public override void DoImpact(WPos pos, Actor firedBy, IEnumerable<int> damageModifiers)
{
var world = firedBy.World;
if (world.LocalPlayer != null)
{
var devMode = world.LocalPlayer.PlayerActor.TraitOrDefault<DeveloperMode>();
if (devMode != null && devMode.ShowCombatGeometry)
world.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(pos, Spread);
}
var range = Spread[0];
var hitActors = world.FindActorsInCircle(pos, range);
if (Spread.Length > 1 && Spread[1].Length > 0)

View File

@@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Warheads
@@ -50,6 +51,13 @@ namespace OpenRA.Mods.Common.Warheads
var world = firedBy.World;
if (world.LocalPlayer != null)
{
var devMode = world.LocalPlayer.PlayerActor.TraitOrDefault<DeveloperMode>();
if (devMode != null && devMode.ShowCombatGeometry)
world.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(pos, Range);
}
// This only finds actors where the center is within the search radius,
// so we need to search beyond the maximum spread to account for actors with large health radius
var hitActors = world.FindActorsInCircle(pos, Range[Range.Length - 1] + TargetExtraSearchRadius);

View File

@@ -73,6 +73,7 @@ World:
ResourceLayer:
ResourceClaimLayer:
PathfinderDebugOverlay:
WarheadDebugOverlay:
SpawnMapActors:
MPStartLocations:
CreateMPPlayers:
@@ -152,4 +153,3 @@ EditorWorld:
Inherits: ^BaseWorld
EditorActorLayer:
EditorResourceLayer:

View File

@@ -67,6 +67,7 @@ World:
ValidGround: Sand, Dune, Rock
DomainIndex:
PathfinderDebugOverlay:
WarheadDebugOverlay:
BuildableTerrainLayer:
D2kResourceLayer:
ResourceClaimLayer:
@@ -146,4 +147,3 @@ EditorWorld:
Inherits: ^BaseWorld
EditorActorLayer:
D2kEditorResourceLayer:

View File

@@ -118,6 +118,7 @@ World:
ResourceLayer:
ResourceClaimLayer:
PathfinderDebugOverlay:
WarheadDebugOverlay:
SpawnMapActors:
CreateMPPlayers:
MPStartUnits@mcvonly:
@@ -171,4 +172,3 @@ EditorWorld:
Inherits: ^BaseWorld
EditorActorLayer:
EditorResourceLayer:

View File

@@ -97,6 +97,7 @@ World:
ResourceLayer:
ResourceClaimLayer:
PathfinderDebugOverlay:
WarheadDebugOverlay:
SpawnMapActors:
CreateMPPlayers:
MPStartUnits@MCV:
@@ -173,4 +174,3 @@ EditorWorld:
Inherits: ^BaseWorld
EditorActorLayer:
EditorResourceLayer: