Add ActorMapOverlay
This commit is contained in:
committed by
Gustas Kažukauskas
parent
3f19c81392
commit
7004b552c9
94
OpenRA.Mods.Common/Traits/World/ActorMapOverlay.cs
Normal file
94
OpenRA.Mods.Common/Traits/World/ActorMapOverlay.cs
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright (c) The OpenRA Developers and Contributors
|
||||||
|
* 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, either version 3 of
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.Common.Commands;
|
||||||
|
using OpenRA.Mods.Common.Graphics;
|
||||||
|
using OpenRA.Primitives;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
[TraitLocation(SystemActors.World)]
|
||||||
|
[IncludeStaticFluentReferences(typeof(ActorMapOverlay))]
|
||||||
|
[Desc("Renders a debug overlay showing the actor influence map. Attach this to the world actor.")]
|
||||||
|
public class ActorMapOverlayInfo : TraitInfo<ActorMapOverlay>, Requires<ActorMapInfo> { }
|
||||||
|
|
||||||
|
public class ActorMapOverlay : IRenderAnnotations, IWorldLoaded, IChatCommand
|
||||||
|
{
|
||||||
|
const string CommandName = "actor-map";
|
||||||
|
|
||||||
|
[FluentReference]
|
||||||
|
const string CommandDescription = "description-actor-map-overlay";
|
||||||
|
|
||||||
|
public bool Enabled;
|
||||||
|
|
||||||
|
void IWorldLoaded.WorldLoaded(World w, WorldRenderer wr)
|
||||||
|
{
|
||||||
|
var console = w.WorldActor.TraitOrDefault<ChatCommands>();
|
||||||
|
var help = w.WorldActor.TraitOrDefault<HelpCommand>();
|
||||||
|
|
||||||
|
if (console == null || help == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
console.RegisterCommand(CommandName, this);
|
||||||
|
help.RegisterHelp(CommandName, CommandDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IChatCommand.InvokeCommand(string name, string arg)
|
||||||
|
{
|
||||||
|
if (name == CommandName)
|
||||||
|
Enabled = !Enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerable<IRenderable> IRenderAnnotations.RenderAnnotations(Actor self, WorldRenderer wr)
|
||||||
|
{
|
||||||
|
if (!Enabled)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
var map = wr.World.Map;
|
||||||
|
|
||||||
|
// Only get actors in actor map.
|
||||||
|
// Cull to visible cells while we are at it.
|
||||||
|
var actorsInBox = new HashSet<Actor>(100);
|
||||||
|
foreach (var mpos in wr.Viewport.AllVisibleCells.CandidateMapCoords)
|
||||||
|
actorsInBox.UnionWith(wr.World.ActorMap.GetActorsAt(mpos.ToCPos(map)));
|
||||||
|
|
||||||
|
foreach (var actor in actorsInBox)
|
||||||
|
{
|
||||||
|
if (actor.OccupiesSpace is not IOccupySpace space)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (var (cell, subCell) in space.OccupiedCells())
|
||||||
|
{
|
||||||
|
var pos = map.CenterOfSubCell(cell, subCell);
|
||||||
|
var fullCell = subCell == SubCell.FullCell;
|
||||||
|
|
||||||
|
Color color;
|
||||||
|
color = fullCell ? Color.Red : wr.World.ActorMap.HasFreeSubCell(cell, false) ? Color.Yellow : Color.Orange;
|
||||||
|
|
||||||
|
var ramp = map.Ramp[cell];
|
||||||
|
var corners = map.Grid.Ramps[ramp].Corners;
|
||||||
|
for (var i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
var j = (i + 1) % 4;
|
||||||
|
var start = pos + corners[i] / (fullCell ? 1 : 2);
|
||||||
|
var end = pos + corners[j] / (fullCell ? 1 : 2);
|
||||||
|
yield return new LineAnnotationRenderable(start, end, 2, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IRenderAnnotations.SpatiallyPartitionable => false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -156,6 +156,7 @@ World:
|
|||||||
PathFinderOverlay:
|
PathFinderOverlay:
|
||||||
AutoSave:
|
AutoSave:
|
||||||
HierarchicalPathFinderOverlay:
|
HierarchicalPathFinderOverlay:
|
||||||
|
ActorMapOverlay:
|
||||||
PlayerCommands:
|
PlayerCommands:
|
||||||
HelpCommand:
|
HelpCommand:
|
||||||
ScreenShaker:
|
ScreenShaker:
|
||||||
|
|||||||
@@ -758,6 +758,9 @@ description-path-debug-overlay = toggles a visualization of path searching.
|
|||||||
## TerrainGeometryOverlay
|
## TerrainGeometryOverlay
|
||||||
description-terrain-geometry-overlay = toggles the terrain geometry overlay.
|
description-terrain-geometry-overlay = toggles the terrain geometry overlay.
|
||||||
|
|
||||||
|
## ActorMapOverlay
|
||||||
|
description-actor-map-overlay = toggles the actor map overlay.
|
||||||
|
|
||||||
## MapOptions, MissionBrowserLogic
|
## MapOptions, MissionBrowserLogic
|
||||||
options-game-speed =
|
options-game-speed =
|
||||||
.slowest = Slowest
|
.slowest = Slowest
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ World:
|
|||||||
DebugVisualizationCommands:
|
DebugVisualizationCommands:
|
||||||
PathFinderOverlay:
|
PathFinderOverlay:
|
||||||
HierarchicalPathFinderOverlay:
|
HierarchicalPathFinderOverlay:
|
||||||
|
ActorMapOverlay:
|
||||||
PlayerCommands:
|
PlayerCommands:
|
||||||
HelpCommand:
|
HelpCommand:
|
||||||
AutoSave:
|
AutoSave:
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ World:
|
|||||||
DebugVisualizationCommands:
|
DebugVisualizationCommands:
|
||||||
PathFinderOverlay:
|
PathFinderOverlay:
|
||||||
HierarchicalPathFinderOverlay:
|
HierarchicalPathFinderOverlay:
|
||||||
|
ActorMapOverlay:
|
||||||
PlayerCommands:
|
PlayerCommands:
|
||||||
HelpCommand:
|
HelpCommand:
|
||||||
ScreenShaker:
|
ScreenShaker:
|
||||||
|
|||||||
@@ -239,6 +239,7 @@ World:
|
|||||||
DebugVisualizationCommands:
|
DebugVisualizationCommands:
|
||||||
PathFinderOverlay:
|
PathFinderOverlay:
|
||||||
HierarchicalPathFinderOverlay:
|
HierarchicalPathFinderOverlay:
|
||||||
|
ActorMapOverlay:
|
||||||
PlayerCommands:
|
PlayerCommands:
|
||||||
HelpCommand:
|
HelpCommand:
|
||||||
BuildingInfluence:
|
BuildingInfluence:
|
||||||
|
|||||||
Reference in New Issue
Block a user