diff --git a/src/creatures/combat/condition.cpp b/src/creatures/combat/condition.cpp index 5cf1905c2e8..bc262a41c76 100644 --- a/src/creatures/combat/condition.cpp +++ b/src/creatures/combat/condition.cpp @@ -1873,12 +1873,15 @@ bool ConditionFeared::getRandomDirection(std::shared_ptr creature, Pos DIRECTION_NORTHWEST }; - std::ranges::shuffle(directions.begin(), directions.end(), getRandomGenerator()); - for (Direction dir : directions) { - if (canWalkTo(creature, pos, dir)) { - this->fleeIndx = static_cast(dir); - return true; - } + std::ranges::shuffle(directions, getRandomGenerator()); + + auto it = std::ranges::find_if(directions, [&](Direction dir) { + return canWalkTo(creature, pos, dir); + }); + + if (it != directions.end()) { + this->fleeIndx = static_cast(*it); + return true; } return false;