1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-29 04:20:29 +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:
elsid 2021-09-28 22:42:44 +02:00
parent 5794a3b346
commit 163968f578
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

View File

@ -457,20 +457,31 @@ DetourNavigator::AreaCosts MWMechanics::AiPackage::getAreaCosts(const MWWorld::P
const DetourNavigator::Flags flags = getNavigatorFlags(actor);
const MWWorld::Class& actorClass = actor.getClass();
if (flags & DetourNavigator::Flag_swim)
costs.mWater = divOrMax(costs.mWater, actorClass.getSwimSpeed(actor));
const float swimSpeed = (flags & DetourNavigator::Flag_swim) == 0
? 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)
walkCost = divOrMax(1.0, actorClass.getWalkSpeed(actor));
else
walkCost = divOrMax(1.0, actorClass.getRunSpeed(actor));
costs.mDoor = costs.mDoor * walkCost;
costs.mPathgrid = costs.mPathgrid * walkCost;
costs.mGround = costs.mGround * walkCost;
}
return actorClass.getWalkSpeed(actor);
return actorClass.getRunSpeed(actor);
} ();
const float maxSpeed = std::max(swimSpeed, walkSpeed);
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;
}