public static IEnumerable <(StatDef moveStat, StatDef costStat)> AnyTerrainMovementStatDefs(this TerrainDef terrain, bool defaultMovementAllowed = true, LocomotionUrgency urgency = LocomotionUrgency.None) { HashSet <StatDef> disallowedPathCostsStats = terrain.TerrainMovementDisallowedPathCostStat(); // Check for if default movement is allowed or not if (defaultMovementAllowed && !disallowedPathCostsStats.Contains(StatDefOf.MoveSpeed)) { yield return(StatDefOf.MoveSpeed, StatDefOf.MoveSpeed); } // Memoize statdef terrain modifications if (AllTerrainMovementStats == null) { AllTerrainMovementStats = new List <TerrainMovementStatDef>(); foreach (StatDef stat in DefDatabase <StatDef> .AllDefs) { TerrainMovementStatDef statExt = stat.GetModExtension <TerrainMovementStatDef>(); if (statExt != null) { AllTerrainMovementStats.Add(statExt); } } } foreach (TerrainMovementStatDef moveStatDef in AllTerrainMovementStats) { yield return(terrain.TerrainMovementStatDefPair(moveStatDef, defaultMovementAllowed, urgency)); } }
public static IEnumerable <(StatDef moveStat, StatDef costStat)> TerrainMovementStatDefs(this TerrainDef terrain) { HashSet <StatDef> disallowedPathCostsStats = terrain.TerrainMovementDisallowedPathCostStat(); // Check for if default movement is allowed or not if (!disallowedPathCostsStats.Contains(null)) { yield return(StatDefOf.MoveSpeed, null); } if (terrain.modExtensions != null) { foreach (DefModExtension ext in terrain.modExtensions) { TerrainMovementStatDef moveStatDef = terrain.LoadTerrainMovementStatDefExtension(ext); if (moveStatDef != null) { StatDef newCostStat; // There's no actual StatDef for pathCost, so map it to null if (moveStatDef.pawnSpeedStat == null || moveStatDef.pawnSpeedStat == "pathCost") { newCostStat = null; } else { newCostStat = StatDef.Named(moveStatDef.terrainPathCostStat); } // Opt out if the terrain disallows this costStat if (!disallowedPathCostsStats.Contains(newCostStat)) { StatDef newMoveStat; if (moveStatDef.pawnSpeedStat == null) { newMoveStat = StatDefOf.MoveSpeed; } else { newMoveStat = StatDef.Named(moveStatDef.pawnSpeedStat); } yield return(newMoveStat, newCostStat); } } } } }
public static IEnumerable <(StatDef moveStat, StatDef costStat)> TerrainMovementStatDefs(this TerrainDef terrain, bool defaultMovementAllowed = true, LocomotionUrgency urgency = LocomotionUrgency.None) { foreach (var pair in terrain.AnyTerrainMovementStatDefs(defaultMovementAllowed, urgency)) { yield return(pair); } if (terrain.modExtensions != null) { foreach (DefModExtension ext in terrain.modExtensions) { TerrainMovementStatDef moveStatDef = terrain.LoadTerrainMovementStatDefExtension(ext); var pair = terrain.TerrainMovementStatDefPair(moveStatDef, defaultMovementAllowed, urgency); if (!(pair.moveStat == null && pair.costStat == null)) { yield return(pair); } } } }
public static (StatDef moveStat, StatDef costStat) TerrainMovementStatDefPair(this TerrainDef terrain, TerrainMovementStatDef moveStatDef, bool defaultMovementAllowed = true, LocomotionUrgency urgency = LocomotionUrgency.None) { HashSet <StatDef> disallowedPathCostsStats = terrain.TerrainMovementDisallowedPathCostStat(); if (moveStatDef != null && moveStatDef.UrgencyAllowed(urgency)) { StatDef newCostStat; // If there's no actual StatDef for pathCost, so map it to null if (moveStatDef.pawnSpeedStat == null || moveStatDef.pawnSpeedStat == "pathCost") { if (defaultMovementAllowed) { newCostStat = StatDefOf.MoveSpeed; } else { newCostStat = null; } } else { newCostStat = StatDef.Named(moveStatDef.terrainPathCostStat); } // Opt out if the terrain disallows this costStat if (!disallowedPathCostsStats.Contains(newCostStat)) { StatDef newMoveStat; if (moveStatDef.pawnSpeedStat == null) { if (defaultMovementAllowed) { newMoveStat = StatDefOf.MoveSpeed; } else { newMoveStat = null; } } else { newMoveStat = StatDef.Named(moveStatDef.pawnSpeedStat); } return(newMoveStat, newCostStat); } } return(null, null); }