From e46fc644c18f7d045663ed0f8f022c4aff84f683 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 14 Jan 2016 21:18:56 +0000 Subject: [PATCH] Remove Util.QuantizeFacing from trait code. --- .../Activities/HarvestResource.cs | 4 +++- OpenRA.Mods.Common/Traits/BodyOrientation.cs | 17 ++++++++++++++++- OpenRA.Mods.Common/Traits/Turreted.cs | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/HarvestResource.cs b/OpenRA.Mods.Common/Activities/HarvestResource.cs index e65941369d..e9a49f8207 100644 --- a/OpenRA.Mods.Common/Activities/HarvestResource.cs +++ b/OpenRA.Mods.Common/Activities/HarvestResource.cs @@ -21,12 +21,14 @@ namespace OpenRA.Mods.Common.Activities readonly IFacing facing; readonly ResourceClaimLayer territory; readonly ResourceLayer resLayer; + readonly BodyOrientation body; public HarvestResource(Actor self) { harv = self.Trait(); harvInfo = self.Info.TraitInfo(); facing = self.Trait(); + body = self.Trait(); territory = self.World.WorldActor.TraitOrDefault(); resLayer = self.World.WorldActor.Trait(); } @@ -53,7 +55,7 @@ namespace OpenRA.Mods.Common.Activities if (harvInfo.HarvestFacings != 0) { var current = facing.Facing; - var desired = Util.QuantizeFacing(current, harvInfo.HarvestFacings) * (256 / harvInfo.HarvestFacings); + var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings); if (desired != current) return Util.SequenceActivities(new Turn(self, desired), this); } diff --git a/OpenRA.Mods.Common/Traits/BodyOrientation.cs b/OpenRA.Mods.Common/Traits/BodyOrientation.cs index e7a8287ed4..3418f4362f 100644 --- a/OpenRA.Mods.Common/Traits/BodyOrientation.cs +++ b/OpenRA.Mods.Common/Traits/BodyOrientation.cs @@ -42,12 +42,17 @@ namespace OpenRA.Mods.Common.Traits return orientation; // Map yaw to the closest facing - var facing = Util.QuantizeFacing(orientation.Yaw.Angle / 4, facings) * (256 / facings); + var facing = QuantizeFacing(orientation.Yaw.Angle / 4, facings); // Roll and pitch are always zero if yaw is quantized return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)); } + public int QuantizeFacing(int facing, int facings) + { + return Util.QuantizeFacing(facing, facings) * (256 / facings); + } + public object Create(ActorInitializer init) { return new BodyOrientation(init, this); } } @@ -97,5 +102,15 @@ namespace OpenRA.Mods.Common.Traits { return info.QuantizeOrientation(orientation, quantizedFacings.Value); } + + public int QuantizeFacing(int facing) + { + return info.QuantizeFacing(facing, quantizedFacings.Value); + } + + public int QuantizeFacing(int facing, int facings) + { + return info.QuantizeFacing(facing, facings); + } } } diff --git a/OpenRA.Mods.Common/Traits/Turreted.cs b/OpenRA.Mods.Common/Traits/Turreted.cs index c23ae24c35..246da505e2 100644 --- a/OpenRA.Mods.Common/Traits/Turreted.cs +++ b/OpenRA.Mods.Common/Traits/Turreted.cs @@ -133,7 +133,7 @@ namespace OpenRA.Mods.Common.Traits // Quantize orientation to match a rendered sprite // Implies no pitch or yaw - var facing = Util.QuantizeFacing(local.Yaw.Angle / 4, QuantizedFacings) * (256 / QuantizedFacings); + var facing = body.QuantizeFacing(local.Yaw.Angle / 4, QuantizedFacings); return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)); }