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
|
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")]
|
[Desc("Voxel sequence name to use")]
|
||||||
public readonly string Sequence = "barrel";
|
public readonly string Sequence = "barrel";
|
||||||
|
|
||||||
[Desc("Armament to use for recoil")]
|
[Desc("Armament to use for recoil")]
|
||||||
public readonly string Armament = "primary";
|
public readonly string Armament = "primary";
|
||||||
|
|
||||||
[Desc("Visual offset")]
|
[Desc("Visual offset")]
|
||||||
public readonly WVec LocalOffset = WVec.Zero;
|
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)
|
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 body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||||
var armament = init.Actor.Traits.WithInterface<ArmamentInfo>()
|
var armament = init.Actor.Traits.WithInterface<ArmamentInfo>()
|
||||||
.First(a => a.Name == Armament);
|
.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 Actor self;
|
||||||
readonly Armament armament;
|
readonly Armament armament;
|
||||||
readonly Turreted turreted;
|
readonly Turreted turreted;
|
||||||
readonly IBodyOrientation body;
|
readonly IBodyOrientation body;
|
||||||
|
|
||||||
public WithVoxelBarrel(Actor self, WithVoxelBarrelInfo info)
|
public WithVoxelBarrel(Actor self, WithVoxelBarrelInfo info)
|
||||||
|
: base(info)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
this.info = info;
|
|
||||||
body = self.Trait<IBodyOrientation>();
|
body = self.Trait<IBodyOrientation>();
|
||||||
armament = self.TraitsImplementing<Armament>()
|
armament = self.TraitsImplementing<Armament>()
|
||||||
.First(a => a.Info.Name == info.Armament);
|
.First(a => a.Info.Name == Info.Armament);
|
||||||
turreted = self.TraitsImplementing<Turreted>()
|
turreted = self.TraitsImplementing<Turreted>()
|
||||||
.First(tt => tt.Name == armament.Info.Turret);
|
.First(tt => tt.Name == armament.Info.Turret);
|
||||||
|
|
||||||
var rv = self.Trait<RenderVoxels>();
|
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,
|
BarrelOffset, BarrelRotation,
|
||||||
() => false, () => 0));
|
() => IsTraitDisabled, () => 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
WVec BarrelOffset()
|
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 turretOffset = turreted != null ? turreted.Position(self) : WVec.Zero;
|
||||||
var turretOrientation = turreted != null ? turreted.LocalOrientation(self) : WRot.Zero;
|
var turretOrientation = turreted != null ? turreted.LocalOrientation(self) : WRot.Zero;
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.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")]
|
[Desc("Voxel sequence name to use")]
|
||||||
public readonly string Sequence = "turret";
|
public readonly string Sequence = "turret";
|
||||||
@@ -24,10 +24,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Turreted 'Turret' key to display")]
|
[Desc("Turreted 'Turret' key to display")]
|
||||||
public readonly string Turret = "primary";
|
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)
|
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 body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
||||||
.First(tt => tt.Turret == Turret);
|
.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 Actor self;
|
||||||
readonly Turreted turreted;
|
readonly Turreted turreted;
|
||||||
readonly IBodyOrientation body;
|
readonly IBodyOrientation body;
|
||||||
|
|
||||||
public WithVoxelTurret(Actor self, WithVoxelTurretInfo info)
|
public WithVoxelTurret(Actor self, WithVoxelTurretInfo info)
|
||||||
|
: base(info)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
body = self.Trait<IBodyOrientation>();
|
body = self.Trait<IBodyOrientation>();
|
||||||
turreted = self.TraitsImplementing<Turreted>()
|
turreted = self.TraitsImplementing<Turreted>()
|
||||||
.First(tt => tt.Name == info.Turret);
|
.First(tt => tt.Name == Info.Turret);
|
||||||
|
|
||||||
var rv = self.Trait<RenderVoxels>();
|
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,
|
() => turreted.Position(self), TurretRotation,
|
||||||
() => false, () => 0));
|
() => IsTraitDisabled, () => 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<WRot> TurretRotation()
|
IEnumerable<WRot> TurretRotation()
|
||||||
|
|||||||
Reference in New Issue
Block a user