public static bool get_FreeColonistsSpawnedOrInPlayerEjectablePodsCount(MapPawns __instance, ref int __result) { int num = 0; lock (pawnsSpawned(__instance)) { for (int index = 0; index < pawnsSpawned(__instance).Count; ++index) { if (pawnsSpawned(__instance)[index].IsFreeColonist) { ++num; } } } List <Thing> thingList = map(__instance).listerThings.ThingsInGroup(ThingRequestGroup.ThingHolder); for (int index1 = 0; index1 < thingList.Count; ++index1) { if (thingList[index1] is Building_CryptosleepCasket cryptosleepCasket && cryptosleepCasket.def.building.isPlayerEjectable || (thingList[index1] is IActiveDropPod || thingList[index1] is PawnFlyer) || thingList[index1].TryGetComp <CompTransporter>() != null) { IThingHolder holder = (IThingHolder)thingList[index1].TryGetComp <CompTransporter>() ?? (IThingHolder)thingList[index1]; List <Thing> tmpThings = new List <Thing>(); ThingOwnerUtility.GetAllThingsRecursively(holder, tmpThings, true, (Predicate <IThingHolder>)null); for (int index2 = 0; index2 < tmpThings.Count; ++index2) { if (tmpThings[index2] is Pawn tmpThing && !tmpThing.Dead && tmpThing.IsFreeColonist) { ++num; } } } } __result = num; return(false); }
private float CalculateWealthItems() { tmpThings.Clear(); ThingOwnerUtility.GetAllThingsRecursively(map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), tmpThings, allowUnreal : false, delegate(IThingHolder x) { if (x is PassingShip || x is MapComponent) { return(false); } Pawn pawn = x as Pawn; if (pawn != null && pawn.Faction != Faction.OfPlayer) { return(false); } return((pawn == null || !pawn.IsQuestLodger()) ? true : false); }); float num = 0f; for (int i = 0; i < tmpThings.Count; i++) { if (tmpThings[i].SpawnedOrAnyParentSpawned && !tmpThings[i].PositionHeld.Fogged(map)) { num += tmpThings[i].MarketValue * (float)tmpThings[i].stackCount; } } tmpThings.Clear(); return(num); }
private static void HighFreqAffixes() { foreach (LootAffixModifier modifier in DefDatabase <LootAffixDef> .AllDefs.SelectMany(lad => lad.modifiers)) { if (modifier is LootAffixModifier_DoOverTime dot) { dot.mtbDays = 0.01f; } if (modifier.chance < 0.5f) { modifier.chance = 0.5f; } } var tmpList = new List <ThingWithComps> { }; ThingOwnerUtility.GetAllThingsRecursively( map: Find.CurrentMap, request: ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), outThings: tmpList ); foreach (CompLootAffixableThing comp in tmpList.Select(twc => twc.TryGetComp <CompLootAffixableThing>()).Where(c => c != null)) { comp.PostAffixCleanup(); } Messages.Message("All LootAffixModifiers set to high-frequency mode until RimWorld restarts", MessageTypeDefOf.NeutralEvent, false); }
private void TakeFromCaravan(Caravan caravan, List <ThingCount> demands, Faction enemyFaction) { List <Thing> list = new List <Thing>(); for (int i = 0; i < demands.Count; i++) { ThingCount thingCount = demands[i]; if (thingCount.Thing is Pawn) { Pawn pawn = (Pawn)thingCount.Thing; caravan.RemovePawn(pawn); foreach (Thing thing in ThingOwnerUtility.GetAllThingsRecursively(pawn, false)) { list.Add(thing); thing.holdingOwner.Take(thing); } enemyFaction.kidnapped.KidnapPawn(pawn, null); } else { thingCount.Thing.SplitOff(thingCount.Count).Destroy(DestroyMode.Vanish); } } for (int j = 0; j < list.Count; j++) { if (!list[j].Destroyed) { CaravanInventoryUtility.GiveThing(caravan, list[j]); } } }
private List <ThingCount> TryGenerateItemsDemand(Caravan caravan) { List <ThingCount> list = new List <ThingCount>(); List <Thing> list2 = new List <Thing>(); list2.AddRange(caravan.PawnsListForReading.SelectMany((Pawn x) => ThingOwnerUtility.GetAllThingsRecursively(x, allowUnreal: false))); list2.RemoveAll((Thing x) => x.MarketValue * (float)x.stackCount < 50f); list2.RemoveAll(delegate(Thing x) { if (x.ParentHolder is Pawn_ApparelTracker) { return(x.MarketValue < 500f); } return(false); }); float num = list2.Sum((Thing x) => x.MarketValue * (float)x.stackCount); float requestedCaravanValue = Mathf.Clamp(DemandAsPercentageOfCaravan.RandomInRange * num, 300f, 3500f); while (requestedCaravanValue > 50f) { if (!(from x in list2 where x.MarketValue * (float)x.stackCount <= requestedCaravanValue * 2f select x).TryRandomElementByWeight((Thing x) => Mathf.Pow(x.MarketValue / x.GetStatValue(StatDefOf.Mass), 2f), out Thing result)) { return(null); } int num2 = Mathf.Clamp((int)(requestedCaravanValue / result.MarketValue), 1, result.stackCount); requestedCaravanValue -= result.MarketValue * (float)num2; list.Add(new ThingCount(result, num2)); list2.Remove(result); } return(list); }
private float CalculateWealthItems() { this.tmpThings.Clear(); ThingOwnerUtility.GetAllThingsRecursively <Thing>(this.map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), this.tmpThings, false, delegate(IThingHolder x) { bool result; if (x is PassingShip || x is MapComponent) { result = false; } else { Pawn pawn = x as Pawn; result = (pawn == null || pawn.Faction == Faction.OfPlayer); } return(result); }, true); float num = 0f; for (int i = 0; i < this.tmpThings.Count; i++) { if (this.tmpThings[i].SpawnedOrAnyParentSpawned && !this.tmpThings[i].PositionHeld.Fogged(this.map)) { num += this.tmpThings[i].MarketValue * (float)this.tmpThings[i].stackCount; } } this.tmpThings.Clear(); return(num); }
private static float CalculateWealthItems(WealthWatcher __instance) { //this.tmpThings.Clear(); List <Thing> tmpThings = new List <Thing>(); ThingOwnerUtility.GetAllThingsRecursively <Thing>(map(__instance), ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), tmpThings, false, delegate(IThingHolder x) { if (x is PassingShip || x is MapComponent) { return(false); } Pawn pawn = x as Pawn; return((pawn == null || pawn.Faction == Faction.OfPlayer) && (pawn == null || !pawn.IsQuestLodger())); }, true); float num = 0f; for (int i = 0; i < tmpThings.Count; i++) { if (tmpThings[i].SpawnedOrAnyParentSpawned && !tmpThings[i].PositionHeld.Fogged(map(__instance))) { num += tmpThings[i].MarketValue * tmpThings[i].stackCount; } } //this.tmpThings.Clear(); return(num); }
public static void RecordPlayerAddedMapThings(IThingHolder owner, Map onMap) { var state = GetStateForMap(onMap); var knownOrInvalidThingIds = new HashSet <int>(state.PlayerAddedThingIds.Union(state.ScenarioGeneratedThingIds)); var nonColonistThings = ThingOwnerUtility.GetAllThingsRecursively(owner, false) .Where(t => !(t is Pawn) && !(t is Building) && !knownOrInvalidThingIds.Contains(t.thingIDNumber)); //Logger.Message("Player added things to map: " + nonColonistThings.ListElements()); state.PlayerAddedThingIds.AddRange(nonColonistThings.Select(t => t.thingIDNumber)); }
private List <Thing> GenerateDemands(Caravan caravan) { List <Thing> list = new List <Thing>(); List <Thing> list2 = new List <Thing>(); list2.AddRange(caravan.PawnsListForReading.Cast <Thing>()); list2.AddRange(caravan.PawnsListForReading.SelectMany((Pawn pawn) => ThingOwnerUtility.GetAllThingsRecursively(pawn, false))); float num = list2.Sum((Thing thing) => thing.MarketValue); float num2 = IncidentWorker_CaravanDemand.DemandAsPercentageOfCaravan.RandomInRange * num; while (num2 > 0f) { if (list2.Count((Thing thing) => thing is Pawn && ((Pawn)thing).IsColonist) == 1) { list2.RemoveAll((Thing thing) => thing is Pawn && ((Pawn)thing).IsColonist); } if (list2.Count == 0) { break; } Thing thing2 = list2.RandomElementByWeight(delegate(Thing thing) { float result; if (thing.def == ThingDefOf.Silver) { result = 5f; } else { if (thing is Pawn) { Pawn pawn = (Pawn)thing; if (pawn.RaceProps.Animal) { return(1f); } if (pawn.IsPrisoner) { return(1f); } if (pawn.IsColonist) { return(0.2f); } } result = 1f; } return(result); }); num2 -= thing2.MarketValue; list.Add(thing2); list2.Remove(thing2); } return(list); }
public void Update() { items = new List <WealthItem>(); Map map = Find.CurrentMap; List <Thing> tmpThings = new List <Thing>(); ThingOwnerUtility.GetAllThingsRecursively(map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), tmpThings, false, thing => { return(!(thing is PassingShip) && !(thing is MapComponent) && (!(thing is Pawn pawn) || pawn.Faction == Faction.OfPlayer)); });
private Dictionary <WealthCategory, float> GetWealthByCategory() { // Initialize wealth categories Dictionary <WealthCategory, float> wealthByCategory = new Dictionary <WealthCategory, float>(); foreach (WealthCategory wealthCategory in Enum.GetValues(typeof(WealthCategory))) { wealthByCategory[wealthCategory] = 0f; } // Get all player items List <Thing> allPlayerThings = new List <Thing>(); ThingOwnerUtility.GetAllThingsRecursively(map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), allPlayerThings, allowUnreal : false, delegate(IThingHolder thingHolder) { bool isPlayerThingHolder = true; if (thingHolder is MapComponent) { isPlayerThingHolder = false; } else if (thingHolder is PassingShip) { isPlayerThingHolder = false; } else { Pawn thingHolderAsPawn = thingHolder as Pawn; if (thingHolderAsPawn != null) { if (thingHolderAsPawn.Faction != Faction.OfPlayer) { isPlayerThingHolder = false; } } } return(isPlayerThingHolder); }); // Classify and tabulate by wealth category foreach (var thing in allPlayerThings) { if (thing.SpawnedOrAnyParentSpawned && !thing.PositionHeld.Fogged(map)) { var wealthCategory = GetWealthCategory(thing.def.FirstThingCategory); wealthByCategory[wealthCategory] += thing.MarketValue * thing.stackCount; } } return(wealthByCategory); }
public static bool get_AnyPawnBlockingMapRemoval(MapPawns __instance, ref bool __result) { Faction ofPlayer = Faction.OfPlayer; lock (pawnsSpawned(__instance)) { for (int index = 0; index < pawnsSpawned(__instance).Count; ++index) { if (!pawnsSpawned(__instance)[index].Downed && pawnsSpawned(__instance)[index].IsColonist || pawnsSpawned(__instance)[index].relations != null && pawnsSpawned(__instance)[index].relations.relativeInvolvedInRescueQuest != null) { __result = true; return(false); } if (pawnsSpawned(__instance)[index].Faction == ofPlayer || pawnsSpawned(__instance)[index].HostFaction == ofPlayer) { Job curJob = pawnsSpawned(__instance)[index].CurJob; if (curJob != null && curJob.exitMapOnArrival) { __result = true; return(false); } } if (CaravanExitMapUtility.FindCaravanToJoinFor(pawnsSpawned(__instance)[index]) != null && !pawnsSpawned(__instance)[index].Downed) { __result = true; return(false); } } } List <Thing> thingList = map(__instance).listerThings.ThingsInGroup(ThingRequestGroup.ThingHolder); for (int index1 = 0; index1 < thingList.Count; ++index1) { if (thingList[index1] is IActiveDropPod || thingList[index1] is PawnFlyer || thingList[index1].TryGetComp <CompTransporter>() != null) { IThingHolder holder = (IThingHolder)thingList[index1].TryGetComp <CompTransporter>() ?? (IThingHolder)thingList[index1]; List <Thing> tmpThings = new List <Thing>(); ThingOwnerUtility.GetAllThingsRecursively(holder, tmpThings, true, (Predicate <IThingHolder>)null); for (int index2 = 0; index2 < tmpThings.Count; ++index2) { if (tmpThings[index2] is Pawn tmpThing && !tmpThing.Dead && (!tmpThing.Downed && tmpThing.IsColonist)) { __result = true; return(false); } } } } __result = false; return(false); }
private static void DestroyThingsInWorldById(IEnumerable <int> idsToDestroy) { var idSet = new HashSet <int>(idsToDestroy); var things = new List <Thing>(); ThingOwnerUtility.GetAllThingsRecursively(Find.World, things, false); for (int i = 0; i < things.Count; i++) { var t = things[i]; if (idSet.Contains(t.thingIDNumber) && !t.Destroyed) { t.Destroy(); } } }
private static List <Thing> GetAllHaulableThingsOnMap(Map map) { var things = new List <Thing>(); var matchingThings = new List <Thing>(); ThingOwnerUtility.GetAllThingsRecursively(map, things, false); for (int i = 0; i < things.Count; i++) { var thing = things[i]; if (thing?.def != null && thing.def.EverHaulable) { matchingThings.Add(thing); } } return(matchingThings); }
public static bool GetAllThingsRecursively_Pawn(Map map, ThingRequest request, List <Pawn> outThings, bool allowUnreal = true, Predicate <IThingHolder> passCheck = null, bool alsoGetSpawnedThings = true) { lock (outThings) { outThings.Clear(); } if (alsoGetSpawnedThings) { List <Thing> list = map.listerThings.ThingsMatching(request); for (int i = 0; i < list.Count; i++) { Pawn t = list[i] as Pawn; if (t != null) { lock (outThings) { outThings.Add(t); } } } } List <IThingHolder> tmpMapChildHolders = new List <IThingHolder>(); //ThingOwnerUtility.tmpMapChildHolders.Clear(); map.GetChildHolders(tmpMapChildHolders); for (int j = 0; j < tmpMapChildHolders.Count; j++) { //ThingOwnerUtility.tmpThings.Clear(); List <Thing> tmpThings = new List <Thing>(); ThingOwnerUtility.GetAllThingsRecursively(tmpMapChildHolders[j], tmpThings, allowUnreal, passCheck); for (int k = 0; k < tmpThings.Count; k++) { Pawn t2 = tmpThings[k] as Pawn; if (t2 != null && request.Accepts(t2)) { lock (outThings) { outThings.Add(t2); } } } } return(false); //tmpThings.Clear(); //tmpMapChildHolders.Clear(); }
public override void PreOpen() { base.PreOpen(); //switch to the map view if the world view is active Find.World.renderer.wantedMode = RimWorld.Planet.WorldRenderMode.None; clearState(); FogGrid fogGrid = Find.CurrentMap.fogGrid; List <Thing> allThings = new List <Thing>(); //all items, buildings, animals and structures on the map but not the undiscovered terrain. allThings.AddRange(Find.CurrentMap.listerThings.AllThings.Where(t => /*!t.def.mineable || */ !fogGrid.IsFogged(t.Position))); //all the stuff that the colonists on the map have(not the stuff from prisoners, allies or enemies). foreach (Pawn p in Find.CurrentMap.mapPawns.FreeColonistsSpawned) { if (!p.Dead) { allThings.AddRange(ThingOwnerUtility.GetAllThingsRecursively(p, false)); } } //corpses for dead people foreach (Pawn p in Find.CurrentMap.mapPawns.AllPawnsSpawned) { if (p.Dead) { allThings.Add(p.Corpse); } } //grouping the things based on their archetype(e.g. all cowboy hats regardless of the material used) thingGroups = (from Thing t in allThings group t by t.def into newGroup orderby newGroup.Key.label select newGroup.ToList()).ToList(); //calculating the widest label and sizing the window to fit that label plus a scrollbar. float width = 0; foreach (List <Thing> g in thingGroups) { float x = Text.CalcSize(g.Count() + " " + g[0].def.label).x; if (x > width) { width = x; } } windowRect.width = width + 32; windowRect.height = 270; windowRect.y = (float)(UI.screenHeight - 35) - windowRect.height; }
public static bool get_FreeColonistsSpawnedOrInPlayerEjectablePodsCount(MapPawns __instance, ref int __result) { int num = 0; for (int i = 0; i < pawnsSpawnedFieldRef(__instance).Count; i++) { if (pawnsSpawnedFieldRef(__instance)[i].IsFreeColonist) { num++; } } List <Thing> list = mapFieldRef(__instance).listerThings.ThingsInGroup(ThingRequestGroup.ThingHolder); for (int j = 0; j < list.Count; j++) { Building_CryptosleepCasket building_CryptosleepCasket = list[j] as Building_CryptosleepCasket; if ((building_CryptosleepCasket == null || !building_CryptosleepCasket.def.building.isPlayerEjectable) && !(list[j] is IActiveDropPod) && !(list[j] is PawnFlyer) && list[j].TryGetComp <CompTransporter>() == null) { continue; } IThingHolder thingHolder = list[j].TryGetComp <CompTransporter>(); IThingHolder holder = thingHolder ?? ((IThingHolder)list[j]); if (tmpThings == null) { tmpThings = new List <Thing>(); } else { tmpThings.Clear(); } ThingOwnerUtility.GetAllThingsRecursively(holder, tmpThings); for (int k = 0; k < tmpThings.Count; k++) { if (tmpThings[k] is Pawn pawn && !pawn.Dead && pawn.IsFreeColonist) { num++; } } } //tmpThings.Clear(); __result = num; return(false); }
private void TakeFromCaravan(Caravan caravan, List <ThingCount> demands, Faction enemyFaction) { List <Thing> list = new List <Thing>(); for (int i = 0; i < demands.Count; i++) { ThingCount thingCount = demands[i]; if (thingCount.Thing is Pawn) { Pawn pawn = (Pawn)thingCount.Thing; caravan.RemovePawn(pawn); foreach (Thing item in ThingOwnerUtility.GetAllThingsRecursively(pawn, allowUnreal: false)) { list.Add(item); item.holdingOwner.Take(item); } if (pawn.RaceProps.Humanlike) { enemyFaction.kidnapped.Kidnap(pawn, null); } else if (!Find.WorldPawns.Contains(pawn)) { Find.WorldPawns.PassToWorld(pawn); } } else { thingCount.Thing.SplitOff(thingCount.Count).Destroy(); } } for (int j = 0; j < list.Count; j++) { if (!list[j].Destroyed) { CaravanInventoryUtility.GiveThing(caravan, list[j]); } } }
public static bool get_AllPawnsUnspawned(MapPawns __instance, ref List <Pawn> __result) { if (allPawnsUnspawnedResult == null) { allPawnsUnspawnedResult = new List <Pawn>(); } else { allPawnsUnspawnedResult.Clear(); } ThingOwnerUtility.GetAllThingsRecursively(mapFieldRef(__instance), ThingRequest.ForGroup(ThingRequestGroup.Pawn), allPawnsUnspawnedResult, allowUnreal: true, null, alsoGetSpawnedThings: false); for (int num = allPawnsUnspawnedResult.Count - 1; num >= 0; num--) { if (allPawnsUnspawnedResult[num].Dead) { allPawnsUnspawnedResult.RemoveAt(num); } } __result = allPawnsUnspawnedResult; return(false); }
public static IEnumerable <Thing> CalculateWealthItems() { tmpThings.Clear(); ThingOwnerUtility.GetAllThingsRecursively <Thing>(Find.CurrentMap, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), tmpThings, false, delegate(IThingHolder x) { if (x is PassingShip || x is MapComponent) { return(false); } Pawn pawn = x as Pawn; return(pawn == null || pawn.Faction == Faction.OfPlayer); }, true); float num = 0f; for (int i = 0; i < tmpThings.Count; i++) { if (tmpThings[i].SpawnedOrAnyParentSpawned && !tmpThings[i].PositionHeld.Fogged(Find.CurrentMap)) { yield return(tmpThings[i]); } } tmpThings.Clear(); }
public static bool get_AllPawnsUnspawned(MapPawns __instance, ref List <Pawn> __result) { List <Pawn> outThings = new List <Pawn>(); List <IThingHolder> tmpMapChildHolders = new List <IThingHolder>(); map(__instance).GetChildHolders(tmpMapChildHolders); List <Thing> tmpThings = new List <Thing>(); for (int j = 0; j < tmpMapChildHolders.Count; j++) { tmpThings.Clear(); ThingOwnerUtility.GetAllThingsRecursively(tmpMapChildHolders[j], tmpThings, true, null); for (int k = 0; k < tmpThings.Count; k++) { Pawn t2 = tmpThings[k] as Pawn; if (t2 != null && ThingRequest.ForGroup(ThingRequestGroup.Pawn).Accepts(t2) && !t2.Dead) { outThings.Add(t2); } } } __result = outThings; return(false); }
private static void CacheAccessibleThings(int nearTile) { if (nearTile == cachedAccessibleThingsForTile && RealTime.frameCount == cachedAccessibleThingsForFrame) { return; } cachedAccessibleThings.Clear(); cachedPossiblyAccessibleThings.Clear(); cachedMakeableItemDefs.Clear(); WorldGrid worldGrid = Find.WorldGrid; List <Map> maps = Find.Maps; for (int i = 0; i < maps.Count; i++) { if (!(worldGrid.ApproxDistanceInTiles(nearTile, maps[i].Tile) > 5f)) { ThingOwnerUtility.GetAllThingsRecursively(maps[i], tmpThings, allowUnreal: false); cachedAccessibleThings.AddRange(tmpThings); } } List <Caravan> caravans = Find.WorldObjects.Caravans; for (int j = 0; j < caravans.Count; j++) { if (caravans[j].IsPlayerControlled && !(worldGrid.ApproxDistanceInTiles(nearTile, caravans[j].Tile) > 5f)) { ThingOwnerUtility.GetAllThingsRecursively(caravans[j], tmpThings, allowUnreal: false); cachedAccessibleThings.AddRange(tmpThings); } } for (int k = 0; k < cachedAccessibleThings.Count; k++) { Thing thing = cachedAccessibleThings[k]; cachedPossiblyAccessibleThings.Add(new ThingDefCount(thing.def, thing.stackCount)); if (GenLeaving.CanBuildingLeaveResources(thing, DestroyMode.Deconstruct)) { List <ThingDefCountClass> list = thing.CostListAdjusted(); for (int l = 0; l < list.Count; l++) { int num = Mathf.RoundToInt((float)list[l].count * thing.def.resourcesFractionWhenDeconstructed); if (num > 0) { cachedPossiblyAccessibleThings.Add(new ThingDefCount(list[l].thingDef, num)); cachedMakeableItemDefs.Add(list[l].thingDef); } } } Plant plant = thing as Plant; if (plant != null && (plant.HarvestableNow || plant.HarvestableSoon)) { int num2 = Mathf.RoundToInt(plant.def.plant.harvestYield * Find.Storyteller.difficultyValues.cropYieldFactor); if (num2 > 0) { cachedPossiblyAccessibleThings.Add(new ThingDefCount(plant.def.plant.harvestedThingDef, num2)); cachedMakeableItemDefs.Add(plant.def.plant.harvestedThingDef); } } if (!thing.def.butcherProducts.NullOrEmpty()) { for (int m = 0; m < thing.def.butcherProducts.Count; m++) { cachedPossiblyAccessibleThings.Add(thing.def.butcherProducts[m]); cachedMakeableItemDefs.Add(thing.def.butcherProducts[m].thingDef); } } Pawn pawn = thing as Pawn; if (pawn != null) { if (pawn.RaceProps.meatDef != null) { int num3 = Mathf.RoundToInt(pawn.GetStatValue(StatDefOf.MeatAmount)); if (num3 > 0) { cachedPossiblyAccessibleThings.Add(new ThingDefCount(pawn.RaceProps.meatDef, num3)); cachedMakeableItemDefs.Add(pawn.RaceProps.meatDef); } } if (pawn.RaceProps.leatherDef != null) { int num4 = GenMath.RoundRandom(pawn.GetStatValue(StatDefOf.LeatherAmount)); if (num4 > 0) { cachedPossiblyAccessibleThings.Add(new ThingDefCount(pawn.RaceProps.leatherDef, num4)); cachedMakeableItemDefs.Add(pawn.RaceProps.leatherDef); } } if (!pawn.RaceProps.Humanlike) { PawnKindLifeStage curKindLifeStage = pawn.ageTracker.CurKindLifeStage; if (curKindLifeStage.butcherBodyPart != null) { cachedPossiblyAccessibleThings.Add(new ThingDefCount(curKindLifeStage.butcherBodyPart.thing, 1)); cachedMakeableItemDefs.Add(curKindLifeStage.butcherBodyPart.thing); } } } if (thing.def.smeltable) { List <ThingDefCountClass> list2 = thing.CostListAdjusted(); for (int n = 0; n < list2.Count; n++) { if (!list2[n].thingDef.intricate) { int num5 = Mathf.RoundToInt((float)list2[n].count * 0.25f); if (num5 > 0) { cachedPossiblyAccessibleThings.Add(new ThingDefCount(list2[n].thingDef, num5)); cachedMakeableItemDefs.Add(list2[n].thingDef); } } } } if (thing.def.smeltable && !thing.def.smeltProducts.NullOrEmpty()) { for (int num6 = 0; num6 < thing.def.smeltProducts.Count; num6++) { cachedPossiblyAccessibleThings.Add(thing.def.smeltProducts[num6]); cachedMakeableItemDefs.Add(thing.def.smeltProducts[num6].thingDef); } } } int num7 = 0; for (int num8 = 0; num8 < cachedAccessibleThings.Count; num8++) { Pawn pawn2 = cachedAccessibleThings[num8] as Pawn; if (pawn2 != null && pawn2.IsFreeColonist && !pawn2.Dead && !pawn2.Downed && pawn2.workSettings.WorkIsActive(WorkTypeDefOf.Crafting)) { num7++; } } if (num7 > 0) { tmpWorkTables.Clear(); for (int num9 = 0; num9 < cachedAccessibleThings.Count; num9++) { Building_WorkTable building_WorkTable = cachedAccessibleThings[num9] as Building_WorkTable; if (building_WorkTable == null || !building_WorkTable.Spawned || !tmpWorkTables.Add(building_WorkTable.def)) { continue; } List <RecipeDef> allRecipes = building_WorkTable.def.AllRecipes; for (int num10 = 0; num10 < allRecipes.Count; num10++) { if (!allRecipes[num10].AvailableNow || !allRecipes[num10].AvailableOnNow(building_WorkTable) || !allRecipes[num10].products.Any() || allRecipes[num10].PotentiallyMissingIngredients(null, building_WorkTable.Map).Any()) { continue; } ThingDef stuffDef = (allRecipes[num10].products[0].thingDef.MadeFromStuff ? GenStuff.DefaultStuffFor(allRecipes[num10].products[0].thingDef) : null); float num11 = allRecipes[num10].WorkAmountTotal(stuffDef); if (num11 <= 0f) { continue; } int num12 = Mathf.FloorToInt((float)(num7 * 60000 * 5) * 0.09f / num11); if (num12 > 0) { for (int num13 = 0; num13 < allRecipes[num10].products.Count; num13++) { cachedPossiblyAccessibleThings.Add(new ThingDefCount(allRecipes[num10].products[num13].thingDef, allRecipes[num10].products[num13].count * num12)); cachedMakeableItemDefs.Add(allRecipes[num10].products[num13].thingDef); } } } } } cachedAccessibleThingsForTile = nearTile; cachedAccessibleThingsForFrame = RealTime.frameCount; }
private static void CacheAccessibleThings(int nearTile) { if (nearTile != PlayerItemAccessibilityUtility.cachedAccessibleThingsForTile || RealTime.frameCount != PlayerItemAccessibilityUtility.cachedAccessibleThingsForFrame) { PlayerItemAccessibilityUtility.cachedAccessibleThings.Clear(); PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Clear(); WorldGrid worldGrid = Find.WorldGrid; List <Map> maps = Find.Maps; for (int i = 0; i < maps.Count; i++) { float num = worldGrid.ApproxDistanceInTiles(nearTile, maps[i].Tile); if (num <= 5f) { ThingOwnerUtility.GetAllThingsRecursively(maps[i], PlayerItemAccessibilityUtility.tmpThings, false, null); PlayerItemAccessibilityUtility.cachedAccessibleThings.AddRange(PlayerItemAccessibilityUtility.tmpThings); } } List <Caravan> caravans = Find.WorldObjects.Caravans; for (int j = 0; j < caravans.Count; j++) { if (caravans[j].IsPlayerControlled) { float num2 = worldGrid.ApproxDistanceInTiles(nearTile, caravans[j].Tile); if (num2 <= 5f) { ThingOwnerUtility.GetAllThingsRecursively(caravans[j], PlayerItemAccessibilityUtility.tmpThings, false, null); PlayerItemAccessibilityUtility.cachedAccessibleThings.AddRange(PlayerItemAccessibilityUtility.tmpThings); } } } for (int k = 0; k < PlayerItemAccessibilityUtility.cachedAccessibleThings.Count; k++) { Thing thing = PlayerItemAccessibilityUtility.cachedAccessibleThings[k]; PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(thing.def, thing.stackCount)); if (GenLeaving.CanBuildingLeaveResources(thing, DestroyMode.Deconstruct)) { List <ThingDefCountClass> list = thing.CostListAdjusted(); for (int l = 0; l < list.Count; l++) { int num3 = Mathf.RoundToInt((float)list[l].count * thing.def.resourcesFractionWhenDeconstructed); if (num3 > 0) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(list[l].thingDef, num3)); } } } Plant plant = thing as Plant; if (plant != null) { if (plant.HarvestableNow || plant.HarvestableSoon) { int num4 = Mathf.RoundToInt(plant.def.plant.harvestYield * Find.Storyteller.difficulty.cropYieldFactor); if (num4 > 0) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(plant.def.plant.harvestedThingDef, num4)); } } } if (!thing.def.butcherProducts.NullOrEmpty <ThingDefCountClass>()) { for (int m = 0; m < thing.def.butcherProducts.Count; m++) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(thing.def.butcherProducts[m]); } } Pawn pawn = thing as Pawn; if (pawn != null) { if (pawn.RaceProps.meatDef != null) { int num5 = Mathf.RoundToInt(pawn.GetStatValue(StatDefOf.MeatAmount, true)); if (num5 > 0) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(pawn.RaceProps.meatDef, num5)); } } if (pawn.RaceProps.leatherDef != null) { int num6 = GenMath.RoundRandom(pawn.GetStatValue(StatDefOf.LeatherAmount, true)); if (num6 > 0) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(pawn.RaceProps.leatherDef, num6)); } } if (!pawn.RaceProps.Humanlike) { PawnKindLifeStage curKindLifeStage = pawn.ageTracker.CurKindLifeStage; if (curKindLifeStage.butcherBodyPart != null) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(curKindLifeStage.butcherBodyPart.thing, 1)); } } } if (thing.def.smeltable) { List <ThingDefCountClass> list2 = thing.CostListAdjusted(); for (int n = 0; n < list2.Count; n++) { if (!list2[n].thingDef.intricate) { int num7 = Mathf.RoundToInt((float)list2[n].count * 0.25f); if (num7 > 0) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(list2[n].thingDef, num7)); } } } } if (thing.def.smeltable && !thing.def.smeltProducts.NullOrEmpty <ThingDefCountClass>()) { for (int num8 = 0; num8 < thing.def.smeltProducts.Count; num8++) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(thing.def.smeltProducts[num8]); } } } int num9 = 0; for (int num10 = 0; num10 < PlayerItemAccessibilityUtility.cachedAccessibleThings.Count; num10++) { Pawn pawn2 = PlayerItemAccessibilityUtility.cachedAccessibleThings[num10] as Pawn; if (pawn2 != null && pawn2.IsFreeColonist && !pawn2.Dead && !pawn2.Downed && pawn2.workSettings.WorkIsActive(WorkTypeDefOf.Crafting)) { num9++; } } if (num9 > 0) { PlayerItemAccessibilityUtility.tmpWorkTables.Clear(); for (int num11 = 0; num11 < PlayerItemAccessibilityUtility.cachedAccessibleThings.Count; num11++) { Building_WorkTable building_WorkTable = PlayerItemAccessibilityUtility.cachedAccessibleThings[num11] as Building_WorkTable; if (building_WorkTable != null && building_WorkTable.Spawned && PlayerItemAccessibilityUtility.tmpWorkTables.Add(building_WorkTable.def)) { List <RecipeDef> allRecipes = building_WorkTable.def.AllRecipes; for (int num12 = 0; num12 < allRecipes.Count; num12++) { if (allRecipes[num12].AvailableNow) { if (allRecipes[num12].products.Any <ThingDefCountClass>()) { if (!allRecipes[num12].PotentiallyMissingIngredients(null, building_WorkTable.Map).Any <ThingDef>()) { ThingDef stuffDef = (!allRecipes[num12].products[0].thingDef.MadeFromStuff) ? null : GenStuff.DefaultStuffFor(allRecipes[num12].products[0].thingDef); float num13 = allRecipes[num12].WorkAmountTotal(stuffDef); if (num13 > 0f) { int num14 = Mathf.FloorToInt((float)(num9 * 60000 * 5) * 0.09f / num13); if (num14 > 0) { for (int num15 = 0; num15 < allRecipes[num12].products.Count; num15++) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(allRecipes[num12].products[num15].thingDef, allRecipes[num12].products[num15].count * num14)); } } } } } } } } } } PlayerItemAccessibilityUtility.cachedAccessibleThingsForTile = nearTile; PlayerItemAccessibilityUtility.cachedAccessibleThingsForFrame = RealTime.frameCount; } }
public static bool get_AnyPawnBlockingMapRemoval(MapPawns __instance, ref bool __result) { Faction ofPlayer = Faction.OfPlayer; List <Pawn> pawnsSpawned = pawnsSpawnedFieldRef(__instance); for (int i = 0; i < pawnsSpawned.Count; i++) { if (!pawnsSpawned[i].Downed && pawnsSpawned[i].IsColonist) { __result = true; return(false); } if (pawnsSpawned[i].relations != null && pawnsSpawned[i].relations.relativeInvolvedInRescueQuest != null) { __result = true; return(false); } if (pawnsSpawned[i].Faction == ofPlayer || pawnsSpawned[i].HostFaction == ofPlayer) { Job curJob = pawnsSpawned[i].CurJob; if (curJob != null && curJob.exitMapOnArrival) { __result = true; return(false); } } if (CaravanExitMapUtility.FindCaravanToJoinFor(pawnsSpawned[i]) != null && !pawnsSpawned[i].Downed) { __result = true; return(false); } } List <Thing> list = mapFieldRef(__instance).listerThings.ThingsInGroup(ThingRequestGroup.ThingHolder); for (int j = 0; j < list.Count; j++) { if (!(list[j] is IActiveDropPod) && !(list[j] is PawnFlyer) && list[j].TryGetComp <CompTransporter>() == null) { continue; } IThingHolder thingHolder = list[j].TryGetComp <CompTransporter>(); IThingHolder holder = thingHolder ?? ((IThingHolder)list[j]); if (tmpThings == null) { tmpThings = new List <Thing>(); } else { tmpThings.Clear(); } ThingOwnerUtility.GetAllThingsRecursively(holder, tmpThings); for (int k = 0; k < tmpThings.Count; k++) { Pawn pawn = tmpThings[k] as Pawn; if (pawn != null && !pawn.Dead && !pawn.Downed && pawn.IsColonist) { tmpThings.Clear(); __result = true; return(false); } } } //tmpThings.Clear(); __result = false; return(false); }
private static IEnumerable <Thing> < TryGenerateItemsDemand > m__3(Pawn x) { return(ThingOwnerUtility.GetAllThingsRecursively(x, false)); }
//draws the window's contents public override void DoWindowContents(Rect inRect) { //Title Rect titleRect = new Rect(inRect); titleRect = titleRect.ContractedBy(17f); titleRect.height = 34f; titleRect.x += 34f; Text.Font = GameFont.Medium; Widgets.Label(titleRect, this.thing.LabelCapNoCount); Rect titleIconRect = new Rect(inRect.x + 9f, titleRect.y, 34f, 34f); if (this.thing != null) { Widgets.ThingIcon(titleIconRect, this.thing, 1f); } //Inner Rectangle Rect innerRect = new Rect(inRect); innerRect.yMin = titleRect.yMax; innerRect.yMax -= 34f; Widgets.DrawLineVertical(innerRect.x + innerRect.width / 2, innerRect.y, innerRect.height); Text.Font = GameFont.Small; //Harddrive Info Rect harddriveInfo = new Rect(innerRect.x, innerRect.y, innerRect.width / 2 - 17f, innerRect.height); Rect cardRect = new Rect(harddriveInfo); cardRect.y += 34f; cardRect.yMax = innerRect.yMax; if (selectedHarddrive != null) { Rect harddriveInfoTabs = harddriveInfo; List <TabRecord> tabs = new List <TabRecord>(); TabRecord stats = new TabRecord("TabStats".Translate(), delegate() { this.tab = Neurolink_Dialog_Mainframe.InfoCardTab.Stats; }, this.tab == Neurolink_Dialog_Mainframe.InfoCardTab.Stats); tabs.Add(stats); if (selectedHarddrive.pawn.RaceProps.Humanlike) { TabRecord character = new TabRecord("TabCharacter".Translate(), delegate() { this.tab = Neurolink_Dialog_Mainframe.InfoCardTab.Character; }, this.tab == Neurolink_Dialog_Mainframe.InfoCardTab.Character); tabs.Add(character); } TabRecord social = new TabRecord("TabSocial".Translate(), delegate() { this.tab = Neurolink_Dialog_Mainframe.InfoCardTab.Social; }, this.tab == Neurolink_Dialog_Mainframe.InfoCardTab.Social); tabs.Add(social); TabRecord needs = new TabRecord("TabNeeds".Translate(), delegate() { this.tab = Neurolink_Dialog_Mainframe.InfoCardTab.Needs; }, this.tab == Neurolink_Dialog_Mainframe.InfoCardTab.Needs); tabs.Add(needs); if (tabs.Count > 1) { harddriveInfoTabs.yMin += 45f; TabDrawer.DrawTabs(harddriveInfoTabs, tabs, cardRect.width); } this.FillInfoTabs(cardRect.ContractedBy(17f)); } //Harddrives Rect harddrivesList = new Rect(innerRect.width / 2 + 17f, innerRect.y, innerRect.width / 2 - 17f, innerRect.height); Widgets.DrawBoxSolid(harddrivesList, Color.black); if (!thing.GetDirectlyHeldThings().NullOrEmpty()) { Thing[] contents = ThingOwnerUtility.GetAllThingsRecursively(thing).ToArray(); Rect[] hdRect = new Rect[contents.Length]; Color buttonBgColor; string buttonText = null; Widgets.BeginScrollView(harddrivesList, ref this.scrollPosition, harddrivesList, true); //%TODO% for (int i = 0; i < contents.Length; i++) { Pawn pawn = ((Neurolink_Harddrive)contents[i]).pawn; hdRect[i] = new Rect(harddrivesList.x, harddrivesList.y + 100f * i, harddrivesList.width, 100f); buttonBgColor = Mouse.IsOver(hdRect[i]) ? Color.green : Color.gray; buttonText = pawn.GetHashCode() + " | " + pawn.Name.ToStringFull + " | " + pawn.story.TitleCap + " | " + pawn.ageTracker.AgeChronologicalYears; if (Widgets.CustomButtonText(ref hdRect[i], buttonText, buttonBgColor, Color.white, Color.black)) { this.selectedHarddrive = (Neurolink_Harddrive)contents.GetValue(i); } } Widgets.EndScrollView(); } //Simulation %TODO% }
private static IEnumerable <Thing> < GenerateDemands > m__0(Pawn pawn) { return(ThingOwnerUtility.GetAllThingsRecursively(pawn, false)); }