public static bool Postfix(bool __result, WorkGiver_BuildRoof __instance, Pawn pawn, IntVec3 c, bool forced)
 {
     if (__result && pawn.IsPrisonerOfColony)
     {
         try
         {
             System.Reflection.MethodInfo methodInfo = AccessTools.Method(typeof(WorkGiver_BuildRoof), "BuildingToTouchToBeAbleToBuildRoof");
             Building building = methodInfo.Invoke(__instance, new object[] { c, pawn }) as Building;
             if (building != null)
             {
                 return(pawn.CanReach(building, Verse.AI.PathEndMode.Touch, pawn.NormalMaxDanger()));
             }
         } catch (Exception e)
         {
             Verse.Log.Message($"Exception in roof patch{e}");
         }
     }
     return(__result);
 }
        public override void SortAndFilterJobTargets(Pawn meeseeks, CompMeeseeksMemory memory, SavedJob savedJob)
        {
            Map map = meeseeks.MapHeld;
            WorkGiver_BuildRoof scanner = savedJob.workGiverDef.Worker as WorkGiver_BuildRoof;

            SavedTargetInfo bestTarget          = null;
            float           bestDistanceSquared = float.MaxValue;

            for (int i = memory.jobTargets.Count - 1; i >= 0; --i)
            {
                SavedTargetInfo target = memory.jobTargets[i];
                if (target.Cell.Roofed(map))
                {
                    CollectNewTargets(meeseeks, memory, target.Cell, map);
                    memory.jobTargets.RemoveAt(i);
                }
            }

            foreach (SavedTargetInfo target in memory.jobTargets)
            {
                if (meeseeks.CanReach(target.Cell, scanner.PathEndMode, Danger.Deadly) && meeseeks.CanReserve(target.Cell, 1, -1, ReservationLayerDefOf.Ceiling, false))
                {
                    float distanceSquared = (target.Cell - meeseeks.Position).LengthHorizontalSquared;

                    if (distanceSquared < bestDistanceSquared)
                    {
                        bestTarget          = target;
                        bestDistanceSquared = distanceSquared;
                    }
                }
            }

            if (bestTarget != null)
            {
                memory.jobTargets.Remove(bestTarget);
                memory.jobTargets.Insert(0, bestTarget);
            }
        }