diff --git a/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs b/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs index c919f3978a..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 = { }; @@ -30,10 +31,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) { @@ -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);