From f25398c731c4aeca57df7460e11d033c80c71644 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Sat, 28 May 2016 23:57:49 +0200 Subject: [PATCH] Add option to apply Rectangle HitShape to all TargetablePositions This allows to simulate a footprint-shaped HitShape until we have a proper Polygon HitShape. --- OpenRA.Mods.Common/HitShapes/Rectangle.cs | 34 ++++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/HitShapes/Rectangle.cs b/OpenRA.Mods.Common/HitShapes/Rectangle.cs index 798e01b90f..10d5d2f960 100644 --- a/OpenRA.Mods.Common/HitShapes/Rectangle.cs +++ b/OpenRA.Mods.Common/HitShapes/Rectangle.cs @@ -38,6 +38,10 @@ namespace OpenRA.Mods.Common.HitShapes "Mobile actors do NOT need this!")] public readonly bool RotateToIsometry = false; + // This is just a temporary work-around until we have a customizable PolygonShape + [Desc("Applies shape to every TargetablePosition instead of just CenterPosition.")] + public readonly bool ApplyToAllTargetablePositions = false; + int2 quadrantSize; int2 center; @@ -97,6 +101,13 @@ namespace OpenRA.Mods.Common.HitShapes var orientation = new WRot(actor.Orientation.Roll, actor.Orientation.Pitch, new WAngle(actor.Orientation.Yaw.Angle + (RotateToIsometry ? 128 : 0))); + var targetablePositions = actor.TraitsImplementing(); + if (ApplyToAllTargetablePositions && targetablePositions.Any()) + { + var positions = targetablePositions.SelectMany(tp => tp.TargetablePositions(actor)); + actorPos = positions.PositionClosestTo(pos); + } + if (pos.Z > actorPos.Z + VerticalTopOffset) return DistanceFromEdge((pos - (actorPos + new WVec(0, 0, VerticalTopOffset))).Rotate(-orientation)); @@ -112,10 +123,25 @@ namespace OpenRA.Mods.Common.HitShapes var orientation = new WRot(actor.Orientation.Roll, actor.Orientation.Pitch, new WAngle(actor.Orientation.Yaw.Angle + (RotateToIsometry ? 128 : 0))); - var vertsTop = combatOverlayVertsTop.Select(v => wr.ScreenPosition(actorPos + v.Rotate(orientation))); - var vertsBottom = combatOverlayVertsBottom.Select(v => wr.ScreenPosition(actorPos + v.Rotate(orientation))); - wcr.DrawPolygon(vertsTop.ToArray(), 1, Color.Yellow); - wcr.DrawPolygon(vertsBottom.ToArray(), 1, Color.Yellow); + var targetablePositions = actor.TraitsImplementing(); + if (ApplyToAllTargetablePositions && targetablePositions.Any()) + { + var positions = targetablePositions.SelectMany(tp => tp.TargetablePositions(actor)); + foreach (var pos in positions) + { + var vertsTop = combatOverlayVertsTop.Select(v => wr.ScreenPosition(pos + v.Rotate(orientation))); + var vertsBottom = combatOverlayVertsBottom.Select(v => wr.ScreenPosition(pos + v.Rotate(orientation))); + wcr.DrawPolygon(vertsTop.ToArray(), 1, Color.Yellow); + wcr.DrawPolygon(vertsBottom.ToArray(), 1, Color.Yellow); + } + } + else + { + var vertsTop = combatOverlayVertsTop.Select(v => wr.ScreenPosition(actorPos + v.Rotate(orientation))); + var vertsBottom = combatOverlayVertsBottom.Select(v => wr.ScreenPosition(actorPos + v.Rotate(orientation))); + wcr.DrawPolygon(vertsTop.ToArray(), 1, Color.Yellow); + wcr.DrawPolygon(vertsBottom.ToArray(), 1, Color.Yellow); + } } } }