Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds Hovers WorldVisualOffset to muzzle calculations #21252

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions OpenRA.Mods.Common/Traits/Armament.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Mods.Common.Traits.Render;
using OpenRA.Traits;

namespace OpenRA.Mods.Common.Traits
Expand Down Expand Up @@ -113,6 +114,8 @@ public class Armament : PausableConditionalTrait<ArmamentInfo>, ITick
public readonly WeaponInfo Weapon;
public readonly Barrel[] Barrels;
Turreted turret;
Hovers hovers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it feels a bit weird to hardcode Hovers here, but I suppose it's fine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it could be implemented via some interface IModifiesMuzzleOffset or something but since it's only trait that does that for now I suppose it's overkill.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't things like slopes and tilting from explosions also need to modify the offset?


BodyOrientation coords;
INotifyBurstComplete[] notifyBurstComplete;
INotifyAttack[] notifyAttacks;
Expand Down Expand Up @@ -168,6 +171,7 @@ public virtual WDist MaxRange()
protected override void Created(Actor self)
{
turret = self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == Info.Turret);
hovers = self.TraitOrDefault<Hovers>();
coords = self.Trait<BodyOrientation>();
notifyBurstComplete = self.TraitsImplementing<INotifyBurstComplete>().ToArray();
notifyAttacks = self.TraitsImplementing<INotifyAttack>().ToArray();
Expand Down Expand Up @@ -389,6 +393,9 @@ protected virtual WVec CalculateMuzzleOffset(Actor self, Barrel b)
// Weapon offset in turret coordinates
var localOffset = b.Offset + new WVec(-Recoil, WDist.Zero, WDist.Zero);

if (hovers != null)
localOffset += hovers.WorldVisualOffset;

// Turret coordinates to body coordinates
var bodyOrientation = coords.QuantizeOrientation(self.Orientation);
if (turret != null)
Expand Down
18 changes: 10 additions & 8 deletions OpenRA.Mods.Common/Traits/Render/Hovers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ public class Hovers : ConditionalTrait<HoversInfo>, IRenderModifier, ITick
readonly int fallTickHeight;

int ticks;
WVec worldVisualOffset;

[Sync]
public WVec WorldVisualOffset { get; private set; }

public Hovers(HoversInfo info)
: base(info)
Expand All @@ -85,11 +87,11 @@ void ITick.Tick(Actor self)
{
if (IsTraitDisabled)
{
if (worldVisualOffset.Z < 0)
if (WorldVisualOffset.Z < 0)
return;

var fallTicks = worldVisualOffset.Z / fallTickHeight - 1;
worldVisualOffset = new WVec(0, 0, fallTickHeight * fallTicks);
var fallTicks = WorldVisualOffset.Z / fallTickHeight - 1;
WorldVisualOffset = new WVec(0, 0, fallTickHeight * fallTicks);
}
else
ticks++;
Expand All @@ -104,13 +106,13 @@ IEnumerable<IRenderable> IRenderModifier.ModifyRender(Actor self, WorldRenderer
var currentHeight = info.BobDistance.Length * visualOffset / 1024 + info.InitialHeight.Length;

// This part rises the actor up from disabled state
if (worldVisualOffset.Z < currentHeight)
currentHeight = Math.Min(worldVisualOffset.Z + info.InitialHeight.Length / info.RiseTicks, currentHeight);
if (WorldVisualOffset.Z < currentHeight)
currentHeight = Math.Min(WorldVisualOffset.Z + info.InitialHeight.Length / info.RiseTicks, currentHeight);

worldVisualOffset = new WVec(0, 0, currentHeight);
WorldVisualOffset = new WVec(0, 0, currentHeight);
}

return r.Select(a => a.OffsetBy(worldVisualOffset));
return r.Select(a => a.OffsetBy(WorldVisualOffset));
}

IEnumerable<Rectangle> IRenderModifier.ModifyScreenBounds(Actor self, WorldRenderer wr, IEnumerable<Rectangle> bounds)
Expand Down