diff --git a/Assemblies/ZombieLand.dll b/Assemblies/ZombieLand.dll index 20a76adb..c9155a1e 100755 Binary files a/Assemblies/ZombieLand.dll and b/Assemblies/ZombieLand.dll differ diff --git a/Source/Patches.cs b/Source/Patches.cs index 7b41ad83..3e08d0f8 100755 --- a/Source/Patches.cs +++ b/Source/Patches.cs @@ -125,14 +125,14 @@ static void Postfix() } // patch for debugging: show zombie pathing grid around the mouse - /* + // [HarmonyPatch(typeof(MapInterface))] [HarmonyPatch("MapInterfaceOnGUI_AfterMainTabs")] class MapInterface_MapInterfaceOnGUI_AfterMainTabs_Patch { static void Postfix() { - if (DebugViewSettings.writePathCosts == false) return; + if (Constants.DEBUGGRID == false || DebugViewSettings.writeBeauty == false) return; if (Event.current.type != EventType.Repaint) return; var map = Find.CurrentMap; @@ -158,7 +158,6 @@ static void Postfix() }); } } - */ // patch to show zombieland version and total number of zombies // @@ -1056,6 +1055,60 @@ static IEnumerable Transpiler(IEnumerable inst } } + // do not open doors when not drafted and they are marked by the avoid grid + // + [HarmonyPatch] + static class Building_Door_PawnCanOpen_Patch + { + static void Postfix(Building_Door __instance, Pawn p, ref bool __result) + { + if (__result == false) + return; + + if (p == null || p.Map == null || p.Drafted) + return; + + if (__instance.FreePassage) + return; + + if (p.CurJob?.playerForced ?? false) + return; + + if (Tools.ShouldAvoidZombies(p) == false) + return; + + var map = p.Map; + + var tickManager = map.GetComponent(); + if (tickManager == null) + return; + + var avoidGrid = tickManager.avoidGrid; + + var size = __instance.def.size; + if (size.x == 1 && size.z == 1) + { + if (avoidGrid.ShouldAvoid(map, __instance.Position)) + __result = false; + } + else + { + var cells = __instance.OccupiedRect().Cells; + if (cells.Any(cell => avoidGrid.ShouldAvoid(map, cell))) + __result = false; + } + } + + static IEnumerable TargetMethods() + { + return GenTypes.AllSubclasses(typeof(Building_Door)) + .Union(new List() { typeof(Building_Door) }) + .Select(type => type.GetMethod("PawnCanOpen", AccessTools.all | BindingFlags.DeclaredOnly)) + .Where(method => method != null) + .Cast(); + } + } + // patch to stop jobs when zombies have to be avoided // [HarmonyPatch(typeof(JobDriver))] diff --git a/Source/WorkGivers.cs b/Source/WorkGivers.cs index 05c7fa17..4e124cc7 100644 --- a/Source/WorkGivers.cs +++ b/Source/WorkGivers.cs @@ -37,11 +37,10 @@ public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false) if (forced == false && ColonistSettings.Values.ConfigFor(pawn).autoExtractZombieSerum == false) return false; - if (pawn.CanReach(corpse, PathEndMode.ClosestTouch, pawn.NormalMaxDanger(), false, TraverseMode.ByPawn) == false) + if (pawn.CanReach(corpse, PathEndMode.ClosestTouch, forced ? Danger.Deadly : Danger.None) == false) return false; - return pawn.CanReserve(corpse, 1, -1, null, forced); - /*var result = pawn.CanReserve(corpse, 1, -1, null, forced); + var result = pawn.CanReserve(corpse, 1, -1, null, forced); if (result && forced == false && ZombieSettings.Values.betterZombieAvoidance) { var map = pawn.Map; @@ -56,7 +55,7 @@ public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false) return false; } } - return result;*/ + return result; } public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)