Exemple #1
0
        public static HediffKeepingCondition GetDefaultPlusSpecificHediffCondition(HediffKeepingCondition defaultHKC, HediffKeepingCondition specificHKC, bool debug = false)
        {
            string debugStr = debug ? "GetDefaultPlusSpecificHediffCondition - " : "";

            Tools.Warn(debugStr + "allocating answerHC", debug);
            HediffKeepingCondition answerHKC = new HediffKeepingCondition {
                needs = new List <NeedCondition>()
            };

            if (defaultHKC != null)
            {
                Tools.Warn(debugStr + "found defaultHKC, copying", debug);
                CopyHediffKeepingCondition(defaultHKC, answerHKC, debug);
            }

            if (specificHKC != null)
            {
                Tools.Warn(debugStr + "found specificHKC, copying", debug);
                CopyHediffKeepingCondition(specificHKC, answerHKC, debug);
            }

            Tools.Warn(
                debugStr +
                $"HasDestroyingHediffs:{answerHKC.HasDestroyingHediffs} - " + (answerHKC.HasDestroyingHediffs?answerHKC.destroyingHediffs.Count():0) +
                $"HasLightCondition:{answerHKC.HasLightCondition} - " +
                (answerHKC.HasLightCondition? ("reqIn:" + answerHKC.light.requiresInside + " reqOut:" + answerHKC.light.requiresOutside) : "") +
                $"HasNeedCondition:{answerHKC.HasNeedCondition}" + (answerHKC.HasNeedCondition ? answerHKC.needs.Count() : 0) +
                $"HasTemperatureCondition:{answerHKC.HasTemperatureCondition}"
                , debug);

            return(answerHKC);
        }
Exemple #2
0
        public static bool IsPawnNeedConditionCompatible(this Pawn p, HediffKeepingCondition HKC, bool debug = false)
        {
            string debugStr = debug ? $"{p.Label} IsPawnNeedConditionCompatible - " : "";

            if (HKC.HasNeedCondition)
            {
                foreach (NeedCondition nc in HKC.needs)
                {
                    bool doesContain = false;
                    foreach (Need n in p.needs.AllNeeds)
                    {
                        Tools.Warn(debugStr + $"{nc.needDef.defName} found in pawn needs, ok", debug);
                        doesContain |= n.def == nc.needDef;
                    }


                    if (!doesContain)
                    {
                        Tools.Warn(debugStr + $"{nc.needDef.defName} not found in pawn needs, exiting", debug);
                        return(false);
                    }
                }
            }

            Tools.Warn(debugStr + "is need compatible, ok", debug);

            return(true);
        }
Exemple #3
0
        public static void CopyHediffKeepingCondition(HediffKeepingCondition source, HediffKeepingCondition dest, bool debug = false)
        {
            string debugStr = debug ? "CopyHediffCondition - " : "";

            if (source.HasTemperatureCondition)
            {
                Tools.Warn(debugStr + "found HasTemperatureCondition, copying", debug);
                dest.temperature = source.temperature;
            }

            if (source.HasLightCondition)
            {
                Tools.Warn(debugStr + "found HasLightCondition, copying", debug);
                dest.light = new LightCondition(source.light);
            }
            if (source.HasNeedCondition)
            {
                Tools.Warn(debugStr + "found HasNeedCondition, copying", debug);
                foreach (NeedCondition nc in source.needs)
                {
                    if (dest.needs.Any(n => n.needDef == nc.needDef))
                    {
                        dest.needs.Where(n => n.needDef == nc.needDef).First().level = nc.level;
                    }
                    else
                    {
                        dest.needs.Add(new NeedCondition(nc));
                    }
                }
            }

            if (source.HasDestroyingHediffs)
            {
                Tools.Warn(debugStr + "found HasDestroyingHediffs, copying", debug);
                foreach (HediffSeverityCondition hsc in source.destroyingHediffs)
                {
                    if (dest.destroyingHediffs.Any(dh => dh.hediffDef == hsc.hediffDef))
                    {
                        dest.destroyingHediffs.Where(dh => dh.hediffDef == hsc.hediffDef).First().acceptableSeverity = hsc.acceptableSeverity;
                    }
                    else
                    {
                        dest.destroyingHediffs.Add(new HediffSeverityCondition(hsc));
                    }
                }
            }
        }
Exemple #4
0
        public static bool TreatRelevantHediffsAndReportIfStillHediffsToCheck(this HediffComp_OnTheCarpet comp)
        {
            bool Mydebug = comp.MyDebug;

            bool AtLeastOneIntersectHediffLeft  = false;
            bool AtLeastOneNonRemovedHediffLeft = false;

            Pawn   pawn     = comp.Pawn;
            string debugStr = Mydebug ? $"{pawn.LabelShort} TreatRelevant - " : "";

            Tools.Warn(debugStr + " Entering", Mydebug);

            float temperature = pawn.AmbientTemperature;
            float lightLevel  = pawn.Map.glowGrid.GameGlowAt(pawn.Position);
            Room  room        = pawn.GetRoom();
            bool  outside     = (room == null) ? true : room.PsychologicallyOutdoors;

            List <Hediff> pHediffs = comp.Pawn.health.hediffSet.hediffs;

            //foreach (Hediff H in comp.Pawn.health.hediffSet.hediffs)
            for (int Hi = pHediffs.Count - 1; Hi >= 0 && !pHediffs.NullOrEmpty(); Hi--)
            {
                Hediff H = pHediffs[Hi];
                foreach (HediffItemToRemove HITR in comp.Props.hediffPool.Where(h => h.hediffDef == H.def))
                {
                    Tools.Warn(debugStr + " found intersect hediff: " + H.def.defName, Mydebug);

                    AtLeastOneNonRemovedHediffLeft = true;

                    HediffKeepingCondition HKC = HediffRemovalConditionBuilder.GetDefaultPlusSpecificHediffCondition(comp.Props.defaultCondition, HITR.specificCondition, Mydebug);
                    bool RemovedSingleHediff   = false;
                    // Light : glow outside inside
                    if (HKC.HasLightCondition)
                    {
                        Tools.Warn(debugStr + H.def.defName + "checking light", Mydebug);
                        RemovedSingleHediff = pawn.TreatLightCondition(HKC.light, H, lightLevel, outside, Mydebug);
                    }
                    // Temperature
                    else if (HKC.HasTemperatureCondition && !HKC.temperature.Value.Includes(temperature))
                    {
                        Tools.Warn(debugStr + H.def.defName + "checking temperature", Mydebug);
                        RemovedSingleHediff = RemoveHediffAndReturnTrue(pawn, H, Mydebug);
                    }
                    // Needs
                    else if (HKC.HasNeedCondition)
                    {
                        Tools.Warn(debugStr + H.def.defName + "checking " + HKC.needs.Count + "need", Mydebug);
                        RemovedSingleHediff = pawn.TreatNeedCondition(HKC.needs, H, Mydebug);
                    }
                    // Hediffs
                    else if (HKC.HasDestroyingHediffs)
                    {
                        Tools.Warn(debugStr + H.def.defName + "checking other hediffs", Mydebug);
                        RemovedSingleHediff = pawn.TreatHediffSeverityCondition(HKC.destroyingHediffs, H, Mydebug);
                    }

                    AtLeastOneIntersectHediffLeft |= AtLeastOneNonRemovedHediffLeft = !RemovedSingleHediff;
                    if (RemovedSingleHediff)
                    {
                        return(true);
                    }
                }
            }


            Tools.Warn(debugStr + "exiting", Mydebug);
            return(AtLeastOneIntersectHediffLeft);
        }