diff --git a/1.4/Assemblies/CombatAI.dll b/1.4/Assemblies/CombatAI.dll index 0ea40b9..55a3493 100644 Binary files a/1.4/Assemblies/CombatAI.dll and b/1.4/Assemblies/CombatAI.dll differ diff --git a/Source/Rule56/Comps/ThingComp_CombatAI.cs b/Source/Rule56/Comps/ThingComp_CombatAI.cs index 696183e..3ba0969 100644 --- a/Source/Rule56/Comps/ThingComp_CombatAI.cs +++ b/Source/Rule56/Comps/ThingComp_CombatAI.cs @@ -422,12 +422,13 @@ public void OnScanFinished() float retreatDist = Maths.Sqrt_Fast(retreatDistSqr, 4); bool Validator_Retreat(IntVec3 cell) { - if (retreatDistSqr - 4 > bestEnemyPositon.DistanceToSquared(cell)) + float mul = 1f; + if (retreatDistSqr > bestEnemyPositon.DistanceToSquared(cell) && warmup != null ) { - return false; + mul = 0.25f; } - return Rand.Chance(sightReader.GetVisibilityToEnemies(pawnPosition) - sightReader.GetVisibilityToEnemies(cell)) || - Rand.Chance(sightReader.GetThreat(pawnPosition) - sightReader.GetThreat(cell)); + return Rand.Chance(mul * (sightReader.GetVisibilityToEnemies(pawnPosition) - sightReader.GetVisibilityToEnemies(cell))) || + Rand.Chance(mul * (sightReader.GetThreat(pawnPosition) - sightReader.GetThreat(cell))); } if (TryRetreat(new LocalTargetInfo(bestEnemy), retreatDist, verb, Validator_Retreat, warmup == null, true)) { diff --git a/Source/Rule56/CoverPositionFinder.cs b/Source/Rule56/CoverPositionFinder.cs index 059ff4e..90acf49 100644 --- a/Source/Rule56/CoverPositionFinder.cs +++ b/Source/Rule56/CoverPositionFinder.cs @@ -43,6 +43,7 @@ public static bool TryFindCoverPosition(CoverPositionRequest request, out IntVec float rootThreat = sightReader.GetThreat(request.locus); float bestCellVisibility = 1e8f; float bestCellScore = 1e8f; + float effectiveRange = request.verb != null && request.verb.EffectiveRange > 0 ? request.verb.EffectiveRange * 0.8f : -1; float rootDutyDestDist = dutyDest.IsValid ? dutyDest.DistanceTo(caster.Position) : -1; bool tpsLow = Finder.Performance.TpsCriticallyLow; flooder.Flood(request.locus, @@ -57,6 +58,10 @@ public static bool TryFindCoverPosition(CoverPositionRequest request, out IntVec { c += Mathf.Clamp((Maths.Sqrt_Fast(dutyDest.DistanceToSquared(node.cell), 3) - rootDutyDestDist) * 0.25f, -1f, 1f); } + if (effectiveRange > 0) + { + c += 2f * Mathf.Abs(effectiveRange - Maths.Sqrt_Fast(node.cell.DistanceToSquared(enemyLoc), 5)) / effectiveRange; + } if (bestCellScore - c >= 0.05f) { float v = sightReader.GetVisibilityToEnemies(node.cell); diff --git a/Source/Rule56/Patches/CastPositionFinder_Patch.cs b/Source/Rule56/Patches/CastPositionFinder_Patch.cs index 9ccadfa..ff895d3 100644 --- a/Source/Rule56/Patches/CastPositionFinder_Patch.cs +++ b/Source/Rule56/Patches/CastPositionFinder_Patch.cs @@ -142,11 +142,11 @@ private static void FloodCellRect(CellRect rect) { if (!skipped && sightReader != null) { - IntVec3 root = pawn.Position; - float rootVis = sightReader.GetVisibilityToEnemies(root); - float rootThreat = sightReader.GetThreat(request.locus); - - float rootDutyDestDist = dutyDest.IsValid ? dutyDest.DistanceTo(pawn.Position) : -1; + IntVec3 root = pawn.Position; + float rootVis = sightReader.GetVisibilityToEnemies(root); + float rootThreat = sightReader.GetThreat(request.locus); + float effectiveRange = verb?.EffectiveRange > 0 ? verb.EffectiveRange : -1; + float rootDutyDestDist = dutyDest.IsValid ? dutyDest.DistanceTo(pawn.Position) : -1; map.GetCellFlooder().Flood(root, node => { @@ -155,6 +155,10 @@ private static void FloodCellRect(CellRect rect) { val += Mathf.Clamp((Maths.Sqrt_Fast(dutyDest.DistanceToSquared(node.cell), 3) - rootDutyDestDist) * 0.25f, -2f, 2f); } + if (effectiveRange > 0) + { + val += 2f * Mathf.Abs(effectiveRange - Maths.Sqrt_Fast(node.cell.DistanceToSquared(targetPosition), 5)) / effectiveRange; + } grid[node.cell] = val; }, cell =>