Example #1
0
        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);
        }
Example #2
0
        public IEnumerable <BodyPartRecord> GetConnectedParts(BodyPartTagDef tag)
        {
            BodyPartRecord ancestor = this;

            while (ancestor.parent != null && ancestor.parent.def.tags.Contains(tag))
            {
                ancestor = ancestor.parent;
            }
            using (IEnumerator <BodyPartRecord> enumerator = ancestor.GetChildParts(tag).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    BodyPartRecord child = enumerator.Current;
                    yield return(child);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            yield break;
IL_0116:
            /*Error near IL_0117: Unexpected return in MoveNext()*/;
        }
        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);
        }
Example #4
0
        public IEnumerable <BodyPartRecord> GetPartsWithTag(BodyPartTagDef tag)
        {
            int            i = 0;
            BodyPartRecord part;

            while (true)
            {
                if (i >= AllParts.Count)
                {
                    yield break;
                }
                part = AllParts[i];
                if (part.def.tags.Contains(tag))
                {
                    break;
                }
                i++;
            }
            yield return(part);

            /*Error: Unable to find new state assignment for yield return*/;
        }
Example #5
0
        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);
        }
Example #6
0
        public IEnumerable <BodyPartRecord> GetNotMissingParts(BodyPartHeight height = BodyPartHeight.Undefined, BodyPartDepth depth = BodyPartDepth.Undefined, BodyPartTagDef tag = null, BodyPartRecord partParent = null)
        {
            List <BodyPartRecord> allPartsList = pawn.def.race.body.AllParts;
            int            i = 0;
            BodyPartRecord part;

            while (true)
            {
                if (i >= allPartsList.Count)
                {
                    yield break;
                }
                part = allPartsList[i];
                if (!PartIsMissing(part) && (height == BodyPartHeight.Undefined || part.height == height) && (depth == BodyPartDepth.Undefined || part.depth == depth) && (tag == null || part.def.tags.Contains(tag)) && (partParent == null || part.parent == partParent))
                {
                    break;
                }
                i++;
            }
            yield return(part);

            /*Error: Unable to find new state assignment for yield return*/;
        }
Example #7
0
        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);
        }
Example #8
0
        public IEnumerable <BodyPartRecord> GetNotMissingParts(BodyPartHeight height = BodyPartHeight.Undefined, BodyPartDepth depth = BodyPartDepth.Undefined, BodyPartTagDef tag = null, BodyPartRecord partParent = null)
        {
            List <BodyPartRecord> allPartsList = pawn.def.race.body.AllParts;

            for (int i = 0; i < allPartsList.Count; i++)
            {
                BodyPartRecord bodyPartRecord = allPartsList[i];
                if (!PartIsMissing(bodyPartRecord) && (height == BodyPartHeight.Undefined || bodyPartRecord.height == height) && (depth == BodyPartDepth.Undefined || bodyPartRecord.depth == depth) && (tag == null || bodyPartRecord.def.tags.Contains(tag)) && (partParent == null || bodyPartRecord.parent == partParent))
                {
                    yield return(bodyPartRecord);
                }
            }
        }
Example #9
0
 private static bool <ShouldRandomSurgeryInjuriesAvoidDestroying> m__3(BodyPartTagDef x)
 {
     return(x.vital);
 }
Example #10
0
 public bool HasChildParts(BodyPartTagDef tag)
 {
     return(GetChildParts(tag).Any());
 }
Example #11
0
 public bool HasChildParts(BodyPartTagDef tag)
 {
     return(this.GetChildParts(tag).Any <BodyPartRecord>());
 }
Example #12
0
        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);
        }