From 4770876fffb3cae524011c0ecf93eef929a00cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 4 Jan 2015 20:19:22 +0100 Subject: [PATCH 1/2] these only store value set in the constructor --- OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs b/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs index c919f3978a..0539673ae6 100644 --- a/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs @@ -30,10 +30,10 @@ namespace OpenRA.Mods.Cnc.Traits public class WithCargo : IRenderModifier { - Cargo cargo; - IFacing facing; - WithCargoInfo cargoInfo; - IBodyOrientation body; + readonly Cargo cargo; + readonly IFacing facing; + readonly WithCargoInfo cargoInfo; + readonly IBodyOrientation body; public WithCargo(Actor self, WithCargoInfo info) { From c250457a34258bc8088475198cb167c872088e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 4 Jan 2015 20:20:14 +0100 Subject: [PATCH 2/2] make this fool proof by choosing a sane default --- OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs b/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs index 0539673ae6..a8e6ddc479 100644 --- a/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs @@ -20,8 +20,9 @@ namespace OpenRA.Mods.Cnc.Traits [Desc("Renders the cargo loaded into the unit.")] public class WithCargoInfo : ITraitInfo, Requires, Requires { - [Desc("Cargo position relative to turret or body. (forward, right, up) triples")] - public readonly WVec[] LocalOffset = { }; + [Desc("Cargo position relative to turret or body in (forward, right, up) triples. The default offset should be in the middle of the list.")] + public readonly WVec[] LocalOffset = { WVec.Zero }; + [Desc("Passenger CargoType to display.")] public readonly string[] DisplayTypes = { }; @@ -42,9 +43,6 @@ namespace OpenRA.Mods.Cnc.Traits cargoInfo = info; body = self.Trait(); - - if (info.LocalOffset.Length == 0) - throw new InvalidOperationException("LocalOffset must have at least one entry"); } public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) @@ -64,7 +62,8 @@ namespace OpenRA.Mods.Cnc.Traits var cargoPassenger = c.Trait(); if (cargoInfo.DisplayTypes.Contains(cargoPassenger.Info.CargoType)) { - var localOffset = cargo.PassengerCount >= 1 ? cargoInfo.LocalOffset[i++ % cargoInfo.LocalOffset.Length] : WVec.Zero; + var index = cargo.PassengerCount > 1 ? i++ % cargoInfo.LocalOffset.Length : cargoInfo.LocalOffset.Length / 2; + var localOffset = cargoInfo.LocalOffset[index]; var offset = pos - c.CenterPosition + body.LocalToWorld(localOffset.Rotate(bodyOrientation)); foreach (var cr in c.Render(wr)) yield return cr.OffsetBy(offset).WithZOffset(1);