Merge pull request #7273 from Mailaender/with-cargo-fix
Fixed WithCargo
This commit is contained in:
@@ -20,8 +20,9 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
[Desc("Renders the cargo loaded into the unit.")]
|
[Desc("Renders the cargo loaded into the unit.")]
|
||||||
public class WithCargoInfo : ITraitInfo, Requires<CargoInfo>, Requires<IBodyOrientationInfo>
|
public class WithCargoInfo : ITraitInfo, Requires<CargoInfo>, Requires<IBodyOrientationInfo>
|
||||||
{
|
{
|
||||||
[Desc("Cargo position relative to turret or body. (forward, right, up) triples")]
|
[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 = { };
|
public readonly WVec[] LocalOffset = { WVec.Zero };
|
||||||
|
|
||||||
[Desc("Passenger CargoType to display.")]
|
[Desc("Passenger CargoType to display.")]
|
||||||
public readonly string[] DisplayTypes = { };
|
public readonly string[] DisplayTypes = { };
|
||||||
|
|
||||||
@@ -30,10 +31,10 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
|
|
||||||
public class WithCargo : IRenderModifier
|
public class WithCargo : IRenderModifier
|
||||||
{
|
{
|
||||||
Cargo cargo;
|
readonly Cargo cargo;
|
||||||
IFacing facing;
|
readonly IFacing facing;
|
||||||
WithCargoInfo cargoInfo;
|
readonly WithCargoInfo cargoInfo;
|
||||||
IBodyOrientation body;
|
readonly IBodyOrientation body;
|
||||||
|
|
||||||
public WithCargo(Actor self, WithCargoInfo info)
|
public WithCargo(Actor self, WithCargoInfo info)
|
||||||
{
|
{
|
||||||
@@ -42,9 +43,6 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
cargoInfo = info;
|
cargoInfo = info;
|
||||||
|
|
||||||
body = self.Trait<IBodyOrientation>();
|
body = self.Trait<IBodyOrientation>();
|
||||||
|
|
||||||
if (info.LocalOffset.Length == 0)
|
|
||||||
throw new InvalidOperationException("LocalOffset must have at least one entry");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
|
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
|
||||||
@@ -64,7 +62,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
var cargoPassenger = c.Trait<Passenger>();
|
var cargoPassenger = c.Trait<Passenger>();
|
||||||
if (cargoInfo.DisplayTypes.Contains(cargoPassenger.Info.CargoType))
|
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));
|
var offset = pos - c.CenterPosition + body.LocalToWorld(localOffset.Rotate(bodyOrientation));
|
||||||
foreach (var cr in c.Render(wr))
|
foreach (var cr in c.Render(wr))
|
||||||
yield return cr.OffsetBy(offset).WithZOffset(1);
|
yield return cr.OffsetBy(offset).WithZOffset(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user