mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-19 10:11:32 +00:00
Normalize area cost factor
Recastnavigation uses path cost and heuristic based on distance to find shortest path by A* algorithm. Using raw speed values makes cost much lower value than heuristic (1000 times less at maximum). Heuristic is defined as distance from node to target * 0.999 that means area cost should never be less than 0.999 or 1 for simplicity. Use max speed to make lowest possible cost factor equal to 1.
This commit is contained in:
parent
5794a3b346
commit
163968f578
1 changed files with 22 additions and 11 deletions
|
@ -457,20 +457,31 @@ DetourNavigator::AreaCosts MWMechanics::AiPackage::getAreaCosts(const MWWorld::P
|
||||||
const DetourNavigator::Flags flags = getNavigatorFlags(actor);
|
const DetourNavigator::Flags flags = getNavigatorFlags(actor);
|
||||||
const MWWorld::Class& actorClass = actor.getClass();
|
const MWWorld::Class& actorClass = actor.getClass();
|
||||||
|
|
||||||
if (flags & DetourNavigator::Flag_swim)
|
const float swimSpeed = (flags & DetourNavigator::Flag_swim) == 0
|
||||||
costs.mWater = divOrMax(costs.mWater, actorClass.getSwimSpeed(actor));
|
? 0.0f
|
||||||
|
: actorClass.getSwimSpeed(actor);
|
||||||
|
|
||||||
if (flags & DetourNavigator::Flag_walk)
|
const float walkSpeed = [&]
|
||||||
{
|
{
|
||||||
float walkCost;
|
if ((flags & DetourNavigator::Flag_walk) == 0)
|
||||||
|
return 0.0f;
|
||||||
if (getTypeId() == AiPackageTypeId::Wander)
|
if (getTypeId() == AiPackageTypeId::Wander)
|
||||||
walkCost = divOrMax(1.0, actorClass.getWalkSpeed(actor));
|
return actorClass.getWalkSpeed(actor);
|
||||||
else
|
return actorClass.getRunSpeed(actor);
|
||||||
walkCost = divOrMax(1.0, actorClass.getRunSpeed(actor));
|
} ();
|
||||||
costs.mDoor = costs.mDoor * walkCost;
|
|
||||||
costs.mPathgrid = costs.mPathgrid * walkCost;
|
const float maxSpeed = std::max(swimSpeed, walkSpeed);
|
||||||
costs.mGround = costs.mGround * walkCost;
|
|
||||||
}
|
if (maxSpeed == 0)
|
||||||
|
return costs;
|
||||||
|
|
||||||
|
const float swimFactor = swimSpeed / maxSpeed;
|
||||||
|
const float walkFactor = walkSpeed / maxSpeed;
|
||||||
|
|
||||||
|
costs.mWater = divOrMax(costs.mWater, swimFactor);
|
||||||
|
costs.mDoor = divOrMax(costs.mDoor, walkFactor);
|
||||||
|
costs.mPathgrid = divOrMax(costs.mPathgrid, walkFactor);
|
||||||
|
costs.mGround = divOrMax(costs.mGround, walkFactor);
|
||||||
|
|
||||||
return costs;
|
return costs;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue