public bool SatisfiesNeededWarmth(NeededWarmth warmth, bool mustBeSafe = false, float mapTemperature = 21f) { if (warmth == NeededWarmth.Any) { return(true); } if (!mustBeSafe || GenTemperature.SafeTemperatureRange(raceDef, aps).Includes(mapTemperature)) { switch (warmth) { case NeededWarmth.Cool: { float num2 = aps.Sum((ThingStuffPair a) => a.InsulationHeat); return(num2 >= -2f); } case NeededWarmth.Warm: { float num = aps.Sum((ThingStuffPair a) => a.InsulationCold); return(num >= 52f); } default: throw new NotImplementedException(); } } return(false); }
public bool SatisfiesNeededWarmth(NeededWarmth warmth, bool mustBeSafe = false, float mapTemperature = 21f) { bool result; if (warmth == NeededWarmth.Any) { result = true; } else if (mustBeSafe && !GenTemperature.SafeTemperatureRange(this.raceDef, this.aps).Includes(mapTemperature)) { result = false; } else if (warmth == NeededWarmth.Cool) { float num = this.aps.Sum((ThingStuffPair a) => a.InsulationHeat); result = (num >= -2f); } else { if (warmth != NeededWarmth.Warm) { throw new NotImplementedException(); } float num2 = this.aps.Sum((ThingStuffPair a) => a.InsulationCold); result = (num2 >= 52f); } return(result); }
public bool SatisfiesNeededWarmth(NeededWarmth warmth, bool mustBeSafe = false, float mapTemperature = 21f) { if (warmth == NeededWarmth.Any) { return(true); } if (mustBeSafe && !GenTemperature.SafeTemperatureRange(raceDef, aps).Includes(mapTemperature)) { return(false); } return(warmth switch { NeededWarmth.Cool => aps.Sum((ThingStuffPair a) => a.InsulationHeat) >= -2f, NeededWarmth.Warm => aps.Sum((ThingStuffPair a) => a.InsulationCold) >= 52f, _ => throw new NotImplementedException(), });
public void AddFreeWarmthAsNeeded(NeededWarmth warmth, float mapTemperature) { if (warmth == NeededWarmth.Any || warmth == NeededWarmth.Cool) { return; } if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine(); debugSb.AppendLine("Trying to give free warm layer."); } for (int i = 0; i < 3; i++) { if (!SatisfiesNeededWarmth(warmth, mustBeSafe: true, mapTemperature)) { if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine("Checking to give free torso-cover at max price " + freeWarmParkaMaxPrice); } Predicate <ThingStuffPair> parkaPairValidator = delegate(ThingStuffPair pa) { if (pa.Price > freeWarmParkaMaxPrice) { return(false); } if (pa.InsulationCold <= 0f) { return(false); } if (!pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso)) { return(false); } if (!pa.thing.apparel.canBeGeneratedToSatisfyWarmth) { return(false); } return((!(GetReplacedInsulationCold(pa) >= pa.InsulationCold)) ? true : false); }; for (int j = 0; j < 2; j++) { ThingStuffPair candidate; if (j == 0) { if (!allApparelPairs.Where((ThingStuffPair pa) => parkaPairValidator(pa) && pa.InsulationCold < 40f).TryRandomElementByWeight((ThingStuffPair pa) => pa.Commonality / (pa.Price * pa.Price), out candidate)) { continue; } } else if (!allApparelPairs.Where((ThingStuffPair pa) => parkaPairValidator(pa)).TryMaxBy((ThingStuffPair x) => x.InsulationCold - GetReplacedInsulationCold(x), out candidate)) { continue; } if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine("Giving free torso-cover: " + candidate + " insulation=" + candidate.InsulationCold); foreach (ThingStuffPair item in aps.Where((ThingStuffPair a) => !ApparelUtility.CanWearTogether(a.thing, candidate.thing, body))) { debugSb.AppendLine(" -replaces " + item.ToString() + " InsulationCold=" + item.InsulationCold); } } aps.RemoveAll((ThingStuffPair pa) => !ApparelUtility.CanWearTogether(pa.thing, candidate.thing, body)); aps.Add(candidate); break; } } if (GenTemperature.SafeTemperatureRange(raceDef, aps).Includes(mapTemperature)) { break; } } if (!SatisfiesNeededWarmth(warmth, mustBeSafe: true, mapTemperature)) { if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine("Checking to give free hat at max price " + freeWarmHatMaxPrice); } Predicate <ThingStuffPair> hatPairValidator = delegate(ThingStuffPair pa) { if (pa.Price > freeWarmHatMaxPrice) { return(false); } if (pa.InsulationCold < 7f) { return(false); } if (!pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.FullHead) && !pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.UpperHead)) { return(false); } return((!(GetReplacedInsulationCold(pa) >= pa.InsulationCold)) ? true : false); }; if (allApparelPairs.Where((ThingStuffPair pa) => hatPairValidator(pa)).TryRandomElementByWeight((ThingStuffPair pa) => pa.Commonality / (pa.Price * pa.Price), out ThingStuffPair hatPair)) { if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine("Giving free hat: " + hatPair + " insulation=" + hatPair.InsulationCold); foreach (ThingStuffPair item2 in aps.Where((ThingStuffPair a) => !ApparelUtility.CanWearTogether(a.thing, hatPair.thing, body))) { debugSb.AppendLine(" -replaces " + item2.ToString() + " InsulationCold=" + item2.InsulationCold); } } aps.RemoveAll((ThingStuffPair pa) => !ApparelUtility.CanWearTogether(pa.thing, hatPair.thing, body)); aps.Add(hatPair); } } if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine("New TotalInsulationCold: " + TotalInsulationCold); } }
public void AddFreeWarmthAsNeeded(NeededWarmth warmth, float mapTemperature) { if (warmth == NeededWarmth.Any) { return; } if (warmth == NeededWarmth.Cool) { return; } if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine(); PawnApparelGenerator.debugSb.AppendLine("Trying to give free warm layer."); } for (int i = 0; i < 3; i++) { if (!this.SatisfiesNeededWarmth(warmth, true, mapTemperature)) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine("Checking to give free torso-cover at max price " + PawnApparelGenerator.freeWarmParkaMaxPrice); } Predicate <ThingStuffPair> parkaPairValidator = delegate(ThingStuffPair pa) { if (pa.Price > PawnApparelGenerator.freeWarmParkaMaxPrice) { return(false); } if (pa.InsulationCold <= 0f) { return(false); } if (!pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso)) { return(false); } float replacedInsulationCold = this.GetReplacedInsulationCold(pa); return(replacedInsulationCold < pa.InsulationCold); }; int j = 0; while (j < 2) { ThingStuffPair candidate; if (j == 0) { if ((from pa in PawnApparelGenerator.allApparelPairs where parkaPairValidator(pa) && pa.InsulationCold < 40f select pa).TryRandomElementByWeight((ThingStuffPair pa) => pa.Commonality / (pa.Price * pa.Price), out candidate)) { goto IL_12F; } } else if ((from pa in PawnApparelGenerator.allApparelPairs where parkaPairValidator(pa) select pa).TryMaxBy((ThingStuffPair x) => x.InsulationCold - this.GetReplacedInsulationCold(x), out candidate)) { goto IL_12F; } j++; continue; IL_12F: if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine(string.Concat(new object[] { "Giving free torso-cover: ", candidate, " insulation=", candidate.InsulationCold })); foreach (ThingStuffPair thingStuffPair in from a in this.aps where !ApparelUtility.CanWearTogether(a.thing, candidate.thing, this.body) select a) { PawnApparelGenerator.debugSb.AppendLine(string.Concat(new object[] { " -replaces ", thingStuffPair.ToString(), " InsulationCold=", thingStuffPair.InsulationCold })); } } this.aps.RemoveAll((ThingStuffPair pa) => !ApparelUtility.CanWearTogether(pa.thing, candidate.thing, this.body)); this.aps.Add(candidate); break; } } if (GenTemperature.SafeTemperatureRange(this.raceDef, this.aps).Includes(mapTemperature)) { break; } } if (!this.SatisfiesNeededWarmth(warmth, true, mapTemperature)) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine("Checking to give free hat at max price " + PawnApparelGenerator.freeWarmHatMaxPrice); } Predicate <ThingStuffPair> hatPairValidator = delegate(ThingStuffPair pa) { if (pa.Price > PawnApparelGenerator.freeWarmHatMaxPrice) { return(false); } if (pa.InsulationCold < 7f) { return(false); } if (!pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.FullHead) && !pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.UpperHead)) { return(false); } float replacedInsulationCold = this.GetReplacedInsulationCold(pa); return(replacedInsulationCold < pa.InsulationCold); }; ThingStuffPair hatPair; if ((from pa in PawnApparelGenerator.allApparelPairs where hatPairValidator(pa) select pa).TryRandomElementByWeight((ThingStuffPair pa) => pa.Commonality / (pa.Price * pa.Price), out hatPair)) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine(string.Concat(new object[] { "Giving free hat: ", hatPair, " insulation=", hatPair.InsulationCold })); foreach (ThingStuffPair thingStuffPair2 in from a in this.aps where !ApparelUtility.CanWearTogether(a.thing, hatPair.thing, this.body) select a) { PawnApparelGenerator.debugSb.AppendLine(string.Concat(new object[] { " -replaces ", thingStuffPair2.ToString(), " InsulationCold=", thingStuffPair2.InsulationCold })); } } this.aps.RemoveAll((ThingStuffPair pa) => !ApparelUtility.CanWearTogether(pa.thing, hatPair.thing, this.body)); this.aps.Add(hatPair); } } if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine("New TotalInsulationCold: " + this.TotalInsulationCold); } }