public static float CalculateLimbEfficiency(HediffSet diffSet, BodyPartTagDef limbCoreTag, BodyPartTagDef limbSegmentTag, BodyPartTagDef limbDigitTag, float appendageWeight, out float functionalPercentage, List <CapacityImpactor> impactors) { BodyDef body = diffSet.pawn.RaceProps.body; float num = 0f; int num2 = 0; int num3 = 0; foreach (BodyPartRecord item in body.GetPartsWithTag(limbCoreTag)) { float num4 = CalculateImmediatePartEfficiencyAndRecord(diffSet, item, impactors); foreach (BodyPartRecord connectedPart in item.GetConnectedParts(limbSegmentTag)) { num4 *= CalculateImmediatePartEfficiencyAndRecord(diffSet, connectedPart, impactors); } if (item.HasChildParts(limbDigitTag)) { num4 = Mathf.Lerp(num4, num4 * item.GetChildParts(limbDigitTag).Average((BodyPartRecord digitPart) => CalculateImmediatePartEfficiencyAndRecord(diffSet, digitPart, impactors)), appendageWeight); } num += num4; num2++; if (num4 > 0f) { num3++; } } if (num2 == 0) { functionalPercentage = 0f; return(0f); } functionalPercentage = (float)num3 / (float)num2; return(num / (float)num2); }
public static float CalculateLimbEfficiency(HediffSet diffSet, BodyPartTagDef limbCoreTag, BodyPartTagDef limbSegmentTag, BodyPartTagDef limbDigitTag, float appendageWeight, out float functionalPercentage, List <CapacityImpactor> impactors) { BodyDef body = diffSet.pawn.RaceProps.body; float totalEfficiency = 0f; int partCount = 0; int functionalPartCount = 0; foreach (BodyPartRecord item in body.GetPartsWithTag(limbCoreTag)) { float partEfficiency = CalculateImmediatePartEfficiencyAndRecord(diffSet, item, impactors); foreach (BodyPartRecord connectedPart in item.GetConnectedParts(limbSegmentTag)) { partEfficiency *= CalculateImmediatePartEfficiencyAndRecord(diffSet, connectedPart, impactors); } if (item.HasChildParts(limbDigitTag)) { partEfficiency = Mathf.Lerp(partEfficiency, partEfficiency * item.GetChildParts(limbDigitTag).Average((BodyPartRecord digitPart) => CalculateImmediatePartEfficiencyAndRecord(diffSet, digitPart, impactors)), appendageWeight); } totalEfficiency += partEfficiency; partCount++; if (partEfficiency > 0f) { functionalPartCount++; } } if (partCount == 0) { functionalPercentage = 0f; return(0f); } functionalPercentage = (float)functionalPartCount / (float)partCount; return(totalEfficiency / (float)partCount); }
public static float CalculateTagEfficiency(HediffSet diffSet, string tag, float maximum = 3.40282347E+38f, List <CapacityImpactor> impactors = null) { BodyDef body = diffSet.pawn.RaceProps.body; float num = 0f; int num2 = 0; List <CapacityImpactor> list = null; foreach (BodyPartRecord item in body.GetPartsWithTag(tag)) { BodyPartRecord part = item; List <CapacityImpactor> impactors2 = list; float num3 = PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, impactors2); if (impactors != null && num3 != 1.0 && list == null) { list = new List <CapacityImpactor>(); part = item; impactors2 = list; PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, impactors2); } num += num3; num2++; } if (num2 == 0) { return(1f); } float num4 = num / (float)num2; float num5 = Mathf.Min(num4, maximum); if (impactors != null && list != null && (maximum != 1.0 || num4 <= 1.0 || num5 == 1.0)) { impactors.AddRange(list); } return(num5); }
public static float CalculateTagEfficiency(HediffSet diffSet, BodyPartTagDef tag, float maximum = 3.40282347E+38f, FloatRange lerp = default(FloatRange), List <PawnCapacityUtility.CapacityImpactor> impactors = null, float bestPartEfficiencySpecialWeight = -1f) { BodyDef body = diffSet.pawn.RaceProps.body; float num = 0f; int num2 = 0; float num3 = 0f; List <PawnCapacityUtility.CapacityImpactor> list = null; foreach (BodyPartRecord current in body.GetPartsWithTag(tag)) { BodyPartRecord part = current; List <PawnCapacityUtility.CapacityImpactor> impactors2 = list; float num4 = PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, impactors2); if (impactors != null && num4 != 1f && list == null) { list = new List <PawnCapacityUtility.CapacityImpactor>(); part = current; impactors2 = list; PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, impactors2); } num += num4; num3 = Mathf.Max(num3, num4); num2++; } if (num2 == 0) { return(1f); } float num5; if (bestPartEfficiencySpecialWeight >= 0f && num2 >= 2) { num5 = num3 * bestPartEfficiencySpecialWeight + (num - num3) / (float)(num2 - 1) * (1f - bestPartEfficiencySpecialWeight); } else { num5 = num / (float)num2; } float num6 = num5; if (lerp != default(FloatRange)) { num6 = lerp.LerpThroughRange(num6); } num6 = Mathf.Min(num6, maximum); if (impactors != null && list != null && (maximum != 1f || num5 <= 1f || num6 == 1f)) { impactors.AddRange(list); } return(num6); }
public static float CalculateTagEfficiency(HediffSet diffSet, BodyPartTagDef tag, float maximum = 3.40282347E+38f, FloatRange lerp = default(FloatRange), List <PawnCapacityUtility.CapacityImpactor> impactors = null) { BodyDef body = diffSet.pawn.RaceProps.body; float num = 0f; int num2 = 0; List <PawnCapacityUtility.CapacityImpactor> list = null; foreach (BodyPartRecord bodyPartRecord in body.GetPartsWithTag(tag)) { BodyPartRecord part = bodyPartRecord; List <PawnCapacityUtility.CapacityImpactor> impactors2 = list; float num3 = PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, impactors2); if (impactors != null && num3 != 1f && list == null) { list = new List <PawnCapacityUtility.CapacityImpactor>(); part = bodyPartRecord; impactors2 = list; PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, impactors2); } num += num3; num2++; } float result; if (num2 == 0) { result = 1f; } else { float num4 = num / (float)num2; float num5 = num4; if (lerp != default(FloatRange)) { num5 = lerp.LerpThroughRange(num5); } num5 = Mathf.Min(num5, maximum); if (impactors != null && list != null && (maximum != 1f || num4 <= 1f || num5 == 1f)) { impactors.AddRange(list); } result = num5; } return(result); }
public static float CalculateTagEfficiency(HediffSet diffSet, BodyPartTagDef tag, float maximum = float.MaxValue, FloatRange lerp = default(FloatRange), List <CapacityImpactor> impactors = null, float bestPartEfficiencySpecialWeight = -1f) { BodyDef body = diffSet.pawn.RaceProps.body; float totalEfficiency = 0f; int partCount = 0; float bestPartEfficiency = 0f; List <CapacityImpactor> list = null; foreach (BodyPartRecord item in body.GetPartsWithTag(tag)) { BodyPartRecord part = item; List <CapacityImpactor> impactors2 = list; float partEfficiency = CalculatePartEfficiency(diffSet, part, ignoreAddedParts: false, impactors2); if (impactors != null && partEfficiency != 1f && list == null) { list = new List <CapacityImpactor>(); part = item; impactors2 = list; CalculatePartEfficiency(diffSet, part, ignoreAddedParts: false, impactors2); } totalEfficiency += partEfficiency; bestPartEfficiency = Mathf.Max(bestPartEfficiency, partEfficiency); partCount++; } if (partCount == 0) { return(1f); } float weightedEfficiency = (!(bestPartEfficiencySpecialWeight >= 0f) || partCount < 2) ? (totalEfficiency / (float)partCount) : (bestPartEfficiency * bestPartEfficiencySpecialWeight + (totalEfficiency - bestPartEfficiency) / (float)(partCount - 1) * (1f - bestPartEfficiencySpecialWeight)); float num6 = weightedEfficiency; if (lerp != default(FloatRange)) { num6 = lerp.LerpThroughRange(num6); } num6 = Mathf.Min(num6, maximum); if (impactors != null && list != null && (maximum != 1f || weightedEfficiency <= 1f || num6 == 1f)) { impactors.AddRange(list); } return(num6); }
public static float CalculateLimbEfficiency(HediffSet diffSet, BodyPartTagDef limbCoreTag, BodyPartTagDef limbSegmentTag, BodyPartTagDef limbDigitTag, float appendageWeight, out float functionalPercentage, List <PawnCapacityUtility.CapacityImpactor> impactors) { BodyDef body = diffSet.pawn.RaceProps.body; float num = 0f; int num2 = 0; int num3 = 0; foreach (BodyPartRecord bodyPartRecord in body.GetPartsWithTag(limbCoreTag)) { float num4 = PawnCapacityUtility.CalculateImmediatePartEfficiencyAndRecord(diffSet, bodyPartRecord, impactors); foreach (BodyPartRecord part in bodyPartRecord.GetConnectedParts(limbSegmentTag)) { num4 *= PawnCapacityUtility.CalculateImmediatePartEfficiencyAndRecord(diffSet, part, impactors); } if (bodyPartRecord.HasChildParts(limbDigitTag)) { num4 = Mathf.Lerp(num4, num4 * bodyPartRecord.GetChildParts(limbDigitTag).Average((BodyPartRecord digitPart) => PawnCapacityUtility.CalculateImmediatePartEfficiencyAndRecord(diffSet, digitPart, impactors)), appendageWeight); } num += num4; num2++; if (num4 > 0f) { num3++; } } float result; if (num2 == 0) { functionalPercentage = 0f; result = 0f; } else { functionalPercentage = (float)num3 / (float)num2; result = num / (float)num2; } return(result); }
public static float CalculateTagEfficiency(HediffSet diffSet, BodyPartTagDef tag, float maximum = float.MaxValue, FloatRange lerp = default(FloatRange), List <CapacityImpactor> impactors = null, float bestPartEfficiencySpecialWeight = -1f) { BodyDef body = diffSet.pawn.RaceProps.body; float num = 0f; int num2 = 0; float num3 = 0f; List <CapacityImpactor> list = null; foreach (BodyPartRecord item in body.GetPartsWithTag(tag)) { float num4 = CalculatePartEfficiency(diffSet, item, ignoreAddedParts: false, list); if (impactors != null && num4 != 1f && list == null) { list = new List <CapacityImpactor>(); CalculatePartEfficiency(diffSet, item, ignoreAddedParts: false, list); } num += num4; num3 = Mathf.Max(num3, num4); num2++; } if (num2 == 0) { return(1f); } float num5 = ((!(bestPartEfficiencySpecialWeight >= 0f) || num2 < 2) ? (num / (float)num2) : (num3 * bestPartEfficiencySpecialWeight + (num - num3) / (float)(num2 - 1) * (1f - bestPartEfficiencySpecialWeight))); float num6 = num5; if (lerp != default(FloatRange)) { num6 = lerp.LerpThroughRange(num6); } num6 = Mathf.Min(num6, maximum); if (impactors != null && list != null && (maximum != 1f || num5 <= 1f || num6 == 1f)) { impactors.AddRange(list); } return(num6); }