static void Postfix(RecipeWorkerCounter __instance, ref int __result, Bill_Production bill) { if (bill.includeFromZone == null) { int i = 0; ThingDef targetDef = __instance.recipe.products[0].thingDef; PRFGameComponent gamecomp = Current.Game.GetComponent <PRFGameComponent>(); for (i = 0; i < gamecomp.AssemblerQueue.Count; i++) { //Don't count Recorces of other maps if (bill.Map != gamecomp.AssemblerQueue[i].Map) { continue; } foreach (Thing heldThing in gamecomp.AssemblerQueue[i].GetThingQueue()) { Thing innerIfMinified = heldThing.GetInnerIfMinified(); if (innerIfMinified.def == targetDef) { __result += innerIfMinified.stackCount; } } } } }
private static int CountPawnThings(Pawn pawn, RecipeWorkerCounter counter, Bill_Production bill, ThingDef productThingDef, bool onlyCarry = false) { int count = 0; if (pawn.apparel != null && !onlyCarry) { count += CountMatchingThingsIn(pawn.apparel.WornApparel.Cast <Thing>(), counter, bill, productThingDef); } if (pawn.equipment != null && !onlyCarry) { count += CountMatchingThingsIn(pawn.equipment.AllEquipmentListForReading.Cast <Thing>(), counter, bill, productThingDef); } if (pawn.inventory != null && !onlyCarry) { count += CountMatchingThingsIn(pawn.inventory.innerContainer, counter, bill, productThingDef); } if (pawn.carryTracker != null) //Bill product immediately carried to stockpile should be counted { count += CountMatchingThingsIn(pawn.carryTracker.innerContainer, counter, bill, productThingDef); } return(count); }
public static bool GetCarriedCount(RecipeWorkerCounter __instance, ref int __result, Bill_Production bill, ThingDef prodDef) { int num = 0; //foreach (Pawn item in bill.Map.mapPawns.FreeColonistsSpawned) if (!RimThreaded.billFreeColonistsSpawned.TryGetValue(bill, out List <Pawn> freeColonistsSpawned)) { freeColonistsSpawned = bill.Map.mapPawns.FreeColonistsSpawned; RimThreaded.billFreeColonistsSpawned[bill] = freeColonistsSpawned; } for (int i = 0; i < freeColonistsSpawned.Count; i++) { Thing carriedThing = freeColonistsSpawned[i]?.carryTracker?.CarriedThing; if (carriedThing == null) { continue; } int stackCount = carriedThing.stackCount; carriedThing = carriedThing.GetInnerIfMinified(); if (__instance.CountValidThing(carriedThing, bill, prodDef)) { num += stackCount; } } __result = num; return(false); }
public static bool GetCarriedCount(RecipeWorkerCounter __instance, ref int __result, Bill_Production bill, ThingDef prodDef) { int num = 0; //foreach (Pawn item in bill.Map.mapPawns.FreeColonistsSpawned) for (int i = 0; i < bill.Map.mapPawns.FreeColonistsSpawned.Count; i++) { Pawn item; try { item = bill.Map.mapPawns.FreeColonistsSpawned[i]; } catch (ArgumentOutOfRangeException) { break; } Thing carriedThing = item.carryTracker.CarriedThing; if (carriedThing != null) { int stackCount = carriedThing.stackCount; carriedThing = carriedThing.GetInnerIfMinified(); if (__instance.CountValidThing(carriedThing, bill, prodDef)) { num += stackCount; } } } __result = num; return(false); }
private static int CountAway(Map billMap, RecipeWorkerCounter counter, Bill_Production bill, ThingDef productThingDef) { int count = 0; // Look for matching items in colonists and animals away from base foreach (var pawn in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_OfPlayerFaction) { if (pawn.GetOriginMap() == billMap) { // OriginMap is only set on our pawns who are away from base count += CountPawnThings(pawn, counter, bill, productThingDef); } } return(count); }
// Helper function to count matching items in inventory lists private static int CountMatchingThingsIn(IEnumerable <Thing> things, RecipeWorkerCounter counterClass, Bill_Production bill, ThingDef productThingDef) { var count = 0; foreach (var thing in things) { Thing item = thing.GetInnerIfMinified(); if (counterClass.CountValidThing(thing, bill, productThingDef)) { count += item.stackCount; } } return(count); }
static void Postfix(ref int __result, RecipeWorkerCounter __instance, Bill_Production bill) { List <ThingDefCountClass> products = __instance.recipe.products; if (WorldComp.HasInfiniteStorages(bill.Map) && products != null) { foreach (ThingDefCountClass product in products) { ThingDef def = product.thingDef; foreach (Building_InfiniteStorage s in WorldComp.GetInfiniteStorages(bill.Map)) { __result += s.StoredThingCount(def, bill.ingredientFilter); } } } }
public static void Postfix(ref RecipeWorkerCounter __instance, ref int __result, ref Bill_Production bill) { var extendedBillData = Main.Instance.GetExtendedBillDataStorage().GetExtendedDataFor(bill); if (extendedBillData == null) { return; } if (extendedBillData.ProductAdditionalFilter != null) { __result += CountAdditionalProducts(__instance, bill, extendedBillData); } if (!ExtendedBillDataStorage.CanOutputBeFiltered(bill)) { return; } var productThingDef = bill.recipe.products.First().thingDef; // Count resource items not in stockpiles if (Main.Instance.ShouldCountOutsideStockpiles() && productThingDef.CountAsResource && !bill.includeEquipped && (bill.includeTainted || !productThingDef.IsApparel || !productThingDef.apparel.careIfWornByCorpse) && bill.includeFromZone == null && bill.hpRange.min == 0f && bill.hpRange.max == 1f && bill.qualityRange.min == QualityCategory.Awful && bill.qualityRange.max == QualityCategory.Legendary && !bill.limitToAllowedStuff) { __result += GetMatchingItemCountOutsideStockpiles(bill, productThingDef); } if (!bill.includeEquipped) { return; } if (extendedBillData.CountAway) { __result += CountAway(bill.Map, __instance, bill, productThingDef); } }
static void Postfix(ref int __result, RecipeWorkerCounter __instance, Bill_Production bill) { List <ThingDefCountClass> products = __instance.recipe.products; if (WorldComp.DressersToUse.Count > 0 && products != null) { foreach (ThingDefCountClass product in products) { ThingDef def = product.thingDef; foreach (Building_Dresser d in WorldComp.DressersToUse) { if (bill.Map == d.Map) { __result += d.GetApparelCount(def, bill.qualityRange, bill.hpRange, (bill.limitToAllowedStuff) ? bill.ingredientFilter : null); } } } } }
static void Postfix(ref int __result, RecipeWorkerCounter __instance, Bill_Production bill) { List <ThingDefCountClass> products = __instance.recipe.products; var storages = WorldComp.GetWeaponStorages(bill?.Map); if (storages.Count() > 0 && products != null) { foreach (ThingDefCountClass product in products) { ThingDef def = product.thingDef; if (def.IsWeapon) { foreach (Building_WeaponStorage ws in WorldComp.GetWeaponStorages(bill.Map)) { __result += ws.GetWeaponCount(def, bill.qualityRange, bill.hpRange, (bill.limitToAllowedStuff) ? bill.ingredientFilter : null); } } } } }
static void Postfix(RecipeWorkerCounter __instance, ref int __result, Bill_Production bill) { if (bill.includeFromZone == null) { int i = 0; ThingDef targetDef = __instance.recipe.products[0].thingDef; for (i = 0; i < PRFGameComponent.AssemblerQueue.Count; i++) { foreach (Thing heldThing in PRFGameComponent.AssemblerQueue[i].GetThingQueue()) { Thing innerIfMinified = heldThing.GetInnerIfMinified(); if (innerIfMinified.def == targetDef) { __result += innerIfMinified.stackCount; } } } } }
internal static int CountProductsWithEquivalency(Bill_Production bill, RecipeWorkerCounter counter) { HashSet <string> eqNames = QOLTweaksPack.MealSelection.Value.InnerList; ThingCountClass thingCountClass = counter.recipe.products[0]; //Log.Message("Looking for equivalencies to " + thingCountClass.thingDef); if (thingCountClass.thingDef.CountAsResource) { int total = 0; foreach (string eqName in eqNames) { ThingDef def = DefDatabase <ThingDef> .GetNamed(eqName); int local = bill.Map.resourceCounter.GetCount(def); total += local; //Log.Message("Counted " + local + " of " + def.defName); } return(total); } int num = bill.Map.listerThings.ThingsOfDef(thingCountClass.thingDef).Count; if (thingCountClass.thingDef.Minifiable) { List <Thing> list = bill.Map.listerThings.ThingsInGroup(ThingRequestGroup.MinifiedThing); for (int i = 0; i < list.Count; i++) { MinifiedThing minifiedThing = (MinifiedThing)list[i]; if (eqNames.Contains(minifiedThing.InnerThing.def.defName)) { num++; } } } return(num); }
// Count other things on map for ProductAdditionalFilter // This is sadly most of CountProducts re-written with a for loop for the additional defs public static int CountAdditionalProducts(RecipeWorkerCounter counter, Bill_Production bill, ExtendedBillData extendedBillData) { ThingFilter filter = extendedBillData.ProductAdditionalFilter; bool countAway = extendedBillData.CountAway; Map map = bill.Map; ThingDef defaultProductDef = counter.recipe.products[0].thingDef; int count = 0; foreach (ThingDef def in filter.AllowedThingDefs) { //Obviously skip the default product, it was already counted if (def == defaultProductDef) { continue; } //Same as CountProducts but now with other products if (def.CountAsResource && !bill.includeEquipped && (bill.includeTainted || !def.IsApparel || !def.apparel.careIfWornByCorpse) && bill.includeFromZone == null && bill.hpRange.min == 0f && bill.hpRange.max == 1f && bill.qualityRange.min == QualityCategory.Awful && bill.qualityRange.max == QualityCategory.Legendary && !bill.limitToAllowedStuff) { count += map.resourceCounter.GetCount(def); foreach (Pawn pawn in map.mapPawns.FreeColonistsSpawned) { count += CountPawnThings(pawn, counter, bill, def, true); } } else if (bill.includeFromZone == null) { count += counter.CountValidThings(map.listerThings.ThingsOfDef(def), bill, def); if (def.Minifiable) { List <Thing> list = map.listerThings.ThingsInGroup(ThingRequestGroup.MinifiedThing); for (int i = 0; i < list.Count; i++) { MinifiedThing minifiedThing = (MinifiedThing)list[i]; if (counter.CountValidThing(minifiedThing.InnerThing, bill, def)) { count += minifiedThing.stackCount * minifiedThing.InnerThing.stackCount; } } } if (!bill.includeEquipped) { //Still count Carried Things foreach (Pawn pawn in map.mapPawns.FreeColonistsSpawned) { count += CountPawnThings(pawn, counter, bill, def, true); } } } else { foreach (Thing current in bill.includeFromZone.AllContainedThings) { Thing innerIfMinified = current.GetInnerIfMinified(); if (counter.CountValidThing(innerIfMinified, bill, def)) { count += innerIfMinified.stackCount; } } } if (bill.includeEquipped) { foreach (Pawn pawn in map.mapPawns.FreeColonistsSpawned) { count += CountPawnThings(pawn, counter, bill, def); } } if (countAway) { count += CountAway(map, counter, bill, def); } } return(count); }
//public int CountValidThings(List<Thing> things, Bill_Production bill, ThingDef def) public static bool Prefix(ref int __result, RecipeWorkerCounter __instance, List <Thing> things, Bill_Production bill, ThingDef def) { //Vital fix being stackCount, not just # of things. __result = things.Where(t => __instance.CountValidThing(t, bill, def)).Sum(t => t.stackCount); return(false); }
public static void Postfix(ref RecipeWorkerCounter __instance, ref int __result, ref Bill_Production bill) { if (!bill.includeEquipped) { return; } if (!ExtendedBillDataStorage.CanOutputBeFiltered(bill)) { return; } var billMap = bill.Map; var productThingDef = bill.recipe.products.First().thingDef; // Fix for vanilla not counting items being hauled by colonists or animals foreach (var pawn in billMap.mapPawns.SpawnedPawnsInFaction(Faction.OfPlayer)) { // Ignore prisoners, include animals if (!(pawn.IsFreeColonist || !pawn.IsColonist)) { continue; } if (pawn.carryTracker != null) { __result += CountMatchingThingsIn( pawn.carryTracker.innerContainer, __instance, bill, productThingDef); } } var extendedBillData = Main.Instance.GetExtendedBillDataStorage().GetExtendedDataFor(bill); if (extendedBillData == null || !extendedBillData.CountAway) { return; } // Look for matching items in colonists and animals away from base foreach (var pawn in Find.WorldPawns.AllPawnsAlive) { if (pawn.GetOriginMap() != billMap) { // OriginMap is only set on our pawns who are away from base continue; } if (pawn.apparel != null) { __result += CountMatchingThingsIn(pawn.apparel.WornApparel.Cast <Thing>(), __instance, bill, productThingDef); } if (pawn.equipment != null) { __result += CountMatchingThingsIn(pawn.equipment.AllEquipmentListForReading.Cast <Thing>(), __instance, bill, productThingDef); } if (pawn.inventory != null) { __result += CountMatchingThingsIn(pawn.inventory.innerContainer, __instance, bill, productThingDef); } if (pawn.carryTracker != null) { __result += CountMatchingThingsIn(pawn.carryTracker.innerContainer, __instance, bill, productThingDef); } } }