-
Notifications
You must be signed in to change notification settings - Fork 3
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.
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;To enforce unreachable terrain the TerrainMovementPawnRestrictions found on a pawn are used inside CanReach and CanReachImmediate to mark reach-ability as negative.
Terrain can similarly define restrictions for what pathCost stats can be used to traverse the terrainDef. The TerrainMovementTerrainRestrictions mod extension has a disallowedPathCostStat which when added to a terrain prevents that pathCost stat from being used during calculations. This is handy if you want a block list approach to terrain movement instead of an allow list approach.
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.
The TerrainMovementPawnKindGraphics mod extension is used to substitute graphs loading for pawns when the using a particular costStat. This is determined by selecting the costStat with the lowest movement cost for the given tile in the same manner it is selected to calculate path costs. This means when a pawn is swimming, it's swim stat will determine graphics rendering if there's a swim cost specific texture extension.