diff --git a/unit.cpp b/unit.cpp index a0f08e7..ced0f44 100644 --- a/unit.cpp +++ b/unit.cpp @@ -101,9 +101,22 @@ void Unit::update(float deltaTime, float tickDuration, float simSpeedMultiplier, return; } - // Speed in hexes per second: movementSpeed points per tickDuration seconds + // Current segment movement step cost (considering terrain type and slope) + float stepCost = 1.0f; + if (pathIndex + 1 < path.size()) { + int fromX = path[pathIndex].first; + int fromY = path[pathIndex].second; + int toX = path[pathIndex + 1].first; + int toY = path[pathIndex + 1].second; + stepCost = TerrainMovementManager::instance().calculateStepCost( + fromX, fromY, toX, toY, config.movementDomain, mapPoints, numPoints05, &config + ); + if (stepCost <= 0.05f) stepCost = 1.0f; + } + + // Speed in hexes per second: movementSpeed points per tickDuration seconds divided by stepCost float effectiveTickDuration = std::max(0.1f, tickDuration); - float hexesPerSec = (config.movementSpeed / effectiveTickDuration) * simSpeedMultiplier; + float hexesPerSec = (config.movementSpeed / (effectiveTickDuration * stepCost)) * simSpeedMultiplier; moveProgress += deltaTime * hexesPerSec;