From 892f97743b4e2e1718dbbd787caab401843d3bb8 Mon Sep 17 00:00:00 2001 From: wraitii Date: Mon, 25 May 2020 20:13:35 +0000 Subject: [PATCH] Fix some cases of units getting stuck. This fixes an off-by-one error that led to entities sometimes getting stuck against obstructions. It also increases the max-range of the short pathfinder to help entities find their way around corridors and house blocks. Fixes 2ff8614ce2 (off-by-one error) and reverts the range changes from 32e8ed51aa Reported By: Freagarach Fixes #5586 . Refs #5624 Differential Revision: https://code.wildfiregames.com/D2754 This was SVN commit r23699. --- source/simulation2/components/CCmpUnitMotion.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/source/simulation2/components/CCmpUnitMotion.cpp b/source/simulation2/components/CCmpUnitMotion.cpp index d3d0606c5f..3fb0289a1e 100644 --- a/source/simulation2/components/CCmpUnitMotion.cpp +++ b/source/simulation2/components/CCmpUnitMotion.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -50,8 +50,8 @@ * smaller ranges might miss some legitimate routes around large obstacles.) */ static const entity_pos_t SHORT_PATH_MIN_SEARCH_RANGE = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*3)/2; -static const entity_pos_t SHORT_PATH_MAX_SEARCH_RANGE = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*6); -static const entity_pos_t SHORT_PATH_SEARCH_RANGE_INCREMENT = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*1); +static const entity_pos_t SHORT_PATH_MAX_SEARCH_RANGE = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*14); +static const entity_pos_t SHORT_PATH_SEARCH_RANGE_INCREMENT = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*2); /** * When using the short-pathfinder to rejoin a long-path waypoint, aim for a circle of this radius around the waypoint. @@ -1024,9 +1024,10 @@ bool CCmpUnitMotion::HandleObstructedMove() if (!InShortPathRange(goal, pos)) { - // If we still have long waypoints, try and compute a short path. - // Assume the next waypoint is impassable - if (m_LongPath.m_Waypoints.size() > 1) + // If we still have long waypoints, try and compute a short path to our next long waypoint. + // Assume the next waypoint is impassable and pop it. This helps unstuck entities in some cases, and we'll just + // end up recomputing a long path if we pop all of them, so it's safe. + if (m_LongPath.m_Waypoints.size() >= 1) m_LongPath.m_Waypoints.pop_back(); if (!m_LongPath.m_Waypoints.empty()) {