internal static bool TryGetEntryForPawn(Pawn getter, Pawn eater, out PawnEntry foodSourceEntry, bool allowForbidden) { var pawnPair = new PawnPair(eater, getter); if (AllByPawnPair.TryGetValue(pawnPair, out foodSourceEntry)) { if (!foodSourceEntry.Expired() && (foodSourceEntry.BestFood == null || // Accepts null FoodUtils.IsValidFoodSourceForPawn(foodSourceEntry.BestFood, eater, getter, eater.GetPolicyAssignedTo(), allowForbidden))) { #if DEBUG //Log.Message(string.Format("Found food entry for {0}/{1} = {2}", eater, getter, foodSourceEntry.BestFood)); #endif return(true); } else { #if DEBUG Log.Message(string.Format("Deleted expired food entry for {0} = {1}", pawnPair, foodSourceEntry.BestFood)); #endif AllByPawnPair.Remove(pawnPair); } } else { #if DEBUG Log.Message(string.Format("No food entry found for {0}", pawnPair)); #endif } foodSourceEntry = null; return(false); }
internal static PawnEntry AddPawnEntry(Pawn getter, Pawn eater, List <FoodSourceRating> rankedFoodSources) { var pair = new PawnPair(eater, getter); #if DEBUG string textlist = ""; textlist += "Added food entry for " + pair + ". Food sources count:" + (rankedFoodSources.Count); Log.Message(textlist); #endif //mapentry.ByRace[PawnGroupEntryKey.ForPawn(eater)].ByPawn.Add(eater, new PawnEntry() { BestFood = foodSource }); var pawnEntry = new PawnEntry() { AllRankedFoods = rankedFoodSources }; AllByPawnPair.Add(pair, pawnEntry); return(pawnEntry); }