Skip to content

Commit

Permalink
Merge pull request #45 from kbatbouta/development
Browse files Browse the repository at this point in the history
Small update
  • Loading branch information
kbatbouta authored Feb 9, 2023
2 parents 1e00bee + 8f3b1c5 commit 0be45c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
Binary file modified 1.4/Assemblies/CombatAI.dll
Binary file not shown.
9 changes: 5 additions & 4 deletions Source/Rule56/Comps/ThingComp_CombatAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
5 changes: 5 additions & 0 deletions Source/Rule56/CoverPositionFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
14 changes: 9 additions & 5 deletions Source/Rule56/Patches/CastPositionFinder_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
{
Expand All @@ -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 =>
Expand Down

0 comments on commit 0be45c1

Please sign in to comment.