From 870e689e5f4a67bbebb8479ac3f0f6c3ccd9abed Mon Sep 17 00:00:00 2001 From: wraitii Date: Tue, 8 Jun 2021 16:38:06 +0000 Subject: [PATCH] Unit pushing: fix pairs of unit being allowed to overlap. Following 40cbde1925, the minimum pushing force is 0.2. This also happens to be the maximum pushing force any pair of units can exert on each other, so they can freely overlap instead of being pushed. This tweaks settings slightly to fix that problem. Reported by: marder Differential Revision: https://code.wildfiregames.com/D4129 This was SVN commit r25748. --- .../data/mods/public/simulation/data/pathfinder.xml | 2 ++ .../simulation2/components/CCmpUnitMotion_System.cpp | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/binaries/data/mods/public/simulation/data/pathfinder.xml b/binaries/data/mods/public/simulation/data/pathfinder.xml index bb5c3d1146..ea59a73df9 100644 --- a/binaries/data/mods/public/simulation/data/pathfinder.xml +++ b/binaries/data/mods/public/simulation/data/pathfinder.xml @@ -26,6 +26,8 @@ + + 0.2 diff --git a/source/simulation2/components/CCmpUnitMotion_System.cpp b/source/simulation2/components/CCmpUnitMotion_System.cpp index e12698c402..fc3938eba1 100644 --- a/source/simulation2/components/CCmpUnitMotion_System.cpp +++ b/source/simulation2/components/CCmpUnitMotion_System.cpp @@ -52,8 +52,11 @@ namespace { /** * Maximum distance multiplier. + * NB: this value interacts with the "minimal pushing" force, + * as two perfectly overlapping units exert MAX_DISTANCE_FACTOR * Turn length in ms / REDUCTION_FACTOR + * of force on each other each turn. If this is below the minimal pushing force, any 2 units can entirely overlap. */ - static const entity_pos_t MAX_DISTANCE_FACTOR = entity_pos_t::FromInt(2); + static const entity_pos_t MAX_DISTANCE_FACTOR = entity_pos_t::FromInt(5) / 2; } CCmpUnitMotionManager::MotionState::MotionState(CmpPtr cmpPos, CCmpUnitMotion* cmpMotion) @@ -297,7 +300,7 @@ void CCmpUnitMotionManager::Push(EntityMap::value_type& a, EntityMa bool dir = a.first % 2; offset.X = entity_pos_t::FromInt(dir ? 1 : 0); offset.Y = entity_pos_t::FromInt(dir ? 0 : 1); - offsetLength = entity_pos_t::FromInt(1); + offsetLength = entity_pos_t::Epsilon() * 10; } else { @@ -320,9 +323,10 @@ void CCmpUnitMotionManager::Push(EntityMap::value_type& a, EntityMa offsetLength = fixed::Zero(); } - // The formula expects 'normal' pushing if the two entities edges are touching. + // The pushing distance factor is 1 if the edges are touching, >1 up to MAX if the units overlap, < 1 otherwise. entity_pos_t distanceFactor = maxDist - combinedClearance; - if (distanceFactor <= entity_pos_t::Zero()) + // Force units that overlap a lot to have the maximum factor. + if (distanceFactor <= entity_pos_t::Zero() || offsetLength < combinedClearance / 2) distanceFactor = MAX_DISTANCE_FACTOR; else distanceFactor = Clamp((maxDist - offsetLength) / distanceFactor, entity_pos_t::Zero(), MAX_DISTANCE_FACTOR);