diff --git a/OpenRA.Game/Graphics/Renderable.cs b/OpenRA.Game/Graphics/Renderable.cs
index 5d4c85396f..bb6924b13f 100644
--- a/OpenRA.Game/Graphics/Renderable.cs
+++ b/OpenRA.Game/Graphics/Renderable.cs
@@ -52,15 +52,6 @@ namespace OpenRA.Graphics
public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, newOffset, Palette, Scale); }
public Renderable WithPos(WPos pos) { return new Renderable(Sprite, pos, ZOffset, Palette, Scale); }
- // Transitional hack
- public Renderable WithPxOffset(float2 offset)
- {
- var x = (int)(Pos.X * Game.CellSize / 1024 + offset.X);
- var y = (int)(Pos.Y * Game.CellSize / 1024 + offset.Y);
- var z = (int)(Pos.Z * Game.CellSize / 1024);
- return new Renderable(Sprite, new PPos(x,y).ToWPos(z), ZOffset, Palette, Scale);
- }
-
public void Render(WorldRenderer wr)
{
Sprite.DrawAt(wr.ScreenPxPosition(Pos) - 0.5f*Scale*Sprite.size, Palette.Index, Scale);
diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj
index 710b030414..4a6755178c 100644
--- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj
+++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj
@@ -86,7 +86,7 @@
-
+
diff --git a/OpenRA.Mods.Cnc/RenderCargo.cs b/OpenRA.Mods.Cnc/RenderCargo.cs
deleted file mode 100644
index 14c7bf7c3c..0000000000
--- a/OpenRA.Mods.Cnc/RenderCargo.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-#region Copyright & License Information
-/*
- * Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
- * 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. For more information,
- * see COPYING.
- */
-#endregion
-
-using System.Collections.Generic;
-using System.Linq;
-using OpenRA.Mods.RA;
-using OpenRA.Graphics;
-using OpenRA.Traits;
-
-namespace OpenRA.Mods.Cnc
-{
- public class RenderCargoInfo : ITraitInfo, Requires
- {
- /* altitude of the cargo, relative to us. -ve is underneath us */
- public readonly int RelativeAltitude = 0;
- public readonly string[] PassengerTypes;
-
- public object Create(ActorInitializer init) { return new RenderCargo(init.self, this); }
- }
-
- public class RenderCargo : IRenderModifier
- {
- Cargo cargo;
- IFacing facing;
- IMove move;
- RenderCargoInfo Info;
-
- public RenderCargo(Actor self, RenderCargoInfo info)
- {
- cargo = self.Trait();
- facing = self.TraitOrDefault();
- move = self.Trait();
- Info = info;
- }
-
- public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r)
- {
- foreach (var c in cargo.Passengers)
- {
- c.Trait().SetPxPosition( c, move.PxPosition );
-
- var cargoFacing = c.TraitOrDefault();
- if (facing != null && cargoFacing != null)
- cargoFacing.Facing = facing.Facing;
- }
-
- var visiblePassengers = (Info.PassengerTypes != null && Info.PassengerTypes.Length > 0)
- ? cargo.Passengers.Where(p =>
- Info.PassengerTypes.Contains(p.Trait().info.CargoType))
- : cargo.Passengers;
-
- return r.Concat(visiblePassengers.SelectMany(a => a.Render(wr))
- .Select(a => a.WithPxOffset(new float2(0, -Info.RelativeAltitude))
- .WithZOffset(a.ZOffset + Info.RelativeAltitude)));
- }
- }
-}
\ No newline at end of file
diff --git a/OpenRA.Mods.Cnc/WithCargo.cs b/OpenRA.Mods.Cnc/WithCargo.cs
new file mode 100644
index 0000000000..590f578a44
--- /dev/null
+++ b/OpenRA.Mods.Cnc/WithCargo.cs
@@ -0,0 +1,78 @@
+#region Copyright & License Information
+/*
+ * Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
+ * 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. For more information,
+ * see COPYING.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using OpenRA.FileFormats;
+using OpenRA.Graphics;
+using OpenRA.Mods.RA;
+using OpenRA.Traits;
+
+namespace OpenRA.Mods.Cnc
+{
+ public class WithCargoInfo : ITraitInfo, Requires, Requires
+ {
+ [Desc("Cargo position relative to turret or body. (forward, right, up) triples")]
+ public readonly WRange[] LocalOffset = {};
+ public readonly string[] DisplayTypes = {};
+
+ public object Create(ActorInitializer init) { return new WithCargo(init.self, this); }
+ }
+
+ public class WithCargo : IRenderModifier
+ {
+ Cargo cargo;
+ IFacing facing;
+ WithCargoInfo Info;
+ WVec[] positions;
+ ILocalCoordinatesModel coords;
+
+ public WithCargo(Actor self, WithCargoInfo info)
+ {
+ cargo = self.Trait();
+ facing = self.TraitOrDefault();
+ Info = info;
+
+ coords = self.Trait();
+
+ if (info.LocalOffset.Length % 3 != 0)
+ throw new InvalidOperationException("Invalid LocalOffset array length");
+
+ positions = new WVec[info.LocalOffset.Length / 3];
+ for (var i = 0; i < info.LocalOffset.Length / 3; i++)
+ positions[i] = new WVec(info.LocalOffset[3*i], info.LocalOffset[3*i + 1], info.LocalOffset[3*i + 2]);
+ }
+
+ public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r)
+ {
+ foreach (var rr in r)
+ yield return rr;
+
+ var bodyOrientation = coords.QuantizeOrientation(self, self.Orientation);
+ var pos = self.CenterPosition;
+ int i = 0;
+ foreach (var c in cargo.Passengers)
+ {
+ var cargoFacing = c.TraitOrDefault();
+ if (facing != null && cargoFacing != null)
+ cargoFacing.Facing = facing.Facing;
+
+ var cargoPassenger = c.Trait();
+ if (Info.DisplayTypes.Contains(cargoPassenger.info.CargoType))
+ {
+ var offset = pos - c.CenterPosition + coords.LocalToWorld(positions[i++ % positions.Length].Rotate(bodyOrientation));
+ foreach (var cr in c.Render(wr))
+ yield return cr.WithPos(cr.Pos + offset).WithZOffset(1);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/mods/cnc/rules/ships.yaml b/mods/cnc/rules/ships.yaml
index 1c32716775..de7e133560 100644
--- a/mods/cnc/rules/ships.yaml
+++ b/mods/cnc/rules/ships.yaml
@@ -56,7 +56,9 @@ LST:
Range: 7
RenderUnit:
WithRoof:
- RenderCargo:
+ WithCargo:
+ DisplayTypes: Infantry, Vehicle
+ LocalOffset: 0,0,0, -390,-256,0, 390,-256,0, -390,256,0, 390,256,0
-Selectable:
Cargo:
Types: Infantry, Vehicle
diff --git a/mods/d2k/rules/aircraft.yaml b/mods/d2k/rules/aircraft.yaml
index fbc47f7fd2..9abb1c113c 100644
--- a/mods/d2k/rules/aircraft.yaml
+++ b/mods/d2k/rules/aircraft.yaml
@@ -21,8 +21,8 @@
RearmBuildings: starporta,starporto,starporth
MinimalLandAltitude: 25
RenderUnit:
- RenderCargo:
- RelativeAltitude: 20
+ WithCargo:
+ LocalOffset: 0,0,-854
WithShadow:
Cargo:
Types: Vehicle