protected void FillCard(Rect cardRect) { if (this.tab == Dialog_InfoCard.InfoCardTab.Stats) { if (this.thing != null) { Thing innerThing = this.thing; MinifiedThing minifiedThing = this.thing as MinifiedThing; if (minifiedThing != null) { innerThing = minifiedThing.InnerThing; } StatsReportUtility.DrawStatsReport(cardRect, innerThing); } else if (this.worldObject != null) { StatsReportUtility.DrawStatsReport(cardRect, this.worldObject); } else { StatsReportUtility.DrawStatsReport(cardRect, this.def, this.stuff); } } else if (this.tab == Dialog_InfoCard.InfoCardTab.Character) { CharacterCardUtility.DrawCharacterCard(cardRect, (Pawn)this.thing, null, default(Rect)); } else if (this.tab == Dialog_InfoCard.InfoCardTab.Health) { cardRect.yMin += 8f; HealthCardUtility.DrawPawnHealthCard(cardRect, (Pawn)this.thing, false, false, null); } else if (this.tab == Dialog_InfoCard.InfoCardTab.Records) { RecordsCardUtility.DrawRecordsCard(cardRect, (Pawn)this.thing); } }
protected void FillCard(Rect cardRect) { if (tab == InfoCardTab.Stats) { if (thing != null) { Thing innerThing = thing; MinifiedThing minifiedThing = thing as MinifiedThing; if (minifiedThing != null) { innerThing = minifiedThing.InnerThing; } StatsReportUtility.DrawStatsReport(cardRect, innerThing); } else if (worldObject != null) { StatsReportUtility.DrawStatsReport(cardRect, worldObject); } else { StatsReportUtility.DrawStatsReport(cardRect, def, stuff); } } else if (tab == InfoCardTab.Character) { CharacterCardUtility.DrawCharacterCard(cardRect, (Pawn)thing); } else if (tab == InfoCardTab.Health) { cardRect.yMin += 8f; HealthCardUtility.DrawPawnHealthCard(cardRect, (Pawn)thing, allowOperations: false, showBloodLoss: false, null); } else if (tab == InfoCardTab.Records) { RecordsCardUtility.DrawRecordsCard(cardRect, (Pawn)thing); } }
public virtual int CountProducts(Bill_Production bill) { ThingCountClass thingCountClass = this.recipe.products[0]; if (thingCountClass.thingDef.CountAsResource) { return(bill.Map.resourceCounter.GetCount(thingCountClass.thingDef)); } 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 (minifiedThing.InnerThing.def == thingCountClass.thingDef) { num++; } } } return(num); }
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); }
//public static Blueprint_Install PlaceBlueprintForInstall(MinifiedThing itemToInstall, IntVec3 center, Map map, Rot4 rotation, Faction faction) public static void Prefix(MinifiedThing itemToInstall, IntVec3 center, Map map, Rot4 rotation, Faction faction) { ThingDef def = itemToInstall.InnerThing.def; InterceptBlueprintPlaceBridgeFrame.Prefix(def, center, map, rotation, faction, itemToInstall.InnerThing.Stuff); }
public virtual int CountProducts(Bill_Production bill) { ThingDefCountClass thingDefCountClass = this.recipe.products[0]; ThingDef thingDef = thingDefCountClass.thingDef; if (thingDefCountClass.thingDef.CountAsResource && !bill.includeEquipped && (bill.includeTainted || !thingDefCountClass.thingDef.IsApparel || !thingDefCountClass.thingDef.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) { return(bill.Map.resourceCounter.GetCount(thingDefCountClass.thingDef) + this.GetCarriedCount(bill, thingDef)); } int num = 0; if (bill.includeFromZone == null) { num = this.CountValidThings(bill.Map.listerThings.ThingsOfDef(thingDefCountClass.thingDef), bill, thingDef); if (thingDefCountClass.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 (this.CountValidThing(minifiedThing.InnerThing, bill, thingDef)) { num += minifiedThing.stackCount * minifiedThing.InnerThing.stackCount; } } } num += this.GetCarriedCount(bill, thingDef); } else { foreach (Thing current in bill.includeFromZone.AllContainedThings) { Thing innerIfMinified = current.GetInnerIfMinified(); if (this.CountValidThing(innerIfMinified, bill, thingDef)) { num += innerIfMinified.stackCount; } } } if (bill.includeEquipped) { foreach (Pawn current2 in bill.Map.mapPawns.FreeColonistsSpawned) { List <ThingWithComps> allEquipmentListForReading = current2.equipment.AllEquipmentListForReading; for (int j = 0; j < allEquipmentListForReading.Count; j++) { if (this.CountValidThing(allEquipmentListForReading[j], bill, thingDef)) { num += allEquipmentListForReading[j].stackCount; } } List <Apparel> wornApparel = current2.apparel.WornApparel; for (int k = 0; k < wornApparel.Count; k++) { if (this.CountValidThing(wornApparel[k], bill, thingDef)) { num += wornApparel[k].stackCount; } } ThingOwner directlyHeldThings = current2.inventory.GetDirectlyHeldThings(); for (int l = 0; l < directlyHeldThings.Count; l++) { if (this.CountValidThing(directlyHeldThings[l], bill, thingDef)) { num += directlyHeldThings[l].stackCount; } } } } 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); }
static Job FindBedrollJob(Job fallbackJob, Pawn pawn) { if (!pawn.IsColonistPlayerControlled) { return(fallbackJob); } Log.Message(pawn + " looking for inventory beds"); MinifiedThing invBed = (MinifiedThing)FindMinifiedBed(pawn); if (invBed == null) { return(fallbackJob); } Log.Message(pawn + " found " + invBed); Map map = pawn.Map; Building_Bed bed = (Building_Bed)invBed.GetInnerIfMinified(); Func <IntVec3, Rot4, bool> cellValidatorDir = delegate(IntVec3 c, Rot4 direction) { if (RegionAndRoomQuery.RoomAtFast(c, map).isPrisonCell != pawn.IsPrisoner) { return(false); } if (!GenConstruct.CanPlaceBlueprintAt(invBed.GetInnerIfMinified().def, c, direction, map).Accepted) { return(false); } if (c.IsForbidden(pawn)) { return(false); } for (CellRect.CellRectIterator iterator = GenAdj.OccupiedRect(c, direction, bed.def.size).GetIterator(); !iterator.Done(); iterator.MoveNext()) { foreach (Thing t in iterator.Current.GetThingList(map)) { if (!(t is Pawn) && GenConstruct.BlocksConstruction(bed, t)) { return(false); } } if (!(map.zoneManager.ZoneAt(c) is null)) { return(false); } } return(true); }; // North/East would be redundant, except for cells on edge ; oh well, too much code to handle that Predicate <IntVec3> cellValidator = c => cellValidatorDir(c, Rot4.South) || cellValidatorDir(c, Rot4.West); Predicate <IntVec3> goodCellValidator = c => !RegionAndRoomQuery.RoomAt(c, map).PsychologicallyOutdoors&& cellValidator(c); IntVec3 placePosition = IntVec3.Invalid; IntVec3 root = pawn.Position; TraverseParms trav = TraverseParms.For(pawn); if (!CellFinder.TryFindRandomReachableCellNear(root, map, 4, trav, goodCellValidator, null, out placePosition)) { if (!CellFinder.TryFindRandomReachableCellNear(root, map, 12, trav, goodCellValidator, null, out placePosition)) { if (!CellFinder.TryFindRandomReachableCellNear(root, map, 4, trav, cellValidator, null, out placePosition)) { CellFinder.TryFindRandomReachableCellNear(root, map, 12, trav, cellValidator, null, out placePosition); } } } if (placePosition.IsValid) { Rot4 dir = cellValidatorDir(placePosition, Rot4.South) ? Rot4.South : Rot4.West; Blueprint_Install blueprint = GenConstruct.PlaceBlueprintForInstall(invBed, placePosition, map, dir, pawn.Faction); Log.Message(pawn + " placing " + blueprint + " at " + placePosition); return(new Job(JobDefOf.PlaceBedroll, invBed, blueprint) { haulMode = HaulMode.ToContainer }); } Log.Message(pawn + " couldn't find place for " + invBed); return(fallbackJob); }
public virtual void RegenerateStock() { TryDestroyStock(); int raidsCount = Find.StoryWatcher.statsRecord.numRaidsEnemy - lastRaidsEnemy; lastRaidsEnemy = raidsCount; int itemsCount = (int)itemsCountPerRaidCurve.Evaluate(raidsCount); float valueRange = startMarketValue + (marketValueMultiplierPerMapEvent * raidsCount); ThingSetMaker_MarketValue maker = new ThingSetMaker_MarketValue(); ThingSetMakerParams parms = default; parms.totalMarketValueRange = new FloatRange(valueRange, valueRange); parms.countRange = new IntRange(itemsCount, itemsCount); parms.filter = DarkNetPriceUtils.GetThingFilter(def.AvaliableGoods); maker.fixedParams = parms; var items = maker.Generate(); stock = new List <SellableItemWithModif>(); foreach (var item in items) { int itemValue = (int)(item.MarketValue * Character.Greed); if (PriceModificatorUtils.TryGetPriceModificator(item, def, out PriceModificatorDef modificator)) { itemValue = (int)(itemValue * modificator.PriceModficator); DarkNetPriceUtils.FinalizeItem(item, modificator); } MinifiedThing minifiedThing = item as MinifiedThing; if (minifiedThing != null) { var quality = minifiedThing.InnerThing.TryGetComp <CompQuality>(); if (quality != null) { quality.SetQuality(QualityUtility.GenerateQualityRandomEqualChance(), ArtGenerationContext.Colony); itemValue = (int)(itemValue * GetPriceMultiplierForQuality(quality.Quality)); } } else { var quality = item.TryGetComp <CompQuality>(); if (quality != null) { quality.SetQuality(QualityUtility.GenerateQualityRandomEqualChance(), ArtGenerationContext.Colony); itemValue = (int)(itemValue * GetPriceMultiplierForQuality(quality.Quality)); } } stock.Add(new SellableItemWithModif(item, itemValue, modificator)); } if (raidsCount >= minRaidsCountToGeneralGood && Rand.Chance(generalGoodsChance)) { parms.totalMarketValueRange = new FloatRange(specialGoodMarketValue, specialGoodMarketValue); parms.countRange = new IntRange(1, 1); parms.filter = specialGoodsFilter; maker.fixedParams = parms; Thing generalGood = maker.Generate().FirstOrDefault(); if (generalGood != null) { goodOfTheWeek = new SellableItemWithModif(generalGood, (int)(generalGood.MarketValue * Character.Greed), null); } } }
public void ReplaceVanillaBarrels() { if (Current.ProgramState != ProgramState.Playing) { return; } foreach (Map map in Find.Maps) { foreach (Thing thing in map.listerThings.ThingsOfDef(ThingDefOf.FermentingBarrel).ToList()) { bool inUse = false; float progress = 0; int fillCount = 0; IntVec3 position = thing.Position; ThingDef stuff; if (thing.Stuff != null) { stuff = thing.Stuff; } else { stuff = ThingDefOf.WoodLog; } if (thing is Building_FermentingBarrel oldBarrel) { inUse = oldBarrel.SpaceLeftForWort < 25; if (inUse) { progress = oldBarrel.Progress; fillCount = 25 - oldBarrel.SpaceLeftForWort; } } Thing newBarrel = ThingMaker.MakeThing(UF_DefOf.UniversalFermenter, stuff); GenSpawn.Spawn(newBarrel, position, map); if (inUse) { CompUniversalFermenter compUF = newBarrel.TryGetComp <CompUniversalFermenter>(); compUF.CurrentProcess = compUF.Props.processes.First(p => p.thingDef == ThingDefOf.Beer); Thing wort = ThingMaker.MakeThing(ThingDefOf.Wort, null); wort.stackCount = fillCount; compUF.AddIngredient(wort); compUF.ProgressTicks = (int)(360000 * progress); } } foreach (Thing thing in map.listerThings.ThingsOfDef(ThingDefOf.MinifiedThing).Where(t => t.GetInnerIfMinified().def == ThingDefOf.FermentingBarrel)) { MinifiedThing minifiedThing = thing as MinifiedThing; ThingDef stuff; if (minifiedThing.InnerThing.Stuff != null) { stuff = minifiedThing.InnerThing.Stuff; } else { stuff = ThingDefOf.WoodLog; } minifiedThing.InnerThing = null; Thing newBarrel = ThingMaker.MakeThing(UF_DefOf.UniversalFermenter, stuff); minifiedThing.InnerThing = newBarrel; cachedGraphic.SetValue(minifiedThing, null); } } }
//protected override Job TryGiveJob(Pawn pawn) public static void Postfix(ref Job __result, Pawn pawn) { if (__result == null) { return; } if (!pawn.IsColonistPlayerControlled) { return; } Map map = pawn.Map; if (!Settings.Get().alsoColonies&& map.IsPlayerHome) { if (!Settings.Get().alsoColoniesKnown) { Settings.Get().alsoColoniesKnown = true; Settings.Get().Write(); Find.LetterStack.ReceiveLetter("TD.UseBedrollsUpdated".Translate(), TranslatorFormattedStringExtensions.Translate("TD.UpdateNewsColonyMaps", pawn), LetterDefOf.NeutralEvent, pawn); // I don't think this really needs to be hugslibs update news or anything. alsoColoniesKnown defaults } return; } if (__result.targetA.Thing is Building_Bed ownedBed) { if (!Settings.Get().distanceCheck || (ownedBed.Position).DistanceTo(pawn.Position) < Settings.Get().distance) { return; //Have a bed that close enough, no need to get from inventory } } MinifiedThing invBed = (MinifiedThing)FindMinifiedBed(pawn); if (invBed == null) { return; } Log.Message($"{pawn} found {invBed}"); Building_Bed bed = (Building_Bed)invBed.GetInnerIfMinified(); Func <IntVec3, Rot4, bool> cellValidatorDir = delegate(IntVec3 c, Rot4 direction) { if (RegionAndRoomQuery.RoomAt(c, map).isPrisonCell != pawn.IsPrisoner) { return(false); } if (!GenConstruct.CanPlaceBlueprintAt(invBed.GetInnerIfMinified().def, c, direction, map).Accepted) { return(false); } //Support ReplaceStuff allowing blueprints over beds if (EdificeBlocking(invBed.GetInnerIfMinified().def, c, direction, map)) { return(false); } if (!GenConstruct.CanPlaceBlueprintAt(invBed.GetInnerIfMinified().def, c, direction, map).Accepted) { return(false); } //Each cell of bed: foreach (var pos in GenAdj.OccupiedRect(c, direction, bed.def.size)) { if (map.zoneManager.ZoneAt(pos) != null) { return(false); } foreach (Thing t in pos.GetThingList(map)) { if (!(t is Pawn) && GenConstruct.BlocksConstruction(bed, t)) { return(false); } } } return(true); }; IntVec3 root = invBed.PositionHeld; // North/East would be redundant, except for cells on edge ; oh well, too much code to handle that Predicate <IntVec3> cellValidator = delegate(IntVec3 c) { if (!cellValidatorDir(c, Rot4.South) && !cellValidatorDir(c, Rot4.West)) { return(false); } using (PawnPath path = map.pathFinder.FindPath(root, c, pawn)) { return(path.TotalCost < 500); } }; Predicate <IntVec3> goodCellValidator = c => !RegionAndRoomQuery.RoomAt(c, map).PsychologicallyOutdoors&& cellValidator(c); IntVec3 placePosition = IntVec3.Invalid; TraverseParms trav = TraverseParms.For(pawn); if (!CellFinder.TryFindRandomReachableCellNear(root, map, 4, trav, goodCellValidator, null, out placePosition)) { if (!CellFinder.TryFindRandomReachableCellNear(root, map, 12, trav, goodCellValidator, null, out placePosition)) { if (!CellFinder.TryFindRandomReachableCellNear(root, map, 4, trav, cellValidator, null, out placePosition)) { CellFinder.TryFindRandomReachableCellNear(root, map, 12, trav, cellValidator, null, out placePosition); } } } if (placePosition.IsValid) { Rot4 dir = cellValidatorDir(placePosition, Rot4.South) ? Rot4.South : Rot4.West; Blueprint_Install blueprint = GenConstruct.PlaceBlueprintForInstall(invBed, placePosition, map, dir, pawn.Faction); Log.Message($"{pawn} placing {blueprint} at {placePosition}"); __result = new Job(JobDefOf.PlaceBedroll, invBed, blueprint) { haulMode = HaulMode.ToContainer }; } }
private IEnumerable <Thing> GenerateTraderThings(TraderKindDef traderDef) { bool flag = false; List <StockGenerator> .Enumerator enumerator = traderDef.stockGenerators.GetEnumerator(); while (enumerator.MoveNext()) { StockGenerator currentGenerator = enumerator.Current; IEnumerator <Thing> generatedThings = currentGenerator.GenerateThings().GetEnumerator(); try { while (generatedThings.MoveNext()) { Thing generatedThing = generatedThings.Current; if (!(currentGenerator is StockGenerator_Treasures) && generatedThing.def.tradeability != Tradeability.Stockable) { Log.Error(string.Concat(new object[] { traderDef, " generated carrying ", generatedThing, " which has is not Stockable. Ignoring..." })); } else { CompQuality compQuality = generatedThing.TryGetComp <CompQuality>(); if (compQuality != null) { compQuality.SetQuality(QualityUtility.RandomTraderItemQuality(), ArtGenerationContext.Outsider); } if (generatedThing.def.colorGeneratorInTraderStock != null) { var color = generatedThing.def.colorGeneratorInTraderStock.NewRandomizedColor(); generatedThing.SetColor(color, true); } if (generatedThing.def.Minifiable) { int stackCount = generatedThing.stackCount; generatedThing.stackCount = 1; MinifiedThing minifiedThing = generatedThing.MakeMinified(); minifiedThing.stackCount = stackCount; generatedThing = minifiedThing; } flag = true; yield return(generatedThing); } } } finally { if (!flag) { if (generatedThings != null) { generatedThings.Dispose(); } } } } yield break; }
public static bool TryGetPriceModificator(Thing useItem, DarkNetTraderDef traderDef, out PriceModificatorDef modificator) { Thing item = useItem; modificator = null; MinifiedThing minifiedThing = item as MinifiedThing; if (minifiedThing != null) { item = minifiedThing.InnerThing; } if (traderDef.AllowedPriceModificatorsFilter == null || traderDef.AllowedPriceModificatorsFilter.AllowedPriceModificators == null) { return(false); } List <PriceModificatorDef> allowedModificators = traderDef.AllowedPriceModificatorsFilter.AllowedPriceModificators.Where(delegate(PriceModificatorDef x) { if (x.SpecialThings != null && x.SpecialThings.Contains(item.def)) { return(true); } if (x.LinkedCategory != null && item.def.thingCategories != null) { foreach (var category in x.LinkedCategory) { if (item.def.thingCategories.Contains(category)) { return(true); } } } if (x.TradeCategories != null && item.def.tradeTags != null) { foreach (var category in x.TradeCategories) { if (item.def.tradeTags.Contains(category)) { return(true); } } } return(false); }).ToList(); if (allowedModificators.Count == 0) { return(false); } if (allowedModificators.TryRandomElementByWeight(x => x.Commonality, out modificator)) { return(true); } return(false); }