Skip to content

Commit f3e57df

Browse files
committed
Fixed exit wound bursts not firing, ensured entry- and exit wound burst sounds only play once per frame per MOSR, added optional isEntryWound and isExitWound bools to AddWound(Ext)
1 parent a92b1b3 commit f3e57df

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
125125

126126
- `Scene` Lua functions `AddNavigatableArea(areaName)` and `ClearNavigatableAreas()` have been renamed/corrected to `AddNavigableArea(areaName)` and `ClearNavigableAreas()`, respectively.
127127

128+
- `MOSRotating` Lua function `AddWound` now additionally accepts the format `MOSRotating:AddWound(AEmitter* woundToAdd, const Vector& parentOffsetToSet, bool checkGibWoundLimit, bool isEntryWound, bool isExitWound)`, allowing modders to specify added wounds as entry- or exit wounds, for the purpose of not playing multiple burst sounds on the same frame. These new arguments are optional.
129+
128130
</details>
129131

130132
<details><summary><b>Fixed</b></summary>

Source/Entities/MOSRotating.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ void MOSRotating::Clear() {
5656
m_RecoilForce.Reset();
5757
m_RecoilOffset.Reset();
5858
m_Wounds.clear();
59-
m_WoundBurstSoundsPlayedThisFrame = {};
59+
m_EntryWoundBurstSoundPlayedThisFrame = false;
60+
m_ExitWoundBurstSoundPlayedThisFrame = false;
6061
m_Attachables.clear();
6162
m_ReferenceHardcodedAttachableUniqueIDs.clear();
6263
m_HardcodedAttachableUniqueIDsAndSetters.clear();
@@ -443,7 +444,7 @@ void MOSRotating::DetachAttachablesFromImpulse(Vector& impulseVector) {
443444
impulseVector.SetMagnitude(impulseRemainder);
444445
}
445446

446-
void MOSRotating::AddWound(AEmitter* woundToAdd, const Vector& parentOffsetToSet, bool checkGibWoundLimit) {
447+
void MOSRotating::AddWoundExt(AEmitter* woundToAdd, const Vector& parentOffsetToSet, bool checkGibWoundLimit, bool isEntryWound, bool isExitWound) {
447448
if (woundToAdd && !m_ToDelete) {
448449
if (checkGibWoundLimit && m_GibWoundLimit > 0 && m_Wounds.size() + 1 >= m_GibWoundLimit) {
449450
// Find and detach an attachable near the new wound before gibbing the object itself. TODO: Perhaps move this to Actor, since it's more relevant there?
@@ -462,14 +463,21 @@ void MOSRotating::AddWound(AEmitter* woundToAdd, const Vector& parentOffsetToSet
462463
woundToAdd->SetParent(this);
463464
woundToAdd->SetIsWound(true);
464465
if (woundToAdd->GetBurstSound()) {
465-
std::string burstSound = woundToAdd->GetBurstSound()->GetPresetName();
466-
for (int i = 0; i < m_WoundBurstSoundsPlayedThisFrame.size(); i++) {
467-
if (burstSound == m_WoundBurstSoundsPlayedThisFrame[i]) {
466+
if (isEntryWound) {
467+
if (m_EntryWoundBurstSoundPlayedThisFrame) {
468468
woundToAdd->SetPlayBurstSound(false);
469-
break;
469+
} else {
470+
m_EntryWoundBurstSoundPlayedThisFrame = true;
471+
}
472+
}
473+
474+
if (isExitWound) {
475+
if (m_ExitWoundBurstSoundPlayedThisFrame) {
476+
woundToAdd->SetPlayBurstSound(false);
477+
} else {
478+
m_ExitWoundBurstSoundPlayedThisFrame = true;
470479
}
471480
}
472-
m_WoundBurstSoundsPlayedThisFrame.push_back(burstSound);
473481
}
474482
if (woundToAdd->HasNoSetDamageMultiplier()) {
475483
woundToAdd->SetDamageMultiplier(1.0F);
@@ -479,6 +487,10 @@ void MOSRotating::AddWound(AEmitter* woundToAdd, const Vector& parentOffsetToSet
479487
}
480488
}
481489

490+
void MOSRotating::AddWound(AEmitter* woundToAdd, const Vector& parentOffsetToSet, bool checkGibWoundLimit) {
491+
AddWoundExt(woundToAdd, parentOffsetToSet, checkGibWoundLimit, false, false);
492+
}
493+
482494
float MOSRotating::RemoveWounds(int numberOfWoundsToRemove, bool includePositiveDamageAttachables, bool includeNegativeDamageAttachables, bool includeNoDamageAttachables) {
483495
float damage = 0;
484496
int woundCount = GetWoundCount(includePositiveDamageAttachables, includeNegativeDamageAttachables, includeNoDamageAttachables);
@@ -816,7 +828,7 @@ bool MOSRotating::ParticlePenetration(HitData& hd) {
816828
pEntryWound->SetDamageMultiplier(damageMultiplier * hd.Body[HITOR]->WoundDamageMultiplier());
817829
// Adjust position so that it looks like the hole is actually *on* the Hitee.
818830
entryPos[dom] += increment[dom] * (pEntryWound->GetSpriteWidth() / 2);
819-
AddWound(pEntryWound, entryPos + m_SpriteOffset);
831+
AddWoundExt(pEntryWound, entryPos + m_SpriteOffset, true, true, false);
820832
pEntryWound = 0;
821833
}
822834

@@ -832,7 +844,7 @@ bool MOSRotating::ParticlePenetration(HitData& hd) {
832844
pExitWound->SetInheritedRotAngleOffset(dir.GetAbsRadAngle());
833845
float damageMultiplier = pExitWound->HasNoSetDamageMultiplier() ? 1.0F : pExitWound->GetDamageMultiplier();
834846
pExitWound->SetDamageMultiplier(damageMultiplier * hd.Body[HITOR]->WoundDamageMultiplier());
835-
AddWound(pExitWound, exitPos + m_SpriteOffset);
847+
AddWoundExt(pExitWound, exitPos + m_SpriteOffset, true, false, true);
836848
pExitWound = 0;
837849
}
838850

@@ -1370,7 +1382,8 @@ void MOSRotating::Update() {
13701382
m_Rotation += radsToGo * m_OrientToVel * velInfluence;
13711383
}
13721384

1373-
m_WoundBurstSoundsPlayedThisFrame = {};
1385+
m_EntryWoundBurstSoundPlayedThisFrame = false;
1386+
m_ExitWoundBurstSoundPlayedThisFrame = false;
13741387

13751388
for (auto woundItr = m_Wounds.begin(); woundItr != m_Wounds.end();) {
13761389
AEmitter* wound = *woundItr;

Source/Entities/MOSRotating.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,12 @@ namespace RTE {
416416
/// @param checkGibWoundLimit Whether to gib this MOSRotating if adding this wound raises its wound count past its gib wound limit. Defaults to true.
417417
virtual void AddWound(AEmitter* woundToAdd, const Vector& parentOffsetToSet, bool checkGibWoundLimit = true);
418418

419+
/// Adds the passed in wound AEmitter to the list of wounds and changes its parent offset to the passed in Vector.
420+
/// @param woundToAdd The wound AEmitter to add.
421+
/// @param parentOffsetToSet The vector to set as the wound AEmitter's parent offset.
422+
/// @param checkGibWoundLimit Whether to gib this MOSRotating if adding this wound raises its wound count past its gib wound limit. Defaults to true.
423+
virtual void AddWoundExt(AEmitter* woundToAdd, const Vector& parentOffsetToSet, bool checkGibWoundLimit = true, bool isEntryWound = false, bool isExitWound = false);
424+
419425
/// Removes the specified number of wounds from this MOSRotating, and returns damage caused by these removed wounds.
420426
/// Includes any Attachables (and their Attachables, etc.) that have a positive damage multiplier.
421427
/// @param numberOfWoundsToRemove The number of wounds that should be removed.
@@ -540,8 +546,10 @@ namespace RTE {
540546
Vector m_RecoilOffset;
541547
// The list of wound AEmitters currently attached to this MOSRotating, and owned here as well.
542548
std::vector<AEmitter*> m_Wounds;
543-
// Whether we added a wound with a BurstSound this frame or not, so we can disable further ones to avoid audio spam.
544-
std::vector<std::string> m_WoundBurstSoundsPlayedThisFrame;
549+
// Whether we added an entry wound with a BurstSound this frame or not, so we can disable further ones to avoid audio spam.
550+
bool m_EntryWoundBurstSoundPlayedThisFrame;
551+
// Whether we added an exit wound with a BurstSound this frame or not.
552+
bool m_ExitWoundBurstSoundPlayedThisFrame;
545553
// The list of Attachables currently attached and Owned by this.
546554
std::list<Attachable*> m_Attachables;
547555
std::unordered_set<unsigned long> m_ReferenceHardcodedAttachableUniqueIDs; //!< An unordered set is filled with the Unique IDs of all of the reference object's hardcoded Attachables when using the copy Create.

Source/Lua/LuaBindingsEntities.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, MOSRotating) {
886886
.def("GetWounds", &LuaAdaptersMOSRotating::GetWounds1, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
887887
.def("GetWounds", &LuaAdaptersMOSRotating::GetWounds2, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
888888
.def("AddWound", &MOSRotating::AddWound, luabind::adopt(_2))
889+
.def("AddWound", &MOSRotating::AddWoundExt, luabind::adopt(_2))
889890
.def("RemoveWounds", (float(MOSRotating::*)(int numberOfWoundsToRemove)) & MOSRotating::RemoveWounds)
890891
.def("RemoveWounds", (float(MOSRotating::*)(int numberOfWoundsToRemove, bool positiveDamage, bool negativeDamage, bool noDamage)) & MOSRotating::RemoveWounds)
891892
.def("IsOnScenePoint", &MOSRotating::IsOnScenePoint)

0 commit comments

Comments
 (0)