diff --git a/apps/openmw/mwmechanics/aiwander.cpp b/apps/openmw/mwmechanics/aiwander.cpp index 5112979c88..2bdeb27179 100644 --- a/apps/openmw/mwmechanics/aiwander.cpp +++ b/apps/openmw/mwmechanics/aiwander.cpp @@ -109,6 +109,31 @@ namespace MWMechanics return std::vector(std::begin(idle), std::end(idle)); } + void trimAllowedNodes(const std::deque& path, std::vector& nodes) + { + // TODO: how to add these back in once the door opens? + // Idea: keep a list of detected closed doors (see aicombat.cpp) + // Every now and then check whether one of the doors is opened. (maybe + // at the end of playing idle?) If the door is opened then re-calculate + // allowed nodes starting from the spawn point. + std::vector points(path.begin(), path.end()); + while (points.size() >= 2) + { + const osg::Vec3f point = points.back(); + for (std::size_t j = 0; j < nodes.size(); j++) + { + // FIXME: doesn't handle a door with the same X/Y + // coordinates but with a different Z + if (std::abs(nodes[j].mX - point.x()) <= 0.5 && std::abs(nodes[j].mY - point.y()) <= 0.5) + { + nodes.erase(nodes.begin() + j); + break; + } + } + points.pop_back(); + } + } + } AiWanderStorage::AiWanderStorage() @@ -586,7 +611,7 @@ namespace MWMechanics { // remove allowed points then select another random destination storage.mTrimCurrentNode = true; - trimAllowedNodes(storage.mAllowedNodes, mPathFinder); + trimAllowedNodes(mPathFinder.getPath(), storage.mAllowedNodes); mObstacleCheck.clear(); stopWalking(actor); storage.setState(AiWanderStorage::Wander_MoveNow); @@ -643,31 +668,6 @@ namespace MWMechanics storage.mAllowedNodes.erase(storage.mAllowedNodes.begin() + randNode); } - void AiWander::trimAllowedNodes(std::vector& nodes, const PathFinder& pathfinder) - { - // TODO: how to add these back in once the door opens? - // Idea: keep a list of detected closed doors (see aicombat.cpp) - // Every now and then check whether one of the doors is opened. (maybe - // at the end of playing idle?) If the door is opened then re-calculate - // allowed nodes starting from the spawn point. - auto paths = pathfinder.getPath(); - while (paths.size() >= 2) - { - const auto pt = paths.back(); - for (unsigned int j = 0; j < nodes.size(); j++) - { - // FIXME: doesn't handle a door with the same X/Y - // coordinates but with a different Z - if (std::abs(nodes[j].mX - pt.x()) <= 0.5 && std::abs(nodes[j].mY - pt.y()) <= 0.5) - { - nodes.erase(nodes.begin() + j); - break; - } - } - paths.pop_back(); - } - } - void AiWander::stopWalking(const MWWorld::Ptr& actor) { mPathFinder.clearPath(); diff --git a/apps/openmw/mwmechanics/aiwander.hpp b/apps/openmw/mwmechanics/aiwander.hpp index a1474bce5f..0bb0f64a83 100644 --- a/apps/openmw/mwmechanics/aiwander.hpp +++ b/apps/openmw/mwmechanics/aiwander.hpp @@ -166,8 +166,6 @@ namespace MWMechanics void getAllowedNodes(const MWWorld::Ptr& actor, AiWanderStorage& storage); - void trimAllowedNodes(std::vector& nodes, const PathFinder& pathfinder); - // constants for converting idleSelect values into groupNames enum GroupIndex {