Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit f4ae69b

Browse files
committed
Fixed helddevice handling on crab/turret destruction and made weapons deactivate when setting the turret's parent
This fixes the sound bug where gatling drones turrets would play the spin sound forever
1 parent fd4d475 commit f4ae69b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Entities/Turret.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ namespace RTE {
3030
return 0;
3131
}
3232

33+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
34+
35+
void Turret::Destroy(bool notInherited) {
36+
if (!notInherited) { Attachable::Destroy(); }
37+
for (const HeldDevice *mountedDevice : m_MountedDevices) { m_HardcodedAttachableUniqueIDsAndRemovers.erase(mountedDevice->GetUniqueID()); }
38+
Clear();
39+
}
40+
3341
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3442

3543
int Turret::ReadProperty(const std::string_view &propName, Reader &reader) {
@@ -121,6 +129,15 @@ namespace RTE {
121129
}
122130
}
123131

132+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
133+
134+
void Turret::SetParent(MOSRotating *newParent) {
135+
Attachable::SetParent(newParent);
136+
for (HeldDevice *mountedDevice : m_MountedDevices) {
137+
mountedDevice->Deactivate(); //mountedDevice->Reloading = false; m_ReloadTmr.Reset();
138+
}
139+
}
140+
124141
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
125142

126143
void Turret::RemoveMountedDevice(const HeldDevice *mountedDeviceToRemove) {

Entities/Turret.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace RTE {
4242
/// Destroys and resets (through Clear()) the Turret object.
4343
/// </summary>
4444
/// <param name="notInherited">Whether to only destroy the members defined in this derived class, or to destroy all inherited members also.</param>
45-
void Destroy(bool notInherited = false) override { if (!notInherited) { Attachable::Destroy(); } Clear(); }
45+
void Destroy(bool notInherited = false) override;
4646

4747
/// <summary>
4848
/// Resets the entire Turret, including its inherited members, to their default settings or values.
@@ -114,12 +114,19 @@ namespace RTE {
114114

115115
protected:
116116

117+
/// <summary>
118+
/// Sets this Attachable's parent MOSRotating, and also sets its Team based on its parent and, if the Attachable is set to collide, adds/removes Atoms to its new/old parent.
119+
/// Additionally, deactivates all MountedDevices.
120+
/// </summary>
121+
/// <param name="newParent">A pointer to the MOSRotating to set as the new parent. Ownership is NOT transferred!</param>
122+
void SetParent(MOSRotating *newParent) override;
123+
117124
static Entity::ClassInfo m_sClass; //!< ClassInfo for this class.
118125

119126
private:
120127

121128
//TODO I think things would be cleaner if this (and all hardcoded attachable pointers) used weak_ptrs. It would solve some weird ownership stuff, particularly with this. However, for that to be possible, m_Attachables has to be shared_ptrs though.
122-
std::vector<HeldDevice *> m_MountedDevices; //!< Vector of unique_ptrs to the mounted HeldDevices of this Turret, if any. Owned here.
129+
std::vector<HeldDevice *> m_MountedDevices; //!< Vector of pointers to the mounted HeldDevices of this Turret, if any. Owned here.
123130
float m_MountedDeviceRotationOffset; //!< The relative offset angle (in radians) of the mounted HeldDevice from this Turret's rotation.
124131

125132
/// <summary>

0 commit comments

Comments
 (0)