public static IntVec3 getClosestAreaLoc(Pawn pawn, Area_Stable areaFound) { IntVec3 targetLoc = new IntVec3(); double minDistance = double.MaxValue; foreach (IntVec3 loc in areaFound.ActiveCells) { double distance = DistanceUtility.QuickDistance(loc, pawn.Position); if (distance < minDistance) { minDistance = distance; targetLoc = loc; } } return(targetLoc); }
private static void parkAnimal(Pawn_JobTracker __instance, Pawn pawn, ExtendedPawnData pawnData) { Area_Stable areaFound = (Area_Stable)pawn.Map.areaManager.GetLabeled(Base.STABLE_LABEL); IntVec3 targetLoc = pawn.Position; if (areaFound != null) { targetLoc = DistanceUtility.getClosestAreaLoc(pawn, areaFound); } Job dismountJob = new Job(GUC_JobDefOf.Dismount); dismountJob.count = 1; __instance.jobQueue.EnqueueFirst(dismountJob); __instance.jobQueue.EnqueueFirst(new Job(JobDefOf.Goto, targetLoc)); PawnDuty animalDuty = pawnData.mount.mindState.duty; if (animalDuty != null) { animalDuty.focus = new LocalTargetInfo(targetLoc); } }