mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-13 20:43:07 +00:00
Make trimAllowedNodes a free function
This commit is contained in:
parent
ae909d7685
commit
7c46635a5a
2 changed files with 26 additions and 28 deletions
|
|
@ -109,6 +109,31 @@ namespace MWMechanics
|
||||||
return std::vector<unsigned char>(std::begin(idle), std::end(idle));
|
return std::vector<unsigned char>(std::begin(idle), std::end(idle));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void trimAllowedNodes(const std::deque<osg::Vec3f>& path, std::vector<ESM::Pathgrid::Point>& 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<osg::Vec3f> 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()
|
AiWanderStorage::AiWanderStorage()
|
||||||
|
|
@ -586,7 +611,7 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
// remove allowed points then select another random destination
|
// remove allowed points then select another random destination
|
||||||
storage.mTrimCurrentNode = true;
|
storage.mTrimCurrentNode = true;
|
||||||
trimAllowedNodes(storage.mAllowedNodes, mPathFinder);
|
trimAllowedNodes(mPathFinder.getPath(), storage.mAllowedNodes);
|
||||||
mObstacleCheck.clear();
|
mObstacleCheck.clear();
|
||||||
stopWalking(actor);
|
stopWalking(actor);
|
||||||
storage.setState(AiWanderStorage::Wander_MoveNow);
|
storage.setState(AiWanderStorage::Wander_MoveNow);
|
||||||
|
|
@ -643,31 +668,6 @@ namespace MWMechanics
|
||||||
storage.mAllowedNodes.erase(storage.mAllowedNodes.begin() + randNode);
|
storage.mAllowedNodes.erase(storage.mAllowedNodes.begin() + randNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AiWander::trimAllowedNodes(std::vector<ESM::Pathgrid::Point>& 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)
|
void AiWander::stopWalking(const MWWorld::Ptr& actor)
|
||||||
{
|
{
|
||||||
mPathFinder.clearPath();
|
mPathFinder.clearPath();
|
||||||
|
|
|
||||||
|
|
@ -166,8 +166,6 @@ namespace MWMechanics
|
||||||
|
|
||||||
void getAllowedNodes(const MWWorld::Ptr& actor, AiWanderStorage& storage);
|
void getAllowedNodes(const MWWorld::Ptr& actor, AiWanderStorage& storage);
|
||||||
|
|
||||||
void trimAllowedNodes(std::vector<ESM::Pathgrid::Point>& nodes, const PathFinder& pathfinder);
|
|
||||||
|
|
||||||
// constants for converting idleSelect values into groupNames
|
// constants for converting idleSelect values into groupNames
|
||||||
enum GroupIndex
|
enum GroupIndex
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue