public override float GetPriority(Pawn pawn)
        {
            float        zero      = 0f;
            Need_Silence quietNeed = pawn.needs.TryGetNeed <Need_Silence>();

            if (quietNeed == null)
            {
                return(zero);
            }
            if (FoodUtility.ShouldBeFedBySomeone(pawn))
            {
                return(zero);
            }
            float num = 0.3f;

            if (pawn.mindState.IsIdle)
            {
                num = 0.5f;
            }
            Need_Rest restNeed = pawn.needs.TryGetNeed <Need_Rest>();

            if (restNeed != null && restNeed.CurLevel > 0.95f)
            {
                num = 0.6f;
            }
            if (quietNeed.CurLevel < num)
            {
                return(8f);                // Bad Hygiene's use toilet is 9.6f;
            }
            return(zero);
        }
Esempio n. 2
0
 private static void TrySatisfyRestNeed(Pawn pawn, Need_Rest rest, Caravan caravan)
 {
     if (caravan.Resting)
     {
         rest.TickResting(1f);
     }
 }
        private void TrySatisfyPawnNeeds(Pawn pawn)
        {
            if (pawn.Dead)
            {
                return;
            }
            List <Need> allNeeds = pawn.needs.AllNeeds;

            for (int i = 0; i < allNeeds.Count; i++)
            {
                Need          need          = allNeeds[i];
                Need_Rest     need_Rest     = need as Need_Rest;
                Need_Food     need_Food     = need as Need_Food;
                Need_Chemical need_Chemical = need as Need_Chemical;
                Need_Joy      need_Joy      = need as Need_Joy;
                if (need_Rest != null)
                {
                    TrySatisfyRestNeed(pawn, need_Rest);
                }
                else if (need_Food != null)
                {
                    TrySatisfyFoodNeed(pawn, need_Food);
                }
                else if (need_Chemical != null)
                {
                    TrySatisfyChemicalNeed(pawn, need_Chemical);
                }
                else if (need_Joy != null)
                {
                    TrySatisfyJoyNeed(pawn, need_Joy);
                }
            }
        }
Esempio n. 4
0
        public float Daniel()
        {
            Need_Rest rest = pawn.needs.rest;

            if (rest == null)
            {
                return(0f);
            }

            switch (rest.CurCategory)
            {
            case RestCategory.Rested:
                return(1f);

            case RestCategory.Tired:
                return(0.5f);

            case RestCategory.VeryTired:
                return(0.125f);

            case RestCategory.Exhausted:
                return(0.0000000000000000001f);
            }

            //if (rest.CurCategory < RestCategory.VeryTired)
            //{
            //    return true;
            //}
            return(0f);
        }
 private static void TrySatisfyPawnNeeds(Pawn pawn, Caravan caravan)
 {
     if (!pawn.Dead)
     {
         List <Need> allNeeds = pawn.needs.AllNeeds;
         for (int i = 0; i < allNeeds.Count; i++)
         {
             Need          need          = allNeeds[i];
             Need_Rest     need_Rest     = need as Need_Rest;
             Need_Food     need_Food     = need as Need_Food;
             Need_Chemical need_Chemical = need as Need_Chemical;
             if (need_Rest != null)
             {
                 CaravanPawnsNeedsUtility.TrySatisfyRestNeed(pawn, need_Rest, caravan);
             }
             else if (need_Food != null)
             {
                 CaravanPawnsNeedsUtility.TrySatisfyFoodNeed(pawn, need_Food, caravan);
             }
             else if (need_Chemical != null)
             {
                 CaravanPawnsNeedsUtility.TrySatisfyChemicalNeed(pawn, need_Chemical, caravan);
             }
         }
     }
 }
Esempio n. 6
0
        public static bool Prefix(Need_Rest __instance, Pawn ___pawn, ref int ___ticksAtZero)
        {
            if (!PeacekeeperUtility.IsPeacekeeper(___pawn))
            {
                return(true);
            }

            // todo add class to hediff that removes the hediff when energy is available
            var isFrozen  = (bool)Traverse.Create(__instance).Property("IsFrozen").GetValue <bool>();
            var malnutInt = MalnutritionSeverityPerInterval(___pawn);

            if (!isFrozen)
            {
                __instance.CurLevel -= __instance.RestFallPerTick * 150f;
            }
            if (__instance.CurLevel < 0.0001f)
            {
                ___ticksAtZero += 150;
            }
            else
            {
                ___ticksAtZero = 0;
            }
            if (___ticksAtZero > 1000)
            {
                HealthUtility.AdjustSeverity(___pawn, RSDefOf.RSEnergyShortage, malnutInt * ModSettings.energyShortageSeverityMult);
            }
            else
            {
                HealthUtility.AdjustSeverity(___pawn, RSDefOf.RSEnergyShortage, -malnutInt);
            }

            return(false);
        }
Esempio n. 7
0
 public override bool ActivateOn(Lord lord, TriggerSignal signal)
 {
     if (signal.type == TriggerSignalType.Tick)
     {
         for (int i = 0; i < lord.ownedPawns.Count; i++)
         {
             if (GenAI.EnemyIsNear(lord.ownedPawns[i], 10f))
             {
                 return(false);
             }
             Need_Rest rest = lord.ownedPawns[i].needs.rest;
             if (rest != null)
             {
                 if (rest.CurLevelPercentage < 0.14f + this.extraRestThreshOffset && !lord.ownedPawns[i].Awake())
                 {
                     return(true);
                 }
             }
             Need_Food food = lord.ownedPawns[i].needs.food;
             if (food != null)
             {
                 if (food.CurCategory == HungerCategory.Starving)
                 {
                     return(true);
                 }
             }
         }
         return(false);
     }
     return(false);
 }
Esempio n. 8
0
 public static void CauseDream(Need_Rest __instance)
 {
     if (Traverse.Create(__instance).Property("Resting").GetValue <bool>())
     {
         Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue <Pawn>();
         if (Rand.Value < 0.001f && pawn.RaceProps.Humanlike && !pawn.Awake())
         {
             if (Rand.Value < 0.5f)
             {
                 if (Rand.Value < 0.125f)
                 {
                     pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfPsychology.DreamNightmare, pawn);
                 }
                 else
                 {
                     pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfPsychology.DreamBad, pawn);
                 }
             }
             else
             {
                 pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfPsychology.DreamGood, pawn);
             }
         }
     }
 }
Esempio n. 9
0
        public override Job TryGiveJob(Pawn pawn)
        {
            Need_Rest need = pawn.needs.rest;

            if (need == null || need.CurLevelPercentage > this.def.restRequirement)
            {
                return(null);
            }

            float dayP = GenLocalDate.DayPercent(pawn.Map);

            if (dayP < 0.42f && dayP > 0.7f)
            {
                return(null);
            }

            Building_Bed bed = RestUtility.FindBedFor(pawn);

            if (bed != null)
            {
                return(new Job(IdleJobDefOf.IdleJob_TakeNap, bed)
                {
                    locomotionUrgency = LocomotionUrgency.Walk
                });
            }

            return(null);
        }
        public override bool ActivateOn(Lord lord, TriggerSignal signal)
        {
            bool result;

            if (signal.type == TriggerSignalType.Tick)
            {
                for (int i = 0; i < lord.ownedPawns.Count; i++)
                {
                    Need_Rest rest = lord.ownedPawns[i].needs.rest;
                    if (rest != null)
                    {
                        if (rest.CurLevelPercentage < 0.14f + this.extraRestThreshOffset && !lord.ownedPawns[i].Awake())
                        {
                            return(false);
                        }
                    }
                }
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }
 private static void TrySatisfyRestNeed(Pawn pawn, Need_Rest rest, Caravan caravan)
 {
     if (caravan.Resting)
     {
         float restEffectiveness = RestUtility.PawnHealthRestEffectivenessFactor(pawn);
         rest.TickResting(restEffectiveness);
     }
 }
Esempio n. 12
0
 private void TrySatisfyRestNeed(Pawn pawn, Need_Rest rest)
 {
     if (!caravan.pather.MovingNow || pawn.InCaravanBed() || pawn.CarriedByCaravan())
     {
         float restEffectiveness = pawn.CurrentCaravanBed()?.GetStatValue(StatDefOf.BedRestEffectiveness) ?? 0.8f;
         rest.TickResting(restEffectiveness);
     }
 }
Esempio n. 13
0
        // When the robot is idle, check if it is inside the room of the recharge station. If not, return there.
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            X2_AIRobot robot = pawn as X2_AIRobot;

            if (robot.DestroyedOrNull())
            {
                return(ThinkResult.NoJob);
            }
            if (!robot.Spawned)
            {
                return(ThinkResult.NoJob);
            }

            X2_Building_AIRobotRechargeStation rechargeStation = robot.rechargeStation;

            if (rechargeStation.DestroyedOrNull())
            {
                return(ThinkResult.NoJob);
            }
            if (!rechargeStation.Spawned)
            {
                return(ThinkResult.NoJob);
            }


            Need_Rest needRest = pawn.needs.rest;

            if (needRest == null)
            {
                return(ThinkResult.NoJob);
            }

            float curLevel = needRest.CurLevel;

            Job jobIdle = new Job(DefDatabase <JobDef> .GetNamed("AIRobot_GoAndWait"), rechargeStation);

            jobIdle.locomotionUrgency = LocomotionUrgency.Amble;

            if (curLevel > 0.751f)
            {
                return(new ThinkResult(jobIdle, this, JobTag.Idle, false));
            }

            //double distance = AIRobot_Helper.GetDistance(pawn.Position, (pawn as X2_AIRobot).rechargeStation.Position);
            //
            //if (distance > 5f)
            //    return ThinkResult.NoJob;

            //Boolean isInDistance = AIRobot_Helper.IsInDistance(pawn.Position, (pawn as X2_AIRobot).rechargeStation.Position, 5);
            //if (isInDistance)
            //    return ThinkResult.NoJob;

            Job job = new Job(DefDatabase <JobDef> .GetNamed("AIRobot_GoRecharge"), rechargeStation);

            job.locomotionUrgency = LocomotionUrgency.Amble;

            return(new ThinkResult(job, this, JobTag.SatisfyingNeeds, false));
        }
Esempio n. 14
0
        public override float GetPriority(Pawn pawn)
        {
            if (pawn == null || pawn.needs == null)
            {
                return(0f);
            }

            Need_Rest needRest = pawn.needs.rest;

            if (needRest == null)
            {
                return(0f);
            }

            float             curLevel          = needRest.CurLevel;
            TimeAssignmentDef timeAssignmentDef = (pawn.timetable != null ? pawn.timetable.CurrentAssignment : TimeAssignmentDefOf.Anything);

            if (timeAssignmentDef == TimeAssignmentDefOf.Anything || timeAssignmentDef == TimeAssignmentDefOf.Work)
            {
                if ((pawn as X2_AIRobot) == null || (pawn as X2_AIRobot).rechargeStation == null || (pawn as X2_AIRobot).rechargeStation.Position == null)
                {
                    return(0f);
                }

                // Own implementation: When level < 45% && dist > 25
                bool isOutsideMaxDistance = !AIRobot_Helper.IsInDistance(pawn.Position, (pawn as X2_AIRobot).rechargeStation.Position, 25f);
                if (curLevel < 0.45f && pawn as X2_AIRobot != null && isOutsideMaxDistance)
                {
                    return(8f);
                }

                if (curLevel < 0.25f)
                {
                    return(8f);
                }

                return(0f);
            }
            if (timeAssignmentDef == TimeAssignmentDefOf.Joy)
            {
                if (curLevel < 0.3f)
                {
                    return(8f);
                }

                return(0f);
            }
            if (timeAssignmentDef == TimeAssignmentDefOf.Sleep)
            {
                if (curLevel < 0.75f)
                {
                    return(8f);
                }

                return(0f);
            }
            return(0f);
        }
Esempio n. 15
0
 public static void Postfix(Need_Rest __instance)
 {
     if (true &&
         __instance.pawn.IsValidWildlifeOrWorldPawn() &&
         __instance.pawn.IsSkippingTicks())
     {
         __instance.lastRestTick += __instance.pawn.GetDeltaT();
     }
 }
Esempio n. 16
0
 private void TrySatisfyRestNeed(Pawn pawn, Need_Rest rest)
 {
     if (!this.caravan.pather.MovingNow || pawn.InCaravanBed() || pawn.CarriedByCaravan())
     {
         Building_Bed building_Bed      = pawn.CurrentCaravanBed();
         float        restEffectiveness = (building_Bed == null) ? 0.8f : building_Bed.GetStatValue(StatDefOf.BedRestEffectiveness, true);
         rest.TickResting(restEffectiveness);
     }
 }
Esempio n. 17
0
 // ToDo: Rotate pawns to allow for some pawns to rest while others
 // use the vehicle.
 // RimWorld.Planet.CaravanPawnsNeedsUtility
 public static void TrySatisfyRestNeed(Pawn pawn, Need_Rest rest, Pawn Vehicle)
 {
     //Do not try to rest in the vehicle during combat.
     //It's too dangerous to sleep while driving.
     //if (Vehicle.Map?.attackTargetsCache?.GetPotentialTargetsFor(Vehicle)?.FirstOrDefault(x => !x.ThreatDisabled()) == null)
     //{
     //    float restEffectiveness = RestUtility.PawnHealthRestEffectivenessFactor(pawn);
     //    rest.TickResting(restEffectiveness);
     //}
 }
Esempio n. 18
0
        public override void HandleTick(SkillRecord sk, Pawn pawn)
        {
            SkillDef sd = InterestBase.GetActiveSkill(pawn);

            if (sd == null)
            {
                return;
            }
            SkillRecord skill = pawn.skills.GetSkill(sd);

            if (skill != sk)
            {
                return;
            }

            Need_Rest restNeed = pawn.needs.TryGetNeed(NeedDefOf.Rest) as Need_Rest;

            if (restNeed == null)
            {
                Log.Error("Got null rest need, wat");
                return;
            }

            // Rest fall per 150 ticks is 150f*1.58333332E-05f * RestFallFactor * (modifier based on tiredness level);
            // Perfect equilibrium is 200f* 1.58333332E-05f
            RestCategory rc = restNeed.CurCategory;
            float        factor;

            switch (rc)
            {
            case RestCategory.Rested:
                factor = 1.0f;
                break;

            case RestCategory.Tired:
                factor = 0.7f;
                break;

            case RestCategory.VeryTired:
                factor = 0.3f;
                break;

            case RestCategory.Exhausted:
                factor = 0.6f;
                break;

            default:
                factor = 999f;
                break;
            }
            float restGain = (200f / 2.0f) * 1.58333332E-05f * factor;

            restNeed.CurLevel += restGain;
        }
Esempio n. 19
0
 internal static void SetTicksAtZero(this Need_Rest _this, int ticks)
 {
     if (_ticksAtZero == null)
     {
         _ticksAtZero = typeof(Need_Rest).GetField("ticksAtZero", BindingFlags.Instance | BindingFlags.NonPublic);
         if (_ticksAtZero == null)
         {
             Log.ErrorOnce("Unable to reflect Need_Rest.ticksAtZero!", 305432421);
         }
     }
     _ticksAtZero.SetValue(_this, ticks);
 }
Esempio n. 20
0
 internal static int GetLastRestTick(this Need_Rest _this)
 {
     if (_lastRestTick == null)
     {
         _lastRestTick = typeof(Need_Rest).GetField("lastRestTick", BindingFlags.Instance | BindingFlags.NonPublic);
         if (_lastRestTick == null)
         {
             Log.ErrorOnce("Unable to reflect Need_Rest.lastRestTick!", 305432421);
         }
     }
     return((int)_lastRestTick.GetValue(_this));
 }
Esempio n. 21
0
 internal static float GetLastRestEffectiveness(this Need_Rest _this)
 {
     if (_lastRestEffectiveness == null)
     {
         _lastRestEffectiveness = typeof(Need_Rest).GetField("lastRestEffectiveness", BindingFlags.Instance | BindingFlags.NonPublic);
         if (_lastRestEffectiveness == null)
         {
             Log.ErrorOnce("Unable to reflect Need_Rest.lastRestEffectiveness!", 305432421);
         }
     }
     return((float)_lastRestEffectiveness.GetValue(_this));
 }
Esempio n. 22
0
 internal static Pawn GetPawn(this Need_Rest _this)
 {
     if (_pawn == null)
     {
         _pawn = typeof(Need_Rest).GetField("pawn", BindingFlags.Instance | BindingFlags.NonPublic);
         if (_pawn == null)
         {
             Log.ErrorOnce("Unable to reflect Need_Rest.pawn!", 0x12348765);
         }
     }
     return((Pawn)_pawn.GetValue(_this));
 }
        static bool Prefix(RestCategory ___minCategory, float ___maxLevelPercentage, ref float __result, Pawn pawn)
        {
            Need_Rest rest = pawn.needs.rest;

            if (rest == null)
            {
                __result = 0f; return(false);
            }
            if (rest.CurCategory < ___minCategory)
            {
                __result = 0f; return(false);
            }
            if (rest.CurLevelPercentage > ___maxLevelPercentage)
            {
                __result = 0f; return(false);
            }
            if (Find.TickManager.TicksGame < pawn.mindState.canSleepTick)
            {
                __result = 0f; return(false);
            }
            TimeAssignmentDef timeAssignmentDef;

            if (pawn.RaceProps.Humanlike)
            {
                timeAssignmentDef = ((pawn.timetable == null) ? TimeAssignmentDefOf.Anything : pawn.timetable.CurrentAssignment);
                if (timeAssignmentDef != TimeAssignmentDefDinner.DinnerDef)
                {
                    return(true);
                }

                Lord lord = pawn.GetLord();
                if (lord != null && !lord.CurLordToil.AllowSatisfyLongNeeds)
                {
                    __result = 0f; return(false);
                }
                float curLevel = rest.CurLevel;
                if (curLevel < 0.3f)
                {
                    __result = 8f;
                }
                else
                {
                    __result = 0f;
                }
                //Log.Message("{0} rest priority = {1}".Translate(pawn.Label, __result));

                return(false);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 24
0
        // RimWorld.Need_Rest
        public static void Vamp_SleepyDuringDaylight(Need_Rest __instance)
        {
            Pawn pawn = (Pawn)AccessTools.Field(typeof(Need_Rest), "pawn").GetValue(__instance);

            if (pawn != null && pawn.IsVampire())
            {
                if (VampireUtility.IsDaylight(pawn))
                {
                    __instance.CurLevel = Mathf.Min(0.1f, __instance.CurLevel);
                }
                else
                {
                    __instance.CurLevel = 1.0f;
                }
            }
        }
Esempio n. 25
0
        private bool closeToSleepNow()
        {
            if (!(parent is Pawn) || ((Pawn)parent).needs == null || ((Pawn)parent).needs.rest == null)
            {
                return(false);
            }
            Need_Rest rest = ((Pawn)parent).needs.rest;

            if (rest.MaxLevel >= 0.8)
            {
                return(rest.CurLevel <= 0.4);
            }
            else
            {
                return(rest.CurLevelPercentage <= 0.5);
            }
        }
Esempio n. 26
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (HiveUtility.JobGivenRecentTick(pawn, "LayDown"))
            {
                return(null);
            }
            Need_Rest rest = pawn.needs.rest;

            if (rest == null || rest.CurCategory < minCategory)
            {
                return(null);
            }
            if (RestUtility.DisturbancePreventsLyingDown(pawn))
            {
                return(null);
            }
            return(new Job(JobDefOf.LayDown, FindGroundSleepSpotFor(pawn)));
        }
Esempio n. 27
0
 public static void MakeInsomniacLessRestful(Need_Rest __instance)
 {
     if (Traverse.Create(__instance).Property("Resting").GetValue <bool>())
     {
         Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue <Pawn>();
         if (!Traverse.Create(__instance).Property("IsFrozen").GetValue <bool>() && pawn.RaceProps.Humanlike && pawn.story.traits.HasTrait(TraitDefOfPsychology.Insomniac))
         {
             __instance.CurLevel -= (2f * 150f * Need_Rest.BaseRestGainPerTick) / 3f;
             if (__instance.CurLevel > (Need_Rest.DefaultNaturalWakeThreshold / 4f))
             {
                 if (Rand.MTBEventOccurs((Need_Rest.DefaultNaturalWakeThreshold - __instance.CurLevel) / 4f, GenDate.TicksPerDay, 150f) && !pawn.Awake())
                 {
                     pawn.jobs.curDriver.asleep = false;
                     pawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                 }
             }
         }
     }
 }
        protected override Job TryGiveJob(Pawn pawn)
        {
            Need_Rest rest = pawn.needs.rest;

            if (rest == null || (int)rest.CurCategory < (int)minCategory || rest.CurLevelPercentage > maxLevelPercentage)
            {
                return(null);
            }
            if (RestUtility.DisturbancePreventsLyingDown(pawn))
            {
                return(null);
            }
            var spot = FindGroundSafeSpotFor(pawn);

            if (spot.IsValid)
            {
                return(JobMaker.MakeJob(JobDefOf.LayDown, spot));
            }
            return(null);
        }
Esempio n. 29
0
        public override float GetPriority(Pawn pawn)
        {
            Need_Rest needRest = pawn.needs.rest;

            if (needRest == null)
            {
                return(0f);
            }
            float             curLevel          = needRest.CurLevel;
            TimeAssignmentDef timeAssignmentDef = (pawn.timetable != null ? pawn.timetable.CurrentAssignment : TimeAssignmentDefOf.Anything);

            if (timeAssignmentDef == TimeAssignmentDefOf.Anything)
            {
                if (curLevel < 0.3f)
                {
                    return(8f);
                }
                return(0f);
            }
            if (timeAssignmentDef == TimeAssignmentDefOf.Work)
            {
                return(0f);
            }
            if (timeAssignmentDef == TimeAssignmentDefOf.Joy)
            {
                if (curLevel < 0.3f)
                {
                    return(8f);
                }
                return(0f);
            }
            if (timeAssignmentDef != TimeAssignmentDefOf.Sleep)
            {
                throw new NotImplementedException();
            }
            if (curLevel < 0.75f)
            {
                return(8f);
            }
            return(0f);
        }
        private void TrySatisfyPawnNeeds(Pawn pawn)
        {
            if (pawn.Dead)
            {
                return;
            }
            List <Need> allNeeds = pawn.needs.AllNeeds;

            for (int i = 0; i < allNeeds.Count; i++)
            {
                Need          need          = allNeeds[i];
                Need_Rest     need_Rest     = need as Need_Rest;
                Need_Food     need_Food     = need as Need_Food;
                Need_Chemical need_Chemical = need as Need_Chemical;
                Need_Joy      need_Joy      = need as Need_Joy;
                if (need_Rest != null)
                {
                    TrySatisfyRestNeed(pawn, need_Rest);
                }
                else if (need_Food != null)
                {
                    TrySatisfyFoodNeed(pawn, need_Food);
                }
                else if (need_Chemical != null)
                {
                    TrySatisfyChemicalNeed(pawn, need_Chemical);
                }
                else if (need_Joy != null)
                {
                    TrySatisfyJoyNeed(pawn, need_Joy);
                }
            }
            Pawn_PsychicEntropyTracker psychicEntropy = pawn.psychicEntropy;

            if (psychicEntropy.Psylink != null)
            {
                TryGainPsyfocus(psychicEntropy);
            }
        }