adds Hovers WorldVisualOffset to muzzle calculations

This commit is contained in:
Wojciech Walaszek
2023-12-12 12:30:32 +01:00
committed by Gustas
parent 9a1823d805
commit 680144b24f
2 changed files with 17 additions and 8 deletions

View File

@@ -13,6 +13,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Mods.Common.Traits.Render;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
@@ -113,6 +114,8 @@ namespace OpenRA.Mods.Common.Traits
public readonly WeaponInfo Weapon; public readonly WeaponInfo Weapon;
public readonly Barrel[] Barrels; public readonly Barrel[] Barrels;
Turreted turret; Turreted turret;
Hovers hovers;
BodyOrientation coords; BodyOrientation coords;
INotifyBurstComplete[] notifyBurstComplete; INotifyBurstComplete[] notifyBurstComplete;
INotifyAttack[] notifyAttacks; INotifyAttack[] notifyAttacks;
@@ -168,6 +171,7 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self) protected override void Created(Actor self)
{ {
turret = self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == Info.Turret); turret = self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == Info.Turret);
hovers = self.TraitOrDefault<Hovers>();
coords = self.Trait<BodyOrientation>(); coords = self.Trait<BodyOrientation>();
notifyBurstComplete = self.TraitsImplementing<INotifyBurstComplete>().ToArray(); notifyBurstComplete = self.TraitsImplementing<INotifyBurstComplete>().ToArray();
notifyAttacks = self.TraitsImplementing<INotifyAttack>().ToArray(); notifyAttacks = self.TraitsImplementing<INotifyAttack>().ToArray();
@@ -389,6 +393,9 @@ namespace OpenRA.Mods.Common.Traits
// Weapon offset in turret coordinates // Weapon offset in turret coordinates
var localOffset = b.Offset + new WVec(-Recoil, WDist.Zero, WDist.Zero); var localOffset = b.Offset + new WVec(-Recoil, WDist.Zero, WDist.Zero);
if (hovers != null)
localOffset += hovers.WorldVisualOffset;
// Turret coordinates to body coordinates // Turret coordinates to body coordinates
var bodyOrientation = coords.QuantizeOrientation(self.Orientation); var bodyOrientation = coords.QuantizeOrientation(self.Orientation);
if (turret != null) if (turret != null)

View File

@@ -69,7 +69,9 @@ namespace OpenRA.Mods.Common.Traits.Render
readonly int fallTickHeight; readonly int fallTickHeight;
int ticks; int ticks;
WVec worldVisualOffset;
[Sync]
public WVec WorldVisualOffset { get; private set; }
public Hovers(HoversInfo info) public Hovers(HoversInfo info)
: base(info) : base(info)
@@ -85,11 +87,11 @@ namespace OpenRA.Mods.Common.Traits.Render
{ {
if (IsTraitDisabled) if (IsTraitDisabled)
{ {
if (worldVisualOffset.Z < 0) if (WorldVisualOffset.Z < 0)
return; return;
var fallTicks = worldVisualOffset.Z / fallTickHeight - 1; var fallTicks = WorldVisualOffset.Z / fallTickHeight - 1;
worldVisualOffset = new WVec(0, 0, fallTickHeight * fallTicks); WorldVisualOffset = new WVec(0, 0, fallTickHeight * fallTicks);
} }
else else
ticks++; ticks++;
@@ -104,13 +106,13 @@ namespace OpenRA.Mods.Common.Traits.Render
var currentHeight = info.BobDistance.Length * visualOffset / 1024 + info.InitialHeight.Length; var currentHeight = info.BobDistance.Length * visualOffset / 1024 + info.InitialHeight.Length;
// This part rises the actor up from disabled state // This part rises the actor up from disabled state
if (worldVisualOffset.Z < currentHeight) if (WorldVisualOffset.Z < currentHeight)
currentHeight = Math.Min(worldVisualOffset.Z + info.InitialHeight.Length / info.RiseTicks, 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) IEnumerable<Rectangle> IRenderModifier.ModifyScreenBounds(Actor self, WorldRenderer wr, IEnumerable<Rectangle> bounds)