public static void InitializeAllThreadStatics() { AttackTargetFinder_Patch.InitializeThreadStatics(); AttackTargetsCache_Patch.InitializeThreadStatics(); BeautyUtility_Patch.InitializeThreadStatics(); CellFinder_Patch.InitializeThreadStatics(); CompCauseGameCondition_Patch.InitializeThreadStatics(); DamageWorker_Patch.InitializeThreadStatics(); DijkstraInt.InitializeThreadStatics(); Fire_Patch.InitializeThreadStatics(); FloatMenuMakerMap_Patch.InitializeThreadStatics(); FoodUtility_Patch.InitializeThreadStatics(); FloodFiller_Patch.InitializeThreadStatics(); GenAdj_Patch.InitializeThreadStatics(); GenAdjFast_Patch.InitializeThreadStatics(); GenLeaving_Patch.InitializeThreadStatics(); GenRadial_Patch.InitializeThreadStatics(); GenTemperature_Patch.InitializeThreadStatics(); GenText_Patch.InitializedThreadStatics(); HaulAIUtility_Patch.InitializeThreadStatics(); ImmunityHandler_Patch.InitializeThreadStatics(); InfestationCellFinder_Patch.InitializeThreadStatics(); MapTemperature_Patch.InitializeThreadStatics(); PathFinder_Patch.InitializeThreadStatics(); Pawn_InteractionsTracker_Transpile.InitializeThreadStatics(); Pawn_MeleeVerbs_Patch.InitializeThreadStatics(); Pawn_WorkSettings_Patch.InitializeThreadStatics(); PawnDiedOrDownedThoughtsUtility_Patch.InitializeThreadStatics(); PawnsFinder_Patch.InitializeThreadStatics(); Rand_Patch.InitializeThreadStatics(); RCellFinder_Patch.InitializeThreadStatics(); Reachability_Patch.InitializeThreadStatics(); ReachabilityCache_Patch.InitializeThreadStatics(); RegionDirtyer_Patch.InitializeThreadStatics(); RegionListersUpdater_Patch.InitializeThreadStatics(); RegionTraverser_Transpile.InitializeThreadStatics(); //this Projectile_Patch.InitializeThreadStatics(); ThinkNode_PrioritySorter_Patch.InitializeThreadStatics(); ThoughtHandler_Patch.InitializeThreadStatics(); Verb_Patch.InitializeThreadStatics(); WealthWatcher_Patch.InitializeThreads(); World_Patch.InitializeThreadStatics(); JoyGiver_InteractBuilding_Patch.InitializeThreadStatics(); JoyGiver_InteractBuildingSitAdjacent_Patch.InitializeThreadStatics(); JoyGiver_TakeDrug_Patch.InitializeThreadStatics(); WorkGiver_DoBill_RegionProcessor.InitializeThreadStatics(); Pawn_RelationsTracker_Patch.InitializeThreadStatics(); Battle_Patch.InitializeThreadStatics(); }
public static bool TryFindBestBillIngredients(ref bool __result, Bill bill, Pawn pawn, Thing billGiver, List <ThingCount> chosen) { WorkGiver_DoBill_RegionProcessor workGiver_DoBill_RegionProcessor = new WorkGiver_DoBill_RegionProcessor(); chosen.Clear(); //WorkGiver_DoBill.newRelevantThings.Clear(); //workGiver_DoBill_RegionProcessor.newRelevantThings = new List<Thing>(); //ADD if (bill.recipe.ingredients.Count == 0) { __result = true; return(false); } IntVec3 rootCell = GetBillGiverRootCell(billGiver, pawn); Region rootReg = rootCell.GetRegion(pawn.Map, RegionType.Set_Passable); if (rootReg == null) { __result = false; return(false); } //List<IngredientCount> ingredientsOrdered = new List<IngredientCount>(); //ADD MakeIngredientsListInProcessingOrder(workGiver_DoBill_RegionProcessor.ingredientsOrdered, bill); //CHANGE //WorkGiver_DoBill.relevantThings.Clear(); //List<Thing> relevantThings = new List<Thing>(); //WorkGiver_DoBill.processedThings.Clear(); //HashSet<Thing> processedThings = new HashSet<Thing>(); Predicate <Thing> baseValidator = t => t.Spawned && !t.IsForbidden(pawn) && ((t.Position - billGiver.Position).LengthHorizontalSquared < bill.ingredientSearchRadius * bill.ingredientSearchRadius && bill.IsFixedOrAllowedIngredient(t) && bill.recipe.ingredients.Any( ingNeed => ingNeed.filter.Allows(t))) && pawn.CanReserve(t, 1, -1, null, false); bool billGiverIsPawn = billGiver is Pawn; if (billGiverIsPawn) { AddEveryMedicineToRelevantThings(pawn, billGiver, workGiver_DoBill_RegionProcessor.relevantThings, baseValidator, pawn.Map); //CHANGE if (TryFindBestBillIngredientsInSet2(workGiver_DoBill_RegionProcessor.relevantThings, bill, chosen, rootCell, billGiverIsPawn, workGiver_DoBill_RegionProcessor.ingredientsOrdered)) //CHANGE { workGiver_DoBill_RegionProcessor.relevantThings.Clear(); //CHANGE workGiver_DoBill_RegionProcessor.ingredientsOrdered.Clear(); //CHANGE { __result = true; return(false); } } } TraverseParms traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false); RegionEntryPredicate entryCondition = null; if (Math.Abs(999f - bill.ingredientSearchRadius) >= 1.0) { float radiusSq = bill.ingredientSearchRadius * bill.ingredientSearchRadius; entryCondition = ((from, r) => { if (!r.Allows(traverseParams, false)) { return(false); } CellRect extentsClose = r.extentsClose; int num1 = Math.Abs(billGiver.Position.x - Math.Max(extentsClose.minX, Math.Min(billGiver.Position.x, extentsClose.maxX))); if (num1 > bill.ingredientSearchRadius) { return(false); } int num2 = Math.Abs(billGiver.Position.z - Math.Max(extentsClose.minZ, Math.Min(billGiver.Position.z, extentsClose.maxZ))); return(num2 <= bill.ingredientSearchRadius && (num1 * num1 + num2 * num2) <= radiusSq); }); } else { entryCondition = (from, r) => r.Allows(traverseParams, false); } int adjacentRegionsAvailable = rootReg.Neighbors.Count(region => entryCondition(rootReg, region)); //int regionsProcessed = 0; workGiver_DoBill_RegionProcessor.processedThings.AddRange(workGiver_DoBill_RegionProcessor.relevantThings); //CHANGE x2 //processedThings, pawn, baseValidator, billGiverIsPawn, newRelevantThings, adjacentRegionsAvailable, relevantThings, bill, chosen, rootCell, ingredientsOrdered workGiver_DoBill_RegionProcessor.pawn = pawn; workGiver_DoBill_RegionProcessor.bill = bill; workGiver_DoBill_RegionProcessor.baseValidator = baseValidator; workGiver_DoBill_RegionProcessor.billGiverIsPawn = billGiverIsPawn; workGiver_DoBill_RegionProcessor.adjacentRegionsAvailable = adjacentRegionsAvailable; workGiver_DoBill_RegionProcessor.rootCell = rootCell; workGiver_DoBill_RegionProcessor.chosen = chosen; RegionProcessor regionProcessor = workGiver_DoBill_RegionProcessor.Get_RegionProcessor; RegionTraverser.BreadthFirstTraverse(rootReg, entryCondition, regionProcessor, 99999, RegionType.Set_Passable); //WorkGiver_DoBill.relevantThings.Clear(); //WorkGiver_DoBill.newRelevantThings.Clear(); //WorkGiver_DoBill.processedThings.Clear(); //WorkGiver_DoBill.ingredientsOrdered.Clear(); __result = workGiver_DoBill_RegionProcessor.foundAll; return(false); }
public static bool TryFindBestBillIngredients(ref bool __result, Bill bill, Pawn pawn, Thing billGiver, List <ThingCount> chosen) { WorkGiver_DoBill_RegionProcessor workGiver_DoBill_RegionProcessor = new WorkGiver_DoBill_RegionProcessor(); //ADD chosen.Clear(); //COULD REMOVE? //newRelevantThings.Clear(); //REMOVE /* * if (pawn?.Map == null || bill?.recipe?.ingredients == null || billGiver?.Position == null) * { * __result = false; * return false; * }*/ if (bill.recipe.ingredients.Count == 0) { __result = true; return(false); } IntVec3 rootCell = GetBillGiverRootCell(billGiver, pawn); Region rootReg = rootCell.GetRegion(pawn.Map); if (rootReg == null) { __result = false; return(false); } MakeIngredientsListInProcessingOrder(WorkGiver_DoBill_RegionProcessor.ingredientsOrdered, bill); //CHANGE //WorkGiver_DoBill.relevantThings.Clear(); REMOVE //WorkGiver_DoBill.processedThings.Clear(); REMOVE //bool foundAll = false; REMOVE Predicate <Thing> baseValidator = t => t.Spawned && !t.IsForbidden(pawn) && ((t.Position - billGiver.Position).LengthHorizontalSquared < bill.ingredientSearchRadius * bill.ingredientSearchRadius && bill.IsFixedOrAllowedIngredient(t) && bill.recipe.ingredients.Any( ingNeed => ingNeed.filter.Allows(t))) && pawn.CanReserve(t, 1, -1, null, false); bool billGiverIsPawn = billGiver is Pawn; if (billGiverIsPawn) { AddEveryMedicineToRelevantThings2(pawn, billGiver, WorkGiver_DoBill_RegionProcessor.relevantThings, baseValidator, pawn.Map); //CHANGE if (TryFindBestBillIngredientsInSet2(WorkGiver_DoBill_RegionProcessor.relevantThings, bill, chosen, rootCell, billGiverIsPawn, WorkGiver_DoBill_RegionProcessor.ingredientsOrdered)) //CHANGE x2 { WorkGiver_DoBill_RegionProcessor.relevantThings.Clear(); //CHANGE WorkGiver_DoBill_RegionProcessor.ingredientsOrdered.Clear(); //CHANGE { __result = true; return(false); } } } TraverseParms traverseParams = TraverseParms.For(pawn); RegionEntryPredicate entryCondition = null; if (Math.Abs(999f - bill.ingredientSearchRadius) >= 1.0) { float radiusSq = bill.ingredientSearchRadius * bill.ingredientSearchRadius; entryCondition = delegate(Region from, Region r) { if (!r.Allows(traverseParams, false)) { return(false); } CellRect extentsClose = r.extentsClose; int num1 = Math.Abs(billGiver.Position.x - Math.Max(extentsClose.minX, Math.Min(billGiver.Position.x, extentsClose.maxX))); if (num1 > bill.ingredientSearchRadius) { return(false); } int num2 = Math.Abs(billGiver.Position.z - Math.Max(extentsClose.minZ, Math.Min(billGiver.Position.z, extentsClose.maxZ))); return(num2 <= bill.ingredientSearchRadius && (num1 * num1 + num2 * num2) <= radiusSq); }; } else { entryCondition = ((Region from, Region r) => r.Allows(traverseParams, isDestination: false)); } int adjacentRegionsAvailable = rootReg.Neighbors.Count((Region region) => entryCondition(rootReg, region)); //int regionsProcessed = 0; REMOVE WorkGiver_DoBill_RegionProcessor.processedThings.AddRange(WorkGiver_DoBill_RegionProcessor.relevantThings); //CHANGE x2 //processedThings, pawn, baseValidator, billGiverIsPawn, newRelevantThings, adjacentRegionsAvailable, relevantThings, bill, chosen, rootCell, ingredientsOrdered workGiver_DoBill_RegionProcessor.bill = bill; //ADD workGiver_DoBill_RegionProcessor.pawn = pawn; //ADD workGiver_DoBill_RegionProcessor.baseValidator = baseValidator; //ADD workGiver_DoBill_RegionProcessor.billGiverIsPawn = billGiverIsPawn; //ADD workGiver_DoBill_RegionProcessor.adjacentRegionsAvailable = adjacentRegionsAvailable; //ADD workGiver_DoBill_RegionProcessor.rootCell = rootCell; //ADD workGiver_DoBill_RegionProcessor.chosen = chosen; //ADD RegionProcessor regionProcessor = workGiver_DoBill_RegionProcessor.Get_RegionProcessor; //CHANGE RegionTraverser.BreadthFirstTraverse(rootReg, entryCondition, regionProcessor, 99999); //WorkGiver_DoBill.relevantThings.Clear(); REMOVE //WorkGiver_DoBill.newRelevantThings.Clear(); REMOVE //WorkGiver_DoBill.processedThings.Clear(); REMOVE //WorkGiver_DoBill.ingredientsOrdered.Clear(); REMOVE __result = workGiver_DoBill_RegionProcessor.foundAll; //CHANGE return(false); }