From 4abcb955bf24c44087bb371e5a408295e45c1161 Mon Sep 17 00:00:00 2001 From: Safairette <71556532+Safairette@users.noreply.github.com> Date: Sat, 11 Nov 2023 18:45:23 +0200 Subject: [PATCH 1/2] Make loadouts respect food restrictions --- .../CombatExtended/Jobs/JobGiver_UpdateLoadout.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Source/CombatExtended/CombatExtended/Jobs/JobGiver_UpdateLoadout.cs b/Source/CombatExtended/CombatExtended/Jobs/JobGiver_UpdateLoadout.cs index 1b2ac52a4b..b0bc8ab2f8 100644 --- a/Source/CombatExtended/CombatExtended/Jobs/JobGiver_UpdateLoadout.cs +++ b/Source/CombatExtended/CombatExtended/Jobs/JobGiver_UpdateLoadout.cs @@ -215,7 +215,7 @@ private static void FindPickup(Pawn pawn, LoadoutSlot curSlot, int findCount, ou { findItem = t => t.GetInnerIfMinified().def == curSlot.thingDef; } - Predicate search = t => findItem(t) && !t.IsForbidden(pawn) && pawn.CanReserve(t, 10, 1) && !isFoodInPrison(t) && AllowedByBiocode(t, pawn); + Predicate search = t => findItem(t) && !t.IsForbidden(pawn) && pawn.CanReserve(t, 10, 1) && !isFoodInPrison(t) && AllowedByBiocode(t, pawn) && AllowedByFoodRestriction(t, pawn); // look for a thing near the pawn. curThing = GenClosest.ClosestThingReachable( @@ -278,6 +278,18 @@ private static bool AllowedByBiocode(Thing thing, Pawn pawn) return (compBiocoded == null || !compBiocoded.Biocoded || compBiocoded.CodedPawn == pawn); } + private static bool AllowedByFoodRestriction(Thing thing, Pawn pawn) + { + if (thing != null && thing.def.IsIngestible) + { + return pawn.foodRestriction.GetCurrentRespectedRestriction(pawn).Allows(thing); + } + else + { + return true; + } + } + /// /// Tries to give the pawn a job related to picking up or dropping an item from their inventory. /// From 308e328c92bd64d7af216a0e27bda9dc25e1dc5a Mon Sep 17 00:00:00 2001 From: Safairette <71556532+Safairette@users.noreply.github.com> Date: Sat, 11 Nov 2023 18:52:07 +0200 Subject: [PATCH 2/2] exclude drugs from check --- .../CombatExtended/Jobs/JobGiver_UpdateLoadout.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/CombatExtended/CombatExtended/Jobs/JobGiver_UpdateLoadout.cs b/Source/CombatExtended/CombatExtended/Jobs/JobGiver_UpdateLoadout.cs index b0bc8ab2f8..de8db31d47 100644 --- a/Source/CombatExtended/CombatExtended/Jobs/JobGiver_UpdateLoadout.cs +++ b/Source/CombatExtended/CombatExtended/Jobs/JobGiver_UpdateLoadout.cs @@ -280,7 +280,7 @@ private static bool AllowedByBiocode(Thing thing, Pawn pawn) private static bool AllowedByFoodRestriction(Thing thing, Pawn pawn) { - if (thing != null && thing.def.IsIngestible) + if (thing != null && thing.def.IsNutritionGivingIngestible) { return pawn.foodRestriction.GetCurrentRespectedRestriction(pawn).Allows(thing); }