static Thing TestFoodFunction([NotNull] FoodFinderFunc func, [NotNull] Pawn tstPawn, out ThingDef oDef) { bool desperate = tstPawn.needs.food.CurCategory == HungerCategory.Starving; func(tstPawn, tstPawn, desperate, out Thing thing, out oDef); return(thing); }
static void TestFoodFunction([NotNull] FoodFinderFunc func, [NotNull] List <Pawn> testers, [NotNull] List <float> results, StringBuilder messageBuilder) { List <(Plant plant, ThingDef eatingDef, Pawn eater)> plantsFound = new List <(Plant plant, ThingDef eatingDef, Pawn eater)>(); for (int i = 0; i < ITERATIONS; i++) { Stopwatch sWatch = Stopwatch.StartNew(); foreach (Pawn p in testers) { if (p == null || p.Dead || p.Destroyed || p.Map == null) { continue; } try { ThingDef tDef; var t = TestFoodFunction(func, p, out tDef); if (t is Plant plant && p.IsHumanlike()) { plantsFound.Add((plant, tDef, p)); } } catch (Exception e) { Log.Message($"caught {e.GetType().Name} while testing {p.Name}\n{e}"); } } var dur = sWatch.ElapsedMilliseconds; sWatch.Stop(); results.Add(dur); if (plantsFound.Count > 0) { var lStr = plantsFound.Join(tup => $"{tup.plant.def.defName}, {tup.eatingDef.defName}, {tup.eater.Name}", "\n"); messageBuilder.AppendLine(lStr); } } }