End point tolerance restored to 64 units.

Corrected problem pointed out by Scrawl.
Destination needs tolerance of 64 to avoid overcrowding.
c++11
dteviot 10 years ago
parent 40a925ad37
commit 52cf8541f5

@ -216,7 +216,7 @@ namespace MWMechanics
// Are we there yet? // Are we there yet?
bool& chooseAction = storage.mChooseAction; bool& chooseAction = storage.mChooseAction;
if(walking && if(walking &&
storage.mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1])) storage.mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], DestinationTolerance))
{ {
stopWalking(actor, storage); stopWalking(actor, storage);
moveNow = false; moveNow = false;
@ -645,9 +645,8 @@ namespace MWMechanics
int index = Misc::Rng::rollDice(mAllowedNodes.size()); int index = Misc::Rng::rollDice(mAllowedNodes.size());
ESM::Pathgrid::Point dest = mAllowedNodes[index]; ESM::Pathgrid::Point dest = mAllowedNodes[index];
// apply a slight offset to prevent overcrowding dest.mX += OffsetToPreventOvercrowding();
dest.mX += static_cast<int>(Misc::Rng::rollProbability() * 128 - 64); dest.mY += OffsetToPreventOvercrowding();
dest.mY += static_cast<int>(Misc::Rng::rollProbability() * 128 - 64);
ToWorldCoordinates(dest, actor.getCell()->getCell()); ToWorldCoordinates(dest, actor.getCell()->getCell());
MWBase::Environment::get().getWorld()->moveObject(actor, static_cast<float>(dest.mX), MWBase::Environment::get().getWorld()->moveObject(actor, static_cast<float>(dest.mX),
@ -658,6 +657,11 @@ namespace MWMechanics
mStoredAvailableNodes = false; mStoredAvailableNodes = false;
} }
int AiWander::OffsetToPreventOvercrowding()
{
return static_cast<int>(DestinationTolerance * (Misc::Rng::rollProbability() * 2.0f - 1.0f));
}
void AiWander::getAllowedNodes(const MWWorld::Ptr& actor, const ESM::Cell* cell) void AiWander::getAllowedNodes(const MWWorld::Ptr& actor, const ESM::Cell* cell)
{ {
if (!mStoredInitialActorPosition) if (!mStoredInitialActorPosition)
@ -739,13 +743,10 @@ namespace MWMechanics
float length = delta.length(); float length = delta.length();
delta.normalize(); delta.normalize();
// destination must be far enough away that NPC will need to move to get there. int distance = std::max(mDistance / 2, MinimumWanderDistance);
const int threshold = PathFinder::PathTolerance * 2;
int distance = std::max(mDistance / 2, threshold);
// must not travel more than 1/2 way between waypoints, // must not travel longer than distance between waypoints or NPC goes past waypoint
// otherwise, NPC goes to far endpoint then comes back. Looks weird. distance = std::min(distance, static_cast<int>(length));
distance = std::min(distance, static_cast<int>(length / 2));
delta *= distance; delta *= distance;
mAllowedNodes.push_back(PathFinder::MakePathgridPoint(vectorStart + delta)); mAllowedNodes.push_back(PathFinder::MakePathgridPoint(vectorStart + delta));
} }

@ -118,6 +118,12 @@ namespace MWMechanics
GroupIndex_MaxIdle = 9 GroupIndex_MaxIdle = 9
}; };
// to prevent overcrowding
static const int DestinationTolerance = 64;
// distance must be long enough that NPC will need to move to get there.
static const int MinimumWanderDistance = DestinationTolerance * 2;
/// convert point from local (i.e. cell) to world co-ordinates /// convert point from local (i.e. cell) to world co-ordinates
void ToWorldCoordinates(ESM::Pathgrid::Point& point, const ESM::Cell * cell); void ToWorldCoordinates(ESM::Pathgrid::Point& point, const ESM::Cell * cell);
@ -129,6 +135,8 @@ namespace MWMechanics
/// lookup table for converting idleSelect value to groupName /// lookup table for converting idleSelect value to groupName
static const std::string sIdleSelectToGroupName[GroupIndex_MaxIdle - GroupIndex_MinIdle + 1]; static const std::string sIdleSelectToGroupName[GroupIndex_MaxIdle - GroupIndex_MinIdle + 1];
static int OffsetToPreventOvercrowding();
}; };

Loading…
Cancel
Save