Skip to content

How It Works

Matthew Seal edited this page Apr 6, 2020 · 4 revisions

How It Works

The Terrain Movement Kit works by overwriting the PathFinder class and the CostToMoveIntoCell function from Pawn_PathFollower and replacing calculations for cost of movement with terrain and pawn aware versions. The algorithm so far (could use a change to A*...) has stayed the same, but the class had to be replaced due to the entire class being private and the FindPath method being exceedingly long.

The Calculation

Despite replacing the PathFinder class, the logic everywhere attempts to be as close to vanilla as possible but where TicksPerMove and the state behind it are calculated by finding the best movement statdef / pathCost combination for a pawn on a given terrain. This ends up being:

var speed = pawn.GetStatValue(terrainStats.moveStat ?? StatDefOf.MoveSpeed) /cost
var cost = terrainStats.costStat == null ? terrain.pathCost : (int)Math.Round(terrain.GetStatValueAbstract(terrainStats.costStat), 0);
return speed / cost;

Unreachable Terrain

To enforce unreachable terrain the TerrainMovementPawnRestrictions found on a pawn are used inside CanReach and CanReachImmediate to mark reach-ability as negative.

Pawn Extensions

Most of the terrain aware calculations done are inside a static extension class of Pawn. These add TerrrainAware<OriginalMethod> methods that perform the <OriginalMethod> operation with an extra TerrainDef argument. These are unlikely the conflict, though the way pathing is rewritten the original methods are rarely if ever called now.

Clone this wiki locally