Skip to content

Commit

Permalink
Merge pull request #83 from kbatbouta/development
Browse files Browse the repository at this point in the history
Fixed the issue of pawns freezing on entering a map
  • Loading branch information
kbatbouta authored Feb 28, 2023
2 parents 867dc58 + c3f18e6 commit 034922e
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 22 deletions.
Binary file modified 1.4/Assemblies/CombatAI.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion 1.4/Defs/DutyDefs/Duties_Misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</subNodes>
</li>
<li Class="JobGiver_WanderNearDutyLocation">
<wanderRadius>8</wanderRadius>
<wanderRadius>32</wanderRadius>
<locomotionUrgencyOutsideRadius>Sprint</locomotionUrgencyOutsideRadius>
</li>
<li Class="JobGiver_AITrashBuildingsDistant">
Expand Down
6 changes: 6 additions & 0 deletions Source/Rule56/Debugging/JobLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ public override string ToString()
StringBuilder builder = new StringBuilder();
builder.AppendFormat("job:\t{0} ({1})\n", job, id);
builder.AppendFormat("duty:\t{0}\n", duty);
builder.AppendFormat("timestamp:\t{0}\n", timestamp);
builder.AppendFormat("(origin:{0}, dest:{1})\n", origin, destination);
if (destination.IsValid)
{
builder.AppendFormat("distanceToDest:\n{0}",destination.DistanceTo(origin));
}
builder.AppendLine();
builder.Append("thinknode trace:\n");
for (int i = 0; i < thinknode.Count; i++)
Expand Down
36 changes: 34 additions & 2 deletions Source/Rule56/Debugging/Window_JobLogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private void DoTestContents(Rect inRect)
PathFinder_Patch.FlashSearch = true;
try
{
PawnPath path = pawn.Map.pathFinder.FindPath(pawn.Position, info, pawn);
PawnPath path = pawn.Map.pathFinder.FindPath(pawn.Position, info.Cell, pawn);
if (path is { Found: true })
{
path.ReleaseToPool();
Expand Down Expand Up @@ -268,6 +268,35 @@ private void DoTestContents(Rect inRect)
}
});
}
if (ButtonText(collapsible_dutyTest, "Reachability check"))
{
Find.Targeter.BeginTargeting(new TargetingParameters
{
canTargetAnimals = false,
canTargetBuildings = false,
canTargetCorpses = false,
canTargetHumans = false,
canTargetSelf = false,
canTargetMechs = false,
canTargetLocations = true,
validator = info =>
{
if (info.Cell.IsValid)
{
string result = $"ByPawn={pawn.CanReach(info.Cell, PathEndMode.InteractionCell, Danger.Deadly, true, true, TraverseMode.ByPawn)}\n"
+ $"NoPassClosedDoors={pawn.CanReach(info.Cell, PathEndMode.InteractionCell, Danger.Deadly, true, true, TraverseMode.NoPassClosedDoors)}\n"
+ $"NoPassClosedDoorsOrWater={pawn.CanReach(info.Cell, PathEndMode.InteractionCell, Danger.Deadly, true, true, TraverseMode.NoPassClosedDoorsOrWater)}\n"
+ $"PassDoors={pawn.CanReach(info.Cell, PathEndMode.InteractionCell, Danger.Deadly, true, true, TraverseMode.PassDoors)}\n"
+ $"PassAllDestroyableThings={pawn.CanReach(info.Cell, PathEndMode.InteractionCell, Danger.Deadly, true, true, TraverseMode.PassAllDestroyableThings)}\n"
+ $"PassAllDestroyableThingsNotWater={pawn.CanReach(info.Cell, PathEndMode.InteractionCell, Danger.Deadly, true, true, TraverseMode.PassAllDestroyableThingsNotWater)}\n";
}
return true;
},
}, info =>
{
return;
});
}
if (ButtonText(collapsible_dutyTest, "End all jobs"))
{
foreach (Pawn other in Find.Selector.SelectedPawns)
Expand Down Expand Up @@ -371,7 +400,10 @@ private void DoJobLogContents(Rect inRect)
}
}, false);
inRect.yMin += 25;
GUIUtility.ScrollView(selectedLog != null ? inRect.TopPart(viewRatio1) : inRect, ref scorllPos, Logs, GetHeight, DrawJobLog);
if (!Logs.NullOrEmpty())
{
GUIUtility.ScrollView(selectedLog != null ? inRect.TopPart(viewRatio1) : inRect, ref scorllPos, Logs, GetHeight, DrawJobLog);
}
if (selectedLog != null)
{
Rect botRect = inRect.BottomPart(1 - viewRatio1);
Expand Down
49 changes: 31 additions & 18 deletions Source/Rule56/Patches/PathFinder_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ private static class PathFinder_FindPath_Patch
private static PathEndMode origina_peMode;

[HarmonyPriority(int.MaxValue)]
internal static bool Prefix(PathFinder __instance, ref PawnPath __result, IntVec3 start, LocalTargetInfo dest, ref TraverseParms traverseParms, PathEndMode peMode, ref PathFinderCostTuning tuning, out bool __state)
internal static void Prefix(PathFinder __instance, ref PawnPath __result, IntVec3 start, LocalTargetInfo dest, ref TraverseParms traverseParms, PathEndMode peMode, ref PathFinderCostTuning tuning, out bool __state)
{
if (fallbackCall)
{
return __state = true;
__state = true;
return;
}
#if DEBUG
flashInstance = flashCost ? __instance : null;
Expand Down Expand Up @@ -107,7 +108,7 @@ internal static bool Prefix(PathFinder __instance, ref PawnPath __result, IntVec
bool humanlike = pawn.RaceProps.Humanlike;
if (humanlike)
{
parms.mode = TraverseMode.PassAllDestroyableThingsNotWater;
parms.mode = TraverseMode.PassAllDestroyableThings;
}
else
{
Expand All @@ -133,11 +134,12 @@ internal static bool Prefix(PathFinder __instance, ref PawnPath __result, IntVec
checkVisibility = sightReader != null;
// counter = 0;
flashCost = Finder.Settings.Debug_DebugPathfinding && Find.Selector.SelectedPawns.Contains(pawn);
return __state = true;
__state = true;
return;
}
__state = false;
Reset();
return true;
return;
}

[HarmonyPriority(int.MinValue)]
Expand All @@ -149,6 +151,24 @@ public static void Postfix(PathFinder __instance, ref PawnPath __result, bool __
}
if (__state)
{
// if (__result == null || __result == PawnPath.NotFound || !__result.Found)
// {
// try
// {
// __result?.Dispose();
// fallbackCall = true;
// dig = false;
// __result = __instance.FindPath(start, dest, original_traverseParms, origina_peMode, tuning);
// }
// catch (Exception er)
// {
// Log.Error($"ISMA: Error occured in FindPath fallback call {er}");
// }
// finally
// {
// fallbackCall = false;
// }
// }
if (dig && !(__result?.nodes.NullOrEmpty() ?? true))
{
blocked.Clear();
Expand Down Expand Up @@ -188,21 +208,16 @@ public static void Postfix(PathFinder __instance, ref PawnPath __result, bool __
tracker.Notify_PathFound(pawn, __result);
}
}
if (FlashSearch)
{
FlashSearch = false;
}
Reset();
}

public static void Reset()
{
avoidanceReader = null;
isRaider = false;
isPlayer = false;
multiplier = 1f;
sightReader = null;
// counter = 0;
avoidanceReader = null;
isRaider = false;
isPlayer = false;
multiplier = 1f;
sightReader = null;
dig = false;
threatAtDest = 0;
instance = null;
Expand Down Expand Up @@ -243,12 +258,10 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio

private static int GetCostOffsetAt(int index, int parentIndex, int openNum)
{
#if DEBUG
if (FlashSearch && map != null && !fallbackCall)
if (FlashSearch && map != null && !fallbackCall)
{
map.debugDrawer.FlashCell(map.cellIndices.IndexToCell(parentIndex), Mathf.Clamp(PathFinder.calcGrid[parentIndex].knownCost / 1200f,0.001f, 0.99f), $"{PathFinder.calcGrid[parentIndex].knownCost}", duration:50);
}
#endif
if (map != null)
{
float value = 0;
Expand Down
2 changes: 1 addition & 1 deletion Source/Rule56/SightGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class SightGrid
/// </summary>
public ITFloatGrid gridFog;

private int regionUpdateIndex;
// private int regionUpdateIndex;
private int ops;
/// <summary>
/// Whether this is the player grid
Expand Down

0 comments on commit 034922e

Please sign in to comment.