Merge pull request #8995 from reaperrr/vxl-upgrades1
Made WithVoxelTurret and WithVoxelBarrel upgradable
This commit is contained in:
@@ -16,19 +16,24 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class WithVoxelBarrelInfo : ITraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>, Requires<ArmamentInfo>, Requires<TurretedInfo>
|
||||
public class WithVoxelBarrelInfo : UpgradableTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>, Requires<ArmamentInfo>, Requires<TurretedInfo>
|
||||
{
|
||||
[Desc("Voxel sequence name to use")]
|
||||
public readonly string Sequence = "barrel";
|
||||
|
||||
[Desc("Armament to use for recoil")]
|
||||
public readonly string Armament = "primary";
|
||||
|
||||
[Desc("Visual offset")]
|
||||
public readonly WVec LocalOffset = WVec.Zero;
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithVoxelBarrel(init.Self, this); }
|
||||
public override object Create(ActorInitializer init) { return new WithVoxelBarrel(init.Self, this); }
|
||||
|
||||
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p)
|
||||
{
|
||||
if (UpgradeMinEnabledLevel > 0)
|
||||
yield break;
|
||||
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var armament = init.Actor.Traits.WithInterface<ArmamentInfo>()
|
||||
.First(a => a.Name == Armament);
|
||||
@@ -46,33 +51,32 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public class WithVoxelBarrel
|
||||
public class WithVoxelBarrel : UpgradableTrait<WithVoxelBarrelInfo>
|
||||
{
|
||||
readonly WithVoxelBarrelInfo info;
|
||||
readonly Actor self;
|
||||
readonly Armament armament;
|
||||
readonly Turreted turreted;
|
||||
readonly IBodyOrientation body;
|
||||
|
||||
public WithVoxelBarrel(Actor self, WithVoxelBarrelInfo info)
|
||||
: base(info)
|
||||
{
|
||||
this.self = self;
|
||||
this.info = info;
|
||||
body = self.Trait<IBodyOrientation>();
|
||||
armament = self.TraitsImplementing<Armament>()
|
||||
.First(a => a.Info.Name == info.Armament);
|
||||
.First(a => a.Info.Name == Info.Armament);
|
||||
turreted = self.TraitsImplementing<Turreted>()
|
||||
.First(tt => tt.Name == armament.Info.Turret);
|
||||
|
||||
var rv = self.Trait<RenderVoxels>();
|
||||
rv.Add(new VoxelAnimation(VoxelProvider.GetVoxel(rv.Image, info.Sequence),
|
||||
rv.Add(new VoxelAnimation(VoxelProvider.GetVoxel(rv.Image, Info.Sequence),
|
||||
BarrelOffset, BarrelRotation,
|
||||
() => false, () => 0));
|
||||
() => IsTraitDisabled, () => 0));
|
||||
}
|
||||
|
||||
WVec BarrelOffset()
|
||||
{
|
||||
var localOffset = info.LocalOffset + new WVec(-armament.Recoil, WDist.Zero, WDist.Zero);
|
||||
var localOffset = Info.LocalOffset + new WVec(-armament.Recoil, WDist.Zero, WDist.Zero);
|
||||
var turretOffset = turreted != null ? turreted.Position(self) : WVec.Zero;
|
||||
var turretOrientation = turreted != null ? turreted.LocalOrientation(self) : WRot.Zero;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class WithVoxelTurretInfo : ITraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>, Requires<TurretedInfo>
|
||||
public class WithVoxelTurretInfo : UpgradableTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>, Requires<TurretedInfo>
|
||||
{
|
||||
[Desc("Voxel sequence name to use")]
|
||||
public readonly string Sequence = "turret";
|
||||
@@ -24,10 +24,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Turreted 'Turret' key to display")]
|
||||
public readonly string Turret = "primary";
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithVoxelTurret(init.Self, this); }
|
||||
public override object Create(ActorInitializer init) { return new WithVoxelTurret(init.Self, this); }
|
||||
|
||||
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p)
|
||||
{
|
||||
if (UpgradeMinEnabledLevel > 0)
|
||||
yield break;
|
||||
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
||||
.First(tt => tt.Turret == Turret);
|
||||
@@ -42,23 +45,24 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public class WithVoxelTurret
|
||||
public class WithVoxelTurret : UpgradableTrait<WithVoxelTurretInfo>
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly Turreted turreted;
|
||||
readonly IBodyOrientation body;
|
||||
|
||||
public WithVoxelTurret(Actor self, WithVoxelTurretInfo info)
|
||||
: base(info)
|
||||
{
|
||||
this.self = self;
|
||||
body = self.Trait<IBodyOrientation>();
|
||||
turreted = self.TraitsImplementing<Turreted>()
|
||||
.First(tt => tt.Name == info.Turret);
|
||||
.First(tt => tt.Name == Info.Turret);
|
||||
|
||||
var rv = self.Trait<RenderVoxels>();
|
||||
rv.Add(new VoxelAnimation(VoxelProvider.GetVoxel(rv.Image, info.Sequence),
|
||||
rv.Add(new VoxelAnimation(VoxelProvider.GetVoxel(rv.Image, Info.Sequence),
|
||||
() => turreted.Position(self), TurretRotation,
|
||||
() => false, () => 0));
|
||||
() => IsTraitDisabled, () => 0));
|
||||
}
|
||||
|
||||
IEnumerable<WRot> TurretRotation()
|
||||
|
||||
Reference in New Issue
Block a user