From b6f2dee43b3acfa83ba8415e2991c6b9e5dc50b9 Mon Sep 17 00:00:00 2001 From: wraitii Date: Fri, 21 May 2021 07:23:47 +0000 Subject: [PATCH] Increase pushing range by 60% Reduces the 'clumpiness' of units, particularly when ordered to move to a single point. The minimum pushing force was increased to compensate. Differential Revision: https://code.wildfiregames.com/D3978 This was SVN commit r25479. --- .../scenarios/unit_chasing_test_triggers.js | 4 ++-- .../components/CCmpUnitMotion_System.cpp | 21 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/binaries/data/mods/public/maps/scenarios/unit_chasing_test_triggers.js b/binaries/data/mods/public/maps/scenarios/unit_chasing_test_triggers.js index 63b75feb8f..f7f3640dc3 100644 --- a/binaries/data/mods/public/maps/scenarios/unit_chasing_test_triggers.js +++ b/binaries/data/mods/public/maps/scenarios/unit_chasing_test_triggers.js @@ -253,7 +253,7 @@ Trigger.prototype.SetupUnits = function() } }; -Trigger.prototype.OnOwnershipChanged = function(msg) +Trigger.prototype.OwnershipChanged = function(msg) { if (msg.to === -1 && msg.entity in onDelete) { @@ -262,7 +262,7 @@ Trigger.prototype.OnOwnershipChanged = function(msg) } }; -cmpTrigger.RegisterTrigger("OnOwnershipChanged", "OnOwnershipChanged", { "enabled": true }); +cmpTrigger.RegisterTrigger("OnOwnershipChanged", "OwnershipChanged", { "enabled": true }); var cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); diff --git a/source/simulation2/components/CCmpUnitMotion_System.cpp b/source/simulation2/components/CCmpUnitMotion_System.cpp index 9a20c2194b..434f8d2727 100644 --- a/source/simulation2/components/CCmpUnitMotion_System.cpp +++ b/source/simulation2/components/CCmpUnitMotion_System.cpp @@ -41,10 +41,23 @@ namespace { /** * Pushing is ignored if the combined push force has lower magnitude than this. */ - static const entity_pos_t MINIMAL_PUSHING = entity_pos_t::FromInt(1)/10; + static const entity_pos_t MINIMAL_PUSHING = entity_pos_t::FromInt(3) / 10; /** - * When moving, units extert a pushing influence at a greater distance. + * For pushing, treat the clearances as a circle - they're defined as squares, + * so we'll take the circumscribing square (approximately). + * Clerances are also full-width instead of half, so we want to divide by two. sqrt(2)/2 is about 0.71 < 5/7. + */ + static const entity_pos_t PUSHING_CORRECTION = entity_pos_t::FromInt(5) / 7; + + /** + * The maximum distance at which units exert a pushing influence on each other, as a multiple of clearance. + * (This is multiplied by PUSHING_CORRECTION for convenience). + */ + static const entity_pos_t PUSHING_RADIUS = (entity_pos_t::FromInt(8) / 5).Multiply(PUSHING_CORRECTION); + + /** + * When moving, units exert a pushing influence at a greater distance. */ static const entity_pos_t PUSHING_MOVING_INFLUENCE_EXTENSION = entity_pos_t::FromInt(1); @@ -229,9 +242,7 @@ void CCmpUnitMotionManager::Push(EntityMap::value_type& a, EntityMa if (movingPush == 1) return; - // Treat the clearances as a circle - they're defined as squares, so we'll slightly overcompensate the diagonal - // (they're also full-width instead of half, so we want to divide by two. sqrt(2)/2 is about 0.71 < 5/7). - entity_pos_t combinedClearance = (a.second.cmpUnitMotion->m_Clearance + b.second.cmpUnitMotion->m_Clearance) * 5 / 7; + entity_pos_t combinedClearance = (a.second.cmpUnitMotion->m_Clearance + b.second.cmpUnitMotion->m_Clearance).Multiply(PUSHING_RADIUS); entity_pos_t maxDist = combinedClearance; if (movingPush) maxDist += PUSHING_MOVING_INFLUENCE_EXTENSION;