public static float CalculateCapacityLevel(HediffSet diffSet, PawnCapacityDef capacity, List <PawnCapacityUtility.CapacityImpactor> impactors = null)
        {
            if (capacity.zeroIfCannotBeAwake && !diffSet.pawn.health.capacities.CanBeAwake)
            {
                if (impactors != null)
                {
                    impactors.Add(new PawnCapacityUtility.CapacityImpactorCapacity
                    {
                        capacity = PawnCapacityDefOf.Consciousness
                    });
                }
                return(0f);
            }
            float num = capacity.Worker.CalculateCapacityLevel(diffSet, impactors);

            if (num > 0f)
            {
                float num2 = 99999f;
                float num3 = 1f;
                for (int i = 0; i < diffSet.hediffs.Count; i++)
                {
                    Hediff hediff = diffSet.hediffs[i];
                    List <PawnCapacityModifier> capMods = hediff.CapMods;
                    if (capMods != null)
                    {
                        for (int j = 0; j < capMods.Count; j++)
                        {
                            PawnCapacityModifier pawnCapacityModifier = capMods[j];
                            if (pawnCapacityModifier.capacity == capacity)
                            {
                                num  += pawnCapacityModifier.offset;
                                num3 *= pawnCapacityModifier.postFactor;
                                if (pawnCapacityModifier.setMax < num2)
                                {
                                    num2 = pawnCapacityModifier.setMax;
                                }
                                if (impactors != null)
                                {
                                    impactors.Add(new PawnCapacityUtility.CapacityImpactorHediff
                                    {
                                        hediff = hediff
                                    });
                                }
                            }
                        }
                    }
                }
                num *= num3;
                num  = Mathf.Min(num, num2);
            }
            num = Mathf.Max(num, capacity.minValue);
            return(GenMath.RoundedHundredth(num));
        }
Example #2
0
        protected float CalculateCapacityAndRecord(HediffSet diffSet, PawnCapacityDef capacity, List <PawnCapacityUtility.CapacityImpactor> impactors)
        {
            float level = diffSet.pawn.health.capacities.GetLevel(capacity);

            if (impactors != null && level != 1.0)
            {
                impactors.Add(new PawnCapacityUtility.CapacityImpactorCapacity
                {
                    capacity = capacity
                });
            }
            return(level);
        }
Example #3
0
        public PawnCapacityDef ShouldBeDeadFromRequiredCapacity()
        {
            List <PawnCapacityDef> allDefsListForReading = DefDatabase <PawnCapacityDef> .AllDefsListForReading;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                PawnCapacityDef pawnCapacityDef = allDefsListForReading[i];
                if (((!pawn.RaceProps.IsFlesh) ? pawnCapacityDef.lethalMechanoids : pawnCapacityDef.lethalFlesh) && !capacities.CapableOf(pawnCapacityDef))
                {
                    return(pawnCapacityDef);
                }
            }
            return(null);
        }
        public PawnCapacityDef ShouldBeDeadFromRequiredCapacity()
        {
            List <PawnCapacityDef> allDefsListForReading = DefDatabase <PawnCapacityDef> .AllDefsListForReading;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                PawnCapacityDef pawnCapacityDef = allDefsListForReading[i];
                if ((pawn.RaceProps.IsFlesh ? pawnCapacityDef.lethalFlesh : pawnCapacityDef.lethalMechanoids) && !capacities.CapableOf(pawnCapacityDef))
                {
                    if (DebugViewSettings.logCauseOfDeath)
                    {
                        Log.Message("CauseOfDeath: no longer capable of " + pawnCapacityDef.defName);
                    }
                    return(pawnCapacityDef);
                }
            }
            return(null);
        }
Example #5
0
        public float GetLevel(PawnCapacityDef capacity)
        {
            float result;

            if (this.pawn.health.Dead)
            {
                result = 0f;
            }
            else
            {
                if (this.cachedCapacityLevels == null)
                {
                    this.Notify_CapacityLevelsDirty();
                }
                PawnCapacitiesHandler.CacheElement cacheElement = this.cachedCapacityLevels[capacity];
                if (cacheElement.status == PawnCapacitiesHandler.CacheStatus.Caching)
                {
                    Log.Error(string.Format("Detected infinite stat recursion when evaluating {0}", capacity), false);
                    result = 0f;
                }
                else
                {
                    if (cacheElement.status == PawnCapacitiesHandler.CacheStatus.Uncached)
                    {
                        cacheElement.status = PawnCapacitiesHandler.CacheStatus.Caching;
                        try
                        {
                            cacheElement.value = PawnCapacityUtility.CalculateCapacityLevel(this.pawn.health.hediffSet, capacity, null);
                        }
                        finally
                        {
                            cacheElement.status = PawnCapacitiesHandler.CacheStatus.Cached;
                        }
                    }
                    result = cacheElement.value;
                }
            }
            return(result);
        }
Example #6
0
 public static bool BodyCanEverDoCapacity(BodyDef bodyDef, PawnCapacityDef capacity)
 {
     return(capacity.Worker.CanHaveCapacity(bodyDef));
 }
 public bool CapableOf(PawnCapacityDef capacity)
 {
     return(this.GetLevel(capacity) > capacity.minForCapable);
 }