Account for step cost in real-time unit movement speed

This commit is contained in:
bart
2026-11-08 17:08:55 +01:00
parent 69362c6ef0
commit abfac333eb
+15 -2
View File
@@ -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;