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

Commit

Permalink
Only take damage from impulse if we're unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
Causeless committed Nov 6, 2023
1 parent c5656e0 commit 3840085
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions Entities/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,20 @@ void Actor::Update()
}
m_Health = std::min(m_Health, m_MaxHealth);

/////////////////////////////
// Stability logic

if (m_Status == STABLE) {
// If moving really fast, we're not able to be stable
if (std::abs(m_Vel.m_X) > std::abs(m_StableVel.m_X) || std::abs(m_Vel.m_Y) > std::abs(m_StableVel.m_Y)) { m_Status = UNSTABLE; }

m_StableRecoverTimer.Reset();
}
else if (m_Status == UNSTABLE) {
// Only regain stability if we're not moving too fast and it's been a while since we lost it
if (m_StableRecoverTimer.IsPastSimMS(m_StableRecoverDelay) && !(std::abs(m_Vel.m_X) > std::abs(m_StableVel.m_X) || std::abs(m_Vel.m_Y) > std::abs(m_StableVel.m_Y))) { m_Status = STABLE; }
}

/////////////////////////////////////////////
// Take damage from large hits during travel

Expand All @@ -1391,28 +1405,14 @@ void Actor::Update()
float halfTravelImpulseDamage = m_TravelImpulseDamage * 0.5F;
if (m_BodyHitSound && travelImpulseMagnitudeSqr > (halfTravelImpulseDamage * halfTravelImpulseDamage)) { m_BodyHitSound->Play(m_Pos); }

if (travelImpulseMagnitudeSqr > (m_TravelImpulseDamage * m_TravelImpulseDamage)) {
// But only actually damage ourselves if we're unstable
if (m_Status == Actor::UNSTABLE && travelImpulseMagnitudeSqr > (m_TravelImpulseDamage * m_TravelImpulseDamage)) {
const float impulse = std::sqrt(travelImpulseMagnitudeSqr) - m_TravelImpulseDamage;
const float damage = std::max(impulse / (m_GibImpulseLimit - m_TravelImpulseDamage) * m_MaxHealth, 0.0F);
m_Health -= damage;
if (m_Status == Actor::STABLE) { m_Status = UNSTABLE; }
m_ForceDeepCheck = true;
}

/////////////////////////////
// Stability logic

if (m_Status == STABLE) {
// If moving really fast, we're not able to be stable
if (std::abs(m_Vel.m_X) > std::abs(m_StableVel.m_X) || std::abs(m_Vel.m_Y) > std::abs(m_StableVel.m_Y)) { m_Status = UNSTABLE; }

m_StableRecoverTimer.Reset();
}
else if (m_Status == UNSTABLE) {
// Only regain stability if we're not moving too fast and it's been a while since we lost it
if (m_StableRecoverTimer.IsPastSimMS(m_StableRecoverDelay) && !(std::abs(m_Vel.m_X) > std::abs(m_StableVel.m_X) || std::abs(m_Vel.m_Y) > std::abs(m_StableVel.m_Y))) { m_Status = STABLE; }
}

// Spread the carried items and gold around before death.
if (m_Status == DYING || m_Status == DEAD) {
// Actor may die for a long time, no need to call this more than once
Expand Down

0 comments on commit 3840085

Please sign in to comment.