From 6e94acb03d9a25cfc7458d8f84d37a4094c719fa Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 11 Nov 2018 21:31:13 +0100 Subject: [PATCH 1/4] Invert if condition This unwraps most of the code from the if body --- mp/src/game/shared/sdk/sdk_gamemovement.cpp | 38 +++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/mp/src/game/shared/sdk/sdk_gamemovement.cpp b/mp/src/game/shared/sdk/sdk_gamemovement.cpp index 9d3e35828..ca638ea1a 100644 --- a/mp/src/game/shared/sdk/sdk_gamemovement.cpp +++ b/mp/src/game/shared/sdk/sdk_gamemovement.cpp @@ -2863,29 +2863,31 @@ void CSDKGameMovement::FullWalkMove () pr2[2] += gpGlobals->frametime*a; TraceBBox (pr1, pr2, mins, maxs, tr); - if (tr.fraction == 1 && !tr.startsolid && !tr.allsolid) + if (tr.fraction != 1 || tr.startsolid || tr.allsolid) { + m_pSDKPlayer->m_Shared.ResetManteling(); + return; + } + + mv->SetAbsOrigin (tr.endpos); + if (m_pSDKPlayer->m_Shared.IsManteling()) { - mv->SetAbsOrigin (tr.endpos); - if (m_pSDKPlayer->m_Shared.IsManteling()) - { - // Try to push the player onto the ledge. - Vector vecOrigin = mv->GetAbsOrigin(); - Vector vecTarget = vecOrigin + Vector(m_vecForward.x, m_vecForward.y, 0).Normalized(); + // Try to push the player onto the ledge. + Vector vecOrigin = mv->GetAbsOrigin(); + Vector vecTarget = vecOrigin + Vector(m_vecForward.x, m_vecForward.y, 0).Normalized(); - TraceBBox(vecOrigin, vecTarget, mins, maxs, tr); + TraceBBox(vecOrigin, vecTarget, mins, maxs, tr); - if (!tr.DidHit ()) - { - mv->SetAbsOrigin (tr.endpos); - m_pSDKPlayer->m_Shared.ResetManteling(); - m_pSDKPlayer->Instructor_LessonLearned("mantel"); - } - else - SetGroundEntity(&tr); + if (!tr.DidHit ()) + { + mv->SetAbsOrigin (tr.endpos); + m_pSDKPlayer->m_Shared.ResetManteling(); + m_pSDKPlayer->Instructor_LessonLearned("mantel"); } + else + SetGroundEntity(&tr); } - else - m_pSDKPlayer->m_Shared.ResetManteling(); + + return; } From 8bc50459e1e9d976ad8cc96bd893d1f89bb7da0c Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 11 Nov 2018 21:33:54 +0100 Subject: [PATCH 2/4] Invert another if condition This again unwraps most of the code from the if body --- mp/src/game/shared/sdk/sdk_gamemovement.cpp | 30 ++++++++++----------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/mp/src/game/shared/sdk/sdk_gamemovement.cpp b/mp/src/game/shared/sdk/sdk_gamemovement.cpp index ca638ea1a..38140126b 100644 --- a/mp/src/game/shared/sdk/sdk_gamemovement.cpp +++ b/mp/src/game/shared/sdk/sdk_gamemovement.cpp @@ -2869,25 +2869,23 @@ void CSDKGameMovement::FullWalkMove () } mv->SetAbsOrigin (tr.endpos); - if (m_pSDKPlayer->m_Shared.IsManteling()) - { - // Try to push the player onto the ledge. - Vector vecOrigin = mv->GetAbsOrigin(); - Vector vecTarget = vecOrigin + Vector(m_vecForward.x, m_vecForward.y, 0).Normalized(); + if (!m_pSDKPlayer->m_Shared.IsManteling()) + return; - TraceBBox(vecOrigin, vecTarget, mins, maxs, tr); - - if (!tr.DidHit ()) - { - mv->SetAbsOrigin (tr.endpos); - m_pSDKPlayer->m_Shared.ResetManteling(); - m_pSDKPlayer->Instructor_LessonLearned("mantel"); - } - else - SetGroundEntity(&tr); - } + // Try to push the player onto the ledge. + Vector vecOrigin = mv->GetAbsOrigin(); + Vector vecTarget = vecOrigin + Vector(m_vecForward.x, m_vecForward.y, 0).Normalized(); + TraceBBox(vecOrigin, vecTarget, mins, maxs, tr); + if (!tr.DidHit ()) + { + mv->SetAbsOrigin (tr.endpos); + m_pSDKPlayer->m_Shared.ResetManteling(); + m_pSDKPlayer->Instructor_LessonLearned("mantel"); + } + else + SetGroundEntity(&tr); return; } From f0e3302626cbb8eccacd4a207dd43ef2b3ac898d Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 11 Nov 2018 21:36:23 +0100 Subject: [PATCH 3/4] Remove useless conditional Since CheckMantel returned true, m_pSDKPlayer->m_Shared.IsManteling() can't possibly be false here. CheckMantel() returns true under one of two conditions: 1. m_pSDKPlayer->m_Shared.IsManteling() is true 2. m_pSDKPlayer->m_Shared.StartManteling has just been called, which sets the member variable returned by m_pSDKPlayer->m_Shared.IsManteling() to true So since this is useless and confusing, I'm removing it. --- mp/src/game/shared/sdk/sdk_gamemovement.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/mp/src/game/shared/sdk/sdk_gamemovement.cpp b/mp/src/game/shared/sdk/sdk_gamemovement.cpp index 38140126b..5a3c6db6a 100644 --- a/mp/src/game/shared/sdk/sdk_gamemovement.cpp +++ b/mp/src/game/shared/sdk/sdk_gamemovement.cpp @@ -2869,8 +2869,6 @@ void CSDKGameMovement::FullWalkMove () } mv->SetAbsOrigin (tr.endpos); - if (!m_pSDKPlayer->m_Shared.IsManteling()) - return; // Try to push the player onto the ledge. Vector vecOrigin = mv->GetAbsOrigin(); From a47b01628fb6a5c18b33847861e4b7246d78f822 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 11 Nov 2018 23:31:49 +0100 Subject: [PATCH 4/4] Use the wall normal instead of the player's forward vector to determine which wall to climb --- mp/src/game/shared/sdk/sdk_gamemovement.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mp/src/game/shared/sdk/sdk_gamemovement.cpp b/mp/src/game/shared/sdk/sdk_gamemovement.cpp index 5a3c6db6a..09a98938d 100644 --- a/mp/src/game/shared/sdk/sdk_gamemovement.cpp +++ b/mp/src/game/shared/sdk/sdk_gamemovement.cpp @@ -2836,7 +2836,21 @@ void CSDKGameMovement::FullWalkMove () } } #endif - if (CheckMantel()) + + // Check if we're manteling + bool canMantel = CheckMantel(); + + // Calculate planarized wall normal + Vector vecWallNormal = m_pSDKPlayer->m_Shared.GetMantelWallNormal(); + vecWallNormal.z = 0; + VectorNormalize(vecWallNormal); + + if (canMantel && vecWallNormal.Dot(Vector(m_vecForward.x, m_vecForward.y, 0).Normalized()) > -0.05) { + m_pSDKPlayer->m_Shared.ResetManteling(); + canMantel = false; + } + + if (canMantel) { /*Move up the height of the bbox over the time of the animation TODO: How get animation duration? Make this use the crouch bbox.*/ @@ -2872,7 +2886,7 @@ void CSDKGameMovement::FullWalkMove () // Try to push the player onto the ledge. Vector vecOrigin = mv->GetAbsOrigin(); - Vector vecTarget = vecOrigin + Vector(m_vecForward.x, m_vecForward.y, 0).Normalized(); + Vector vecTarget = vecOrigin - vecWallNormal; TraceBBox(vecOrigin, vecTarget, mins, maxs, tr);