Skip to content

Commit cace503

Browse files
committed
invasive and illogical changes so InheritedRotAngleOffset works for mounted devices
1 parent dc4d4bf commit cace503

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

Data/Browncoats.rte/Actors/Turrets/Thunderer/ThundererGun.lua

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function Create(self)
5858

5959
self.reloadSmokeTimer = Timer();
6060

61-
self.rotationSpeed = 0.10;
61+
self.rotationSpeed = 0.08;
6262
self.smoothedRotAngle = self.RotAngle;
6363
self.InheritedRotAngleTarget = 0;
6464

@@ -76,26 +76,28 @@ function Update(self)
7676

7777
-- reticule of actual aim line so the gun feels cannon-y rather than unresponsive
7878

79+
local actingRotAngle = self.RotAngle - self.InheritedRotAngleOffset;
80+
7981
if self.playerControlled and self.parent.SharpAimProgress > 0.13 then
8082
for i = 1, 24 do
8183
if i % 3 == 0 then
82-
local dotVec = Vector(i*self.FlipFactor, 0):RadRotate(self.RotAngle) + self.Pos + Vector((self.SharpLength + 15) * self.FlipFactor, 0):RadRotate(self.RotAngle)*self.parent.SharpAimProgress;
84+
local dotVec = Vector(i*self.FlipFactor, 0):RadRotate(actingRotAngle) + self.Pos + Vector((self.SharpLength + 15) * self.FlipFactor, 0):RadRotate(actingRotAngle)*self.parent.SharpAimProgress;
8385
PrimitiveMan:DrawLinePrimitive(dotVec, dotVec, 116, 2);
8486
end
8587
end
8688
end
8789
-- rotation smoothing, for a cannon-y feel:
8890

89-
if self.smoothedRotAngle ~= self.RotAngle then
90-
self.smoothedRotAngle = self.smoothedRotAngle - (self.rotationSpeed * (self.smoothedRotAngle - self.RotAngle));
91+
if self.smoothedRotAngle ~= actingRotAngle then
92+
self.smoothedRotAngle = self.smoothedRotAngle - (self.rotationSpeed * (self.smoothedRotAngle - (actingRotAngle)));
9193
end
9294

93-
-- self.servoLoopSoundVolumeTarget = 0 + math.abs(self.smoothedRotAngle - self.RotAngle)
94-
-- self.servoLoopSound.Volume = self.servoLoopSound.Volume - (0.5 * (self.servoLoopSound.Volume - self.servoLoopSoundVolumeTarget));
95-
-- self.servoLoopSoundPitchTarget = 1 + math.abs(self.smoothedRotAngle - self.RotAngle)
96-
-- self.servoLoopSound.Pitch = self.servoLoopSound.Pitch - (0.1 * (self.servoLoopSound.Pitch - self.servoLoopSoundPitchTarget));
95+
--self.servoLoopSoundVolumeTarget = 0 + math.abs(self.smoothedRotAngle - actingRotAngle)
96+
--self.servoLoopSound.Volume = self.servoLoopSound.Volume - (0.5 * (self.servoLoopSound.Volume - self.servoLoopSoundVolumeTarget));
97+
--self.servoLoopSoundPitchTarget = 1 + math.abs(self.smoothedRotAngle - actingRotAngle)
98+
--self.servoLoopSound.Pitch = self.servoLoopSound.Pitch - (0.1 * (self.servoLoopSound.Pitch - self.servoLoopSoundPitchTarget));
9799

98-
self.InheritedRotAngleOffset = self.smoothedRotAngle - self.RotAngle;
100+
self.InheritedRotAngleOffset = self.smoothedRotAngle - actingRotAngle;
99101

100102
if self:DoneReloading() then
101103
self.currentBaseFrame = 0;

Data/Coalition.rte/Actors/Turrets/BunkerCannon/BunkerCannonGun.lua

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function Create(self)
4444

4545
self.reloadSmokeTimer = Timer();
4646

47-
self.rotationSpeed = 0.10;
47+
self.rotationSpeed = 0.04;
4848
self.smoothedRotAngle = self.RotAngle;
4949
self.InheritedRotAngleTarget = 0;
5050

@@ -66,26 +66,28 @@ function Update(self)
6666

6767
-- reticule of actual aim line so the gun feels cannon-y rather than unresponsive
6868

69+
local actingRotAngle = self.RotAngle - self.InheritedRotAngleOffset;
70+
6971
if self.playerControlled and self.parent.SharpAimProgress > 0.13 then
7072
for i = 1, 24 do
7173
if i % 3 == 0 then
72-
local dotVec = Vector(i*self.FlipFactor, 0):RadRotate(self.RotAngle) + self.Pos + Vector((self.SharpLength + 15) * self.FlipFactor, 0):RadRotate(self.RotAngle)*self.parent.SharpAimProgress;
74+
local dotVec = Vector(i*self.FlipFactor, 0):RadRotate(actingRotAngle) + self.Pos + Vector((self.SharpLength + 15) * self.FlipFactor, 0):RadRotate(actingRotAngle)*self.parent.SharpAimProgress;
7375
PrimitiveMan:DrawLinePrimitive(dotVec, dotVec, 116, 2);
7476
end
7577
end
7678
end
7779
-- rotation smoothing, for a cannon-y feel:
7880

79-
if self.smoothedRotAngle ~= self.RotAngle then
80-
self.smoothedRotAngle = self.smoothedRotAngle - (self.rotationSpeed * (self.smoothedRotAngle - self.RotAngle));
81+
if self.smoothedRotAngle ~= actingRotAngle then
82+
self.smoothedRotAngle = self.smoothedRotAngle - (self.rotationSpeed * (self.smoothedRotAngle - (actingRotAngle)));
8183
end
8284

83-
self.servoLoopSoundVolumeTarget = 0 + math.abs(self.smoothedRotAngle - self.RotAngle)
85+
self.servoLoopSoundVolumeTarget = 0 + math.abs(self.smoothedRotAngle - actingRotAngle)
8486
self.servoLoopSound.Volume = self.servoLoopSound.Volume - (0.5 * (self.servoLoopSound.Volume - self.servoLoopSoundVolumeTarget));
85-
self.servoLoopSoundPitchTarget = 1 + math.abs(self.smoothedRotAngle - self.RotAngle)
87+
self.servoLoopSoundPitchTarget = 1 + math.abs(self.smoothedRotAngle - actingRotAngle)
8688
self.servoLoopSound.Pitch = self.servoLoopSound.Pitch - (0.1 * (self.servoLoopSound.Pitch - self.servoLoopSoundPitchTarget));
8789

88-
self.InheritedRotAngleOffset = self.smoothedRotAngle - self.RotAngle;
90+
self.InheritedRotAngleOffset = self.smoothedRotAngle - actingRotAngle;
8991

9092
-- Mathemagical firing anim by filipex
9193
local f = math.max(1 - math.min((self.FireTimer.ElapsedSimTimeMS) / 200, 1), 0)

Source/Entities/Attachable.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void Attachable::Clear() {
4646
m_InheritsHFlipped = 1;
4747
m_InheritsRotAngle = true;
4848
m_InheritedRotAngleOffset = 0;
49+
m_MountedRotAngleOffset = 0.0F;
4950
m_InheritsFrame = false;
5051

5152
m_AtomSubgroupID = -1L;
@@ -95,6 +96,7 @@ int Attachable::Create(const Attachable& reference) {
9596
m_InheritsHFlipped = reference.m_InheritsHFlipped;
9697
m_InheritsRotAngle = reference.m_InheritsRotAngle;
9798
m_InheritedRotAngleOffset = reference.m_InheritedRotAngleOffset;
99+
m_MountedRotAngleOffset = reference.m_MountedRotAngleOffset;
98100
m_InheritsFrame = reference.m_InheritsFrame;
99101

100102
m_AtomSubgroupID = GetUniqueID();
@@ -143,6 +145,7 @@ int Attachable::ReadProperty(const std::string_view& propName, Reader& reader) {
143145
MatchProperty("InheritsRotAngle", { reader >> m_InheritsRotAngle; });
144146
MatchForwards("InheritedRotAngleRadOffset") MatchProperty("InheritedRotAngleOffset", { reader >> m_InheritedRotAngleOffset; });
145147
MatchProperty("InheritedRotAngleDegOffset", { m_InheritedRotAngleOffset = DegreesToRadians(std::stof(reader.ReadPropValue())); });
148+
MatchProperty("MountedRotAngleOffset", { reader >> m_MountedRotAngleOffset; });
146149
MatchProperty("InheritsFrame", { reader >> m_InheritsFrame; });
147150
MatchProperty("CollidesWithTerrainWhileAttached", { reader >> m_CollidesWithTerrainWhileAttached; });
148151
MatchProperty("IgnoresParticlesWhileAttached", { reader >> m_IgnoresParticlesWhileAttached; });
@@ -170,6 +173,7 @@ int Attachable::Save(Writer& writer) const {
170173
writer.NewPropertyWithValue("InheritsHFlipped", ((m_InheritsHFlipped == 0 || m_InheritsHFlipped == 1) ? m_InheritsHFlipped : 2));
171174
writer.NewPropertyWithValue("InheritsRotAngle", m_InheritsRotAngle);
172175
writer.NewPropertyWithValue("InheritedRotAngleOffset", m_InheritedRotAngleOffset);
176+
writer.NewPropertyWithValue("MountedRotAngleOffset", m_MountedRotAngleOffset);
173177

174178
writer.NewPropertyWithValue("CollidesWithTerrainWhileAttached", m_CollidesWithTerrainWhileAttached);
175179
writer.NewPropertyWithValue("IgnoresParticlesWhileAttached", m_IgnoresParticlesWhileAttached);
@@ -414,7 +418,7 @@ void Attachable::PreUpdate() {
414418
m_HFlipped = m_InheritsHFlipped == 1 ? m_Parent->IsHFlipped() : !m_Parent->IsHFlipped();
415419
}
416420
if (InheritsRotAngle()) {
417-
SetRotAngle(m_Parent->GetRotAngle() + m_InheritedRotAngleOffset * m_Parent->GetFlipFactor());
421+
SetRotAngle(m_Parent->GetRotAngle() + m_MountedRotAngleOffset + m_InheritedRotAngleOffset * m_Parent->GetFlipFactor());
418422
m_AngularVel = 0.0F;
419423
}
420424
}
@@ -482,6 +486,8 @@ void Attachable::SetParent(MOSRotating* newParent) {
482486
RTEAssert(!(m_Parent && newParent), "Tried to set an Attachable's " + GetModuleAndPresetName() + " parent without first unsetting its old parent, " + (IsAttached() ? GetParent()->GetModuleAndPresetName() : "ERROR") + ".");
483487
MOSRotating* parentToUseForScriptCall = newParent ? newParent : m_Parent;
484488

489+
m_MountedRotAngleOffset = 0.0F;
490+
485491
// TODO Get rid of the need for calling ResetAllTimers, if something like inventory swapping needs timers reset it should do it itself! This blanket handling probably has side-effects.
486492
// Timers are reset here as a precaution, so that if something was sitting in an inventory, it doesn't cause backed up emissions.
487493
ResetAllTimers();

Source/Entities/Attachable.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,14 @@ namespace RTE {
261261
/// @param inheritedRotAngleOffset Thee new rotation angle offset for this Attachable.
262262
void SetInheritedRotAngleOffset(float inheritedRotAngleOffset) { m_InheritedRotAngleOffset = inheritedRotAngleOffset; }
263263

264+
/// Gets the Turret-specific offset in radians for this HeldDevice's rotation.
265+
/// @return The rotation void Update() override;ooffset in radians.
266+
float GetMountedRotAngleOffset() const { return m_MountedRotAngleOffset; }
267+
268+
/// Sets the Turret-specific offset in radians for this HeldDevice's rotation.
269+
/// @param mountedRotationOffset The new rotation offset in radians.
270+
void SetMountedRotAngleOffset(float mountedRotationOffset) { m_MountedRotAngleOffset = mountedRotationOffset; }
271+
264272
/// Gets whether or not this Attachable inherits its Frame from its parent, if attached.
265273
/// @return Whether or not this Attachable inherits its parent's Frame.
266274
bool InheritsFrame() const { return m_InheritsFrame; }
@@ -435,6 +443,8 @@ namespace RTE {
435443
int m_InheritsHFlipped; //!< Whether this Attachable should inherit its parent's HFlipped. Defaults to 1 (normal inheritance).
436444
bool m_InheritsRotAngle; //!< Whether this Attachable should inherit its parent's RotAngle. Defaults to true.
437445
float m_InheritedRotAngleOffset; //!< The offset by which this Attachable should be rotated when it's set to inherit its parent's rotation angle. Defaults to 0.
446+
// TODO: It really sucks this has to be here just because Turrets are Speshul, we should figure out something better.
447+
float m_MountedRotAngleOffset; //!< A relative offset angle (in radians) of this Attachable's rotation that should only be set by Turrets. Defaults to 0.
438448
bool m_InheritsFrame; //!< Whether this Attachable should inherit its parent's Frame. Defaults to false.
439449

440450
long m_AtomSubgroupID; //!< The Atom IDs this' atoms will have when attached and added to a parent's AtomGroup.

Source/Entities/Turret.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void Turret::AddMountedDevice(HeldDevice* newMountedDevice) {
104104
dynamic_cast<Turret*>(parent)->RemoveMountedDevice(castedAttachable);
105105
}});
106106

107-
newMountedDevice->SetInheritsRotAngle(false);
107+
newMountedDevice->SetInheritsRotAngle(true);
108108
newMountedDevice->SetUnPickupable(true);
109109
newMountedDevice->SetGibWithParentChance(1.0F);
110110
// Force weapons mounted on turrets to never be removed due to forces. This doesn't affect them gibbing from hitting their impulse limits though.
@@ -115,7 +115,7 @@ void Turret::AddMountedDevice(HeldDevice* newMountedDevice) {
115115

116116
void Turret::Update() {
117117
for (HeldDevice* mountedDevice: m_MountedDevices) {
118-
mountedDevice->SetRotAngle(m_Rotation.GetRadAngle() + m_MountedDeviceRotationOffset);
118+
mountedDevice->SetMountedRotAngleOffset(m_MountedDeviceRotationOffset);
119119
}
120120
Attachable::Update();
121121
}

0 commit comments

Comments
 (0)