From 49c9cfc57e11d07d4f2db5f4a98cc6f2f819105b Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Thu, 3 Apr 2025 00:52:20 -0700 Subject: [PATCH] Skip Smashes if they coincide with a UnSmash Remove debug logs Comment on return --- dGame/dComponents/ModelComponent.cpp | 15 ++++++++++++++- dGame/dComponents/ModelComponent.h | 7 +++++++ dGame/dPropertyBehaviors/Strip.cpp | 20 +++++++++++++------- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/dGame/dComponents/ModelComponent.cpp b/dGame/dComponents/ModelComponent.cpp index 6b164995..730aefa2 100644 --- a/dGame/dComponents/ModelComponent.cpp +++ b/dGame/dComponents/ModelComponent.cpp @@ -31,6 +31,7 @@ bool ModelComponent::OnResetModelToDefaults(GameMessages::GameMsg& msg) { unsmash.duration = 0.0f; unsmash.Send(UNASSIGNED_SYSTEM_ADDRESS); m_NumListeningInteract = 0; + m_NumActiveUnSmash = 0; m_Dirty = true; Game::entityManager->SerializeEntity(GetParent()); return true; @@ -179,7 +180,7 @@ std::array, 5> ModelComponent::GetBehaviorsForSa } void ModelComponent::AddInteract() { - LOG_DEBUG("adding interact %i", m_NumListeningInteract); + LOG_DEBUG("Adding interact %i", m_NumListeningInteract); m_Dirty = true; m_NumListeningInteract++; } @@ -190,3 +191,15 @@ void ModelComponent::RemoveInteract() { m_Dirty = true; m_NumListeningInteract--; } + +void ModelComponent::AddUnSmash() { + LOG_DEBUG("Adding UnSmash %i", m_NumActiveUnSmash); + m_NumActiveUnSmash++; +} + +void ModelComponent::RemoveUnSmash() { + // Players can assign an UnSmash without a Smash so an assert would be bad here + if (m_NumActiveUnSmash == 0) return; + LOG_DEBUG("Removing UnSmash %i", m_NumActiveUnSmash); + m_NumActiveUnSmash--; +} diff --git a/dGame/dComponents/ModelComponent.h b/dGame/dComponents/ModelComponent.h index d16e7daa..e63a7f0e 100644 --- a/dGame/dComponents/ModelComponent.h +++ b/dGame/dComponents/ModelComponent.h @@ -125,8 +125,15 @@ public: void Pause() { m_Dirty = true; m_IsPaused = true; } + void AddUnSmash(); + void RemoveUnSmash(); + bool IsUnSmashing() const { return m_NumActiveUnSmash != 0; } + void Resume(); private: + // Number of Actions that are awaiting an UnSmash to finish. + uint32_t m_NumActiveUnSmash{}; + // Whether or not this component needs to have its extra data serialized. bool m_Dirty{}; diff --git a/dGame/dPropertyBehaviors/Strip.cpp b/dGame/dPropertyBehaviors/Strip.cpp index f425c6ae..b1dd94eb 100644 --- a/dGame/dPropertyBehaviors/Strip.cpp +++ b/dGame/dPropertyBehaviors/Strip.cpp @@ -140,16 +140,20 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) { } else if (nextActionType == "DropArmor") { for (; numberAsInt > 0; numberAsInt--) SpawnDrop(6431, entity); // 1 Armor powerup } else if (nextActionType == "Smash") { - GameMessages::Smash smash{}; - smash.target = entity.GetObjectID(); - smash.killerID = entity.GetObjectID(); - smash.Send(UNASSIGNED_SYSTEM_ADDRESS); + if (!modelComponent.IsUnSmashing()) { + GameMessages::Smash smash{}; + smash.target = entity.GetObjectID(); + smash.killerID = entity.GetObjectID(); + smash.Send(UNASSIGNED_SYSTEM_ADDRESS); + } } else if (nextActionType == "UnSmash") { GameMessages::UnSmash unsmash{}; unsmash.target = entity.GetObjectID(); unsmash.duration = number; unsmash.builderID = LWOOBJID_EMPTY; unsmash.Send(UNASSIGNED_SYSTEM_ADDRESS); + modelComponent.AddUnSmash(); + m_PausedTime = number; } else if (nextActionType == "Wait") { m_PausedTime = number; @@ -172,12 +176,14 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) { // Decrement references to the previous state if we have progressed to the next one. void Strip::RemoveStates(ModelComponent& modelComponent) const { - // Starting blocks can only be at index one, don't bother trying to remove them otherwise. - if (m_NextActionIndex != 1) return; + const auto& prevAction = GetPreviousAction(); + const auto prevActionType = prevAction.GetType(); - if (GetPreviousAction().GetType() == "OnInteract") { + if (prevActionType == "OnInteract") { modelComponent.RemoveInteract(); Game::entityManager->SerializeEntity(modelComponent.GetParent()); + } else if (prevActionType == "UnSmash") { + modelComponent.RemoveUnSmash(); } }