public static void ChangePriority(this Pawn pawn, WorkGiverDef workgiver, int diff, int hour, bool recache = true) { if (hour < 0) { hour = GenLocalDate.HourOfDay(pawn); } int priority = pawn.GetPriority(workgiver, hour) + diff; SetPriority(pawn, workgiver, priority, hour, recache); }
public bool ShouldDoNow(ActivityTask task) { if (tasks.Contains(task)) { if (GenLocalDate.DayOfSeason(Find.CurrentMap) == dayNumber && task.ShouldDoNow()) { return(true); } } return(false); }
public override bool Trigger(IncidentDef param, Map map) { if (map is null) { return(false); } if (!allowedSeasons?.Contains(GenLocalDate.Season(map.Tile)) ?? true) { return(false); } return(base.Trigger(param, map)); }
public override float Multiplier() { float distanceFromMidday = Mathf.Abs(0.45f - GenLocalDate.DayPercent(pawn.Map)); if (distanceFromMidday > 0.5f) { distanceFromMidday = 1.0f - distanceFromMidday; } float m = distanceFromMidday * 4 - 1f; return(m < 0 ? m * def.negativeMultiplier : m *def.positiveMultiplier); }
protected override Job TryGiveJob(Pawn pawn) { if (!CultKnowledge.isExposed) { return(null); } if (CultKnowledge.selectedDeity == null) { return(null); } /* * Get [CurrentAssignment] indirectly, because [pawn.timetable.CurrentAssignment] getter has harmony patch. * Patch overrides result from [Cults_TimeAssignment_Worship] to [TimeAssignmentDefOf.Anything] * Vanilla functions can't check custom timetable defs otherwise they throw [NotImplementedException] * [JobGiver_Worship] happens before core colonist behavior * * Classes that check a schedule: * ThinkNode_Priority_GetJoy * JobGiver_GetRest * JobGiver_Work */ // TimeAssignmentDef assignment = pawn.timetable.CurrentAssignment; TimeAssignmentDef assignment = pawn.timetable.times[GenLocalDate.HourOfDay(pawn)]; // TODO: implement reservations IEnumerable <Building_BaseAltar> altars = pawn.Map.listerBuildings.AllBuildingsColonistOfClass <Building_BaseAltar>(); TraverseParms parms = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false); Thing altar = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, altars, PathEndMode.OnCell, parms); if (altar != null) { if (!WatchBuildingUtility.TryFindBestWatchCell(altar, pawn, true, out IntVec3 spot, out Building chair)) { if (!WatchBuildingUtility.TryFindBestWatchCell(altar, pawn, false, out spot, out chair)) { return(null); } } ; Job job = JobMaker.MakeJob(CultsDefOf.Cults_Job_Worship, spot, altar); //if(pawn.CurJob != null)Log.Message("info " + pawn.HasReserved(pawn.CurJob.targetA).ToString() + " " + pawn.CurJobDef.defName.ToString()); //if(pawn.CanReserve(spot, 1, -1)) pawn.Reserve(spot, job, 1, -1); if (assignment == Cults.CultsDefOf.Cults_TimeAssignment_Worship) { return(job); } } ; return(null); }
protected override Job TryGiveJob(Pawn pawn) { Pawn_Drone drone = (Pawn_Drone)pawn; if (drone.station != null) { if (drone.station.Spawned && drone.station.Map == pawn.Map) { Job result = null; if (drone.station is Building_WorkGiverDroneStation b) { if (!(drone.station.cachedSleepTimeList.Contains(GenLocalDate.HourOfDay(drone).ToString()))) { pawn.workSettings = new Pawn_WorkSettings(pawn); pawn.workSettings.EnableAndInitialize(); pawn.workSettings.DisableAll(); foreach (WorkTypeDef def in b.WorkSettings_dict.Keys) { if (b.WorkSettings_dict[def]) { pawn.workSettings.SetPriority(def, 3); } else { pawn.workSettings.SetPriority(def, 0); } } // So the station finds the best job for the pawn result = b.TryIssueJobPackageDrone(drone, true).Job; if (result == null) { result = b.TryIssueJobPackageDrone(drone, false).Job; } } } else { result = drone.station.TryGiveJob(); } if (result == null) { result = new Job(PRFDefOf.PRFDrone_ReturnToStation, drone.station); } return(result); } return(new Job(PRFDefOf.PRFDrone_SelfTerminate)); } return(null); }
//TODO Finding a good way to Cache pawn.workSettings may increase performence public override Job TryGiveJob() { Job result = null; if (!(cachedSleepTimeList.Contains(GenLocalDate.HourOfDay(this).ToString()))) { //Only plausibel enhancment would be to cache the pawn //MakeDrone Average time of 1ms Pawn pawn = MakeDrone(); //Spawn is cheap GenSpawn.Spawn(pawn, Position, Map); if (workSettings == null) { //This case takes an Average of 3.31ms pawn.workSettings = new Pawn_WorkSettings(pawn); pawn.workSettings.EnableAndInitialize(); pawn.workSettings.DisableAll(); workSettings = pawn.workSettings; } else { pawn.workSettings = workSettings; } //This loop is cheap //Set the workSettings based upon the settings foreach (WorkTypeDef def in WorkSettings.Keys) { if (WorkSettings[def]) { pawn.workSettings.SetPriority(def, 3); } else { pawn.workSettings.SetPriority(def, 0); } } //Each call to TryIssueJobPackageDrone takes an Average of 1ms result = TryIssueJobPackageDrone(pawn, true).Job; if (result == null) { result = TryIssueJobPackageDrone(pawn, false).Job; } pawn.Destroy(); Notify_DroneGained(); } return(result); }
private float LowestTemperatureComing([NotNull] Map map) { Twelfth twelfth = GenLocalDate.Twelfth(map); float a = this.GetTemperature(twelfth, map); for (int i = 0; i < 3; i++) { twelfth = twelfth.NextTwelfth(); a = Mathf.Min(a, this.GetTemperature(twelfth, map)); } return(Mathf.Min(a, map.mapTemperature.OutdoorTemp)); }
private float HighestTemperatureComing([NotNull] Map map) { var twelfth = GenLocalDate.Twelfth(map); var a = GetTemperature(twelfth, map); for (var i = 0; i < 3; i++) { twelfth = twelfth.NextTwelfth(); a = Mathf.Max(a, GetTemperature(twelfth, map)); } return(Mathf.Max(a, map.mapTemperature.OutdoorTemp)); }
public static void ClearYesterdaysSkillValues(Pawn pawn) { int num = GenLocalDate.DayOfYear(pawn); if (PawnMeleeSkillValues.ContainsKey(pawn.ThingID) && PawnMeleeSkillValues[pawn.ThingID].DayOfYear != num) { PawnMeleeSkillValues.Remove(pawn.ThingID); } if (PawnShootingSkillValues.ContainsKey(pawn.ThingID) && PawnShootingSkillValues[pawn.ThingID].DayOfYear != num) { PawnShootingSkillValues.Remove(pawn.ThingID); } }
private static float AlertNeedWarmClothes_LowestTemperatureComing(Map map) { Twelfth twelfth = GenLocalDate.Twelfth(map); float a = GenTemperature.AverageTemperatureAtTileForTwelfth(map.Tile, twelfth); for (int i = 0; i < 3; i++) { twelfth = twelfth.NextTwelfth(); a = Mathf.Min(a, GenTemperature.AverageTemperatureAtTileForTwelfth(map.Tile, twelfth)); } return(Mathf.Min(a, map.mapTemperature.OutdoorTemp)); }
static bool Prefix(ref ThoughtState __result, Pawn p) { if (p.needs.food == null) { __result = ThoughtState.Inactive; return(false); } if (p.RaceProps.Humanlike && p.timetable != null) { TimeAssignmentDef timeAssignmentDef = p.timetable.CurrentAssignment; if (timeAssignmentDef != TimeAssignmentDefDinner.DinnerDef) { Need_Food food = p.needs.food; if (p.timetable.GetAssignment((GenLocalDate.HourOfDay(p) + 1) % 24) == TimeAssignmentDefDinner.DinnerDef && food.CurLevelPercentage > p.RaceProps.FoodLevelPercentageWantEat * 0.45f && food.CurCategory >= HungerCategory.Hungry) {//下一小时是dinner时间并且饥饿度百分比>0.45并且处于饥饿及以上类型状态 __result = ThoughtState.ActiveAtStage(7); return(false); } } } switch (p.needs.food.CurCategory) { case HungerCategory.Fed: __result = ThoughtState.Inactive; return(false); case HungerCategory.Hungry: __result = ThoughtState.ActiveAtStage(0); return(false); case HungerCategory.UrgentlyHungry: __result = ThoughtState.ActiveAtStage(1); return(false); case HungerCategory.Starving: { Hediff firstHediffOfDef = p.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Malnutrition, false); int num = (firstHediffOfDef == null) ? 0 : firstHediffOfDef.CurStageIndex; if (num > 4) { num = 4; } __result = ThoughtState.ActiveAtStage(2 + num); return(false); } default: throw new NotImplementedException(); } }
public static void CancelJob(ref Job __result, Pawn pawn) { Pawn partner = LovePartnerRelationUtility.GetPartnerInMyBed(pawn); if (PsycheHelper.PsychologyEnabled(pawn) && PsycheHelper.PsychologyEnabled(partner) && PsychologyBase.ActivateKinsey()) { float random = Rand.ValueSeeded((pawn.GetHashCode() ^ (GenLocalDate.DayOfYear(pawn) + GenLocalDate.Year(pawn) + (int)(GenLocalDate.DayPercent(pawn) * 2) * 60) * 391)); float random2 = Rand.ValueSeeded((pawn.GetHashCode() ^ (GenLocalDate.DayOfYear(partner) + GenLocalDate.Year(partner) + (int)(GenLocalDate.DayPercent(partner) * 2) * 60) * 391)); if (random > PsycheHelper.Comp(pawn).Sexuality.AdjustedSexDrive&& random2 > PsycheHelper.Comp(partner).Sexuality.AdjustedSexDrive) { __result = null; } } }
public static int NowToTicks(int tileId) { var day = GenLocalDate.DayOfYear(tileId); var year = GenLocalDate.Year(tileId); var ticks = DateToTicks(day, year); if (ticks == 0) { ticks = 1; } return(ticks); }
public static void TickMindstateLeaveDaylight(Pawn __instance) { if (__instance?.kindDef == PawnKindDefOf_SCP.SCP_939_PawnKindDef && __instance.Spawned) { if (GenLocalDate.HourOfDay(__instance.Map) >= 5 && GenLocalDate.HourOfDay(__instance.Map) < 19) { if (CellFinder.TryFindRandomPawnExitCell(__instance, out IntVec3 cell)) { Job job = new Job(JobDefOf_SCP.LeaveMapDaylight, cell); __instance.jobs.TryTakeOrderedJob(job, JobTag.DraftedOrder); } } } }
public static bool CheckSeason(this Pawn p, List <Season> seasons) { if (p.Map == null) { return(false); } if (seasons.Contains(GenLocalDate.Season(p.Map))) { return(true); } return(false); }
private void Finished() { List <Pair <Pawn, int> > voteTally = new List <Pair <Pawn, int> >(); foreach (Candidate candidate in this.candidates) { IEnumerable <string> votesForMe = (from v in this.votes where v == candidate.pawn.LabelShort select v); voteTally.Add(new Pair <Pawn, int>(candidate.pawn, votesForMe.Count())); } //If there ends up being a tie, we'll just assume the least competitive candidates drop out. //The chances of there being a tie after that are exceedingly slim, but the result will be essentially random. IEnumerable <Pair <Pawn, int> > orderedTally = (from v in voteTally orderby PsycheHelper.Comp(v.First).Psyche.GetPersonalityRating(PersonalityNodeDefOf.Competitive) descending orderby v.Second descending select v); if (Prefs.DevMode && Prefs.LogVerbose) { foreach (Pair <Pawn, int> t in orderedTally) { Log.Message("Psychology :: Votes for " + t.First + ": " + t.Second); } } Pair <Pawn, int> winningCandidate = orderedTally.First(); if (orderedTally.Count() > 1 && orderedTally.First().Second == orderedTally.ElementAt(1).Second) { Find.LetterStack.ReceiveLetter("LetterLabelTieSettled".Translate(winningCandidate.First), "LetterTieSettled".Translate(winningCandidate.First), LetterDefOf.NeutralEvent, winningCandidate.First); } StringBuilder issuesString = new StringBuilder(); for (int i = 0; i < candidates.Find(c => c.pawn == winningCandidate.First).nodes.Count; i++) { issuesString.AppendFormat("{0}) {1}{2}", i + 1, PsycheHelper.Comp(winningCandidate.First).Psyche.GetPersonalityNodeOfDef(candidates.Find(c => c.pawn == winningCandidate.First).nodes[i]).PlatformIssue, (i != candidates.Find(c => c.pawn == winningCandidate.First).nodes.Count - 1 ? "\n" : "")); } if (this.map == null) { this.map = winningCandidate.First.Map; } Hediff mayor = HediffMaker.MakeHediff(HediffDefOfPsychology.Mayor, winningCandidate.First); (mayor as Hediff_Mayor).worldTileElectedOn = map.Tile; (mayor as Hediff_Mayor).yearElected = GenLocalDate.Year(map); winningCandidate.First.health.AddHediff(mayor); winningCandidate.First.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfPsychology.WonElection); Find.LetterStack.ReceiveLetter("LetterLabelElectionWon".Translate(winningCandidate.First), "LetterElectionWon".Translate(winningCandidate.First, this.baseName, winningCandidate.Second, issuesString.ToString()), LetterDefOf.NeutralEvent, winningCandidate.First); }
private void TryTimedLesson() { int teacherInt = seasonSchedule[GenLocalDate.DayOfSeason(this.Map)]; if (teacherInt >= 3) { tempTeacher = TeachingUtility.DetermineTeacher(this.Map); } else { tempTeacher = teachers[teacherInt - 1]; } TryLesson(); }
public override float TemperatureOffset() { Map map = Find.CurrentMap; if (GenLocalDate.HourInteger(map) >= 11 && GenLocalDate.HourInteger(map) <= 19) { return(GameConditionUtility.LerpInOutValue(this, 10000f, MaxTempOffset)); } else if (GenLocalDate.HourInteger(map) >= 20 || GenLocalDate.HourInteger(map) <= 10) { return(GameConditionUtility.LerpInOutValue(this, 10000f, MinTempOffset)); } return(GameConditionUtility.LerpInOutValue(this, 10000f, MaxTempOffset)); }
public static TimeAssignmentDef TimeAssignmentFor(Pawn pawn) { int hour = GenLocalDate.HourOfDay(pawn); ExtendedRaceProperties extendedRaceProps = pawn.def.GetModExtension <ExtendedRaceProperties>(); if (extendedRaceProps != null && extendedRaceProps.bodyClock == BodyClock.Crepuscular) { return(hour > 3 && hour < 16 ? TimeAssignmentDefOf.Sleep : TimeAssignmentDefOf.Anything); } else if (extendedRaceProps != null && extendedRaceProps.bodyClock == BodyClock.Nocturnal) { return(hour > 9 && hour < 19 ? TimeAssignmentDefOf.Sleep : TimeAssignmentDefOf.Anything); } return((hour >= 7 && hour <= 21) ? TimeAssignmentDefOf.Anything : TimeAssignmentDefOf.Sleep); }
private void DrawFloatMenu() { try { var model = Model; var hour = GenLocalDate.HourOfDay(Model.Base); var options = DefDatabase <TimeAssignmentDef> .AllDefs.Select(timeAssignment => new FloatMenuOption(Lang.Get("Model.Selector.SetTimeAssignment", hour, timeAssignment.LabelCap), () => Mod_Multiplayer.SetAssignment(model.Base, hour, timeAssignment))).ToList(); options.Add(new FloatMenuOption(Lang.Get("Model.Selector.Manage").Italic(), () => Find.MainTabsRoot.SetCurrentTab(Access.MainButtonDefOfRestrict))); Find.WindowStack.Add(new FloatMenu(options)); } catch (Exception exception) { Mod.HandleError(exception); } }
internal static void Postfix(ref float __result, Map ___map, ThingDef plant) { if (!plant.HasModExtension <DM_ModExtension>()) { return; } DM_ModExtension ext = plant.GetModExtension <DM_ModExtension>(); if (SeasonUtility.GetPreviousSeason(ext.season) == GenLocalDate.Season(___map) && ext.spawnInPreviousSeason) { __result = (ext.commonality / 2); return; } __result = ext.commonality; }
public static void CancelJob(ref Job __result, Pawn pawn) { Pawn partnerInMyBed = LovePartnerRelationUtility.GetPartnerInMyBed(pawn); PsychologyPawn realPawn = pawn as PsychologyPawn; PsychologyPawn realPartner = partnerInMyBed as PsychologyPawn; if (realPawn != null && realPartner != null && PsychologyBase.ActivateKinsey() && realPawn.sexuality != null && realPartner.sexuality != null) { float random = Rand.ValueSeeded((pawn.GetHashCode() ^ (GenLocalDate.DayOfYear(pawn) + GenLocalDate.Year(pawn) + (int)(GenLocalDate.DayPercent(pawn) * 2) * 60) * 391)); if (random > realPawn.sexuality.AdjustedSexDrive && random > realPartner.sexuality.AdjustedSexDrive) { __result = null; } } }
public static Thought_Memory AddDesensitizedChance(Thought_Memory thought_Memory, Pawn pawn) { if (thought_Memory != null && thought_Memory.def == ThoughtDefOf.ObservedLayingCorpse) { if (!pawn.story.traits.HasTrait(TraitDefOfPsychology.BleedingHeart) && !pawn.story.traits.HasTrait(TraitDefOf.Psychopath) && !pawn.story.traits.HasTrait(TraitDefOf.Bloodlust) && !pawn.story.traits.HasTrait(TraitDefOfPsychology.Desensitized)) { if (((pawn.GetHashCode() ^ (GenLocalDate.DayOfYear(pawn) + GenLocalDate.Year(pawn) + (int)(GenLocalDate.DayPercent(pawn) * 5) * 60) * 391) % 1000) == 0) { pawn.story.traits.GainTrait(new Trait(TraitDefOfPsychology.Desensitized)); pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfPsychology.RecentlyDesensitized); } } } return(thought_Memory); }
// during night, drift towards colony ======================================================= // public static void Wander(this JobDriver_Stumble driver, Zombie zombie, PheromoneGrid grid, List <IntVec3> possibleMoves) { if (driver.destination.IsValid) { return; } // check for day/night and dust/dawn // during night, zombies drift towards the colonies center // if (zombie.Map.areaManager.Home[zombie.Position] == false) { var moveTowardsCenter = false; var hour = GenLocalDate.HourOfDay(Find.CurrentMap); if (hour < 12) { hour += 24; } if (hour > Constants.HOUR_START_OF_NIGHT && hour < Constants.HOUR_END_OF_NIGHT) { moveTowardsCenter = true; } else if (hour >= Constants.HOUR_START_OF_DUSK && hour <= Constants.HOUR_START_OF_NIGHT) { moveTowardsCenter = Rand.RangeInclusive(hour, Constants.HOUR_START_OF_NIGHT) == Constants.HOUR_START_OF_NIGHT; } else if (hour >= Constants.HOUR_END_OF_NIGHT && hour <= Constants.HOUR_START_OF_DAWN) { moveTowardsCenter = Rand.RangeInclusive(Constants.HOUR_END_OF_NIGHT, hour) == Constants.HOUR_END_OF_NIGHT; } if (moveTowardsCenter) { var center = zombie.wanderDestination.IsValid ? zombie.wanderDestination : zombie.Map.Center; possibleMoves.Sort((p1, p2) => p1.DistanceToSquared(center).CompareTo(p2.DistanceToSquared(center))); possibleMoves = possibleMoves.Take(Constants.NUMBER_OF_TOP_MOVEMENT_PICKS).ToList(); possibleMoves = possibleMoves.OrderBy(p => grid.GetZombieCount(p)).ToList(); driver.destination = possibleMoves.First(); return; } } // random wandering var n = possibleMoves.Count(); driver.destination = possibleMoves[Constants.random.Next(n)]; }
public static IEnumerable <Rule> ExtraRules() { Pawn initiator = DialogManager.Initiator; if (initiator == null) { yield break; } //pawn parameters if (PawnCheck()) { Pawn recipient = DialogManager.Recipient; string initPrefix = "INITIATOR_", reciPrefix = "RECIPIENT_"; foreach (var rule in ExtraRulesForPawn(initPrefix, initiator, recipient)) { yield return(rule); } foreach (var rule in ExtraRulesForPawn(reciPrefix, recipient, initiator)) { yield return(rule); } } //climate yield return(new Rule_String("WEATHER", initiator.Map.weatherManager.CurWeatherPerceived.label)); //time yield return(new Rule_String("HOUR", GenLocalDate.HourInteger(initiator).ToString())); yield return(new Rule_String("DAYPERIOD", DayPeriod(initiator))); //temperature yield return(new Rule_String("TEMPERATURE", GenTemperature.GetTemperatureForCell(initiator.Position, initiator.Map).ToString())); //outdoor? yield return(new Rule_String("OUTDOORS", initiator.Position.UsesOutdoorTemperature(initiator.Map).ToStringYesNo())); //nearest things foreach (var group in subjects) { var thing = GenClosest.ClosestThing_Global(initiator.Position, initiator.Map.listerThings.ThingsInGroup(group), lookRadius); if (thing != null) { yield return(new Rule_String($"NEAREST_{group.ToString().ToLower()}", $"{thing.def.label}")); } } }
private string getTideLevel() { if (this.map.gameConditionManager.ConditionIsActive(GameConditionDefOf.Eclipse)) { return("high"); } else if (GenLocalDate.HourOfDay(this.map) > 4 && GenLocalDate.HourOfDay(this.map) < 8) { return("low"); } else if (GenLocalDate.HourOfDay(this.map) > 15 && GenLocalDate.HourOfDay(this.map) < 20) { return("high"); } return("normal"); }
public override bool CanSpawn(Map affectedMap) { if (Current.Game.Maps.Count == 0) { return(false); } Map map = Current.Game.Maps[0]; if (GenLocalDate.HourInteger(map) >= MinHours && GenLocalDate.HourInteger(map) <= MaxHours) { return(true); } return(false); }
private static void ClearYesterdaysSkillValues(Pawn pawn) { // This gets the day of the year in the pawn's local time, which is important because the daily XP reset is // done by using midnight in the pawn's local time. See Pawn_SkillTracker::SkillsTick() // Here the day is used instead of the hour because it is not guaranteed that the job will be checked every hour, or even every day. int dayOfYear = GenLocalDate.DayOfYear(pawn); if (PawnMeleeSkillValues.ContainsKey(pawn.ThingID) && PawnMeleeSkillValues[pawn.ThingID].DayOfYear != dayOfYear) { PawnMeleeSkillValues.Remove(pawn.ThingID); } if (PawnShootingSkillValues.ContainsKey(pawn.ThingID) && PawnShootingSkillValues[pawn.ThingID].DayOfYear != dayOfYear) { PawnShootingSkillValues.Remove(pawn.ThingID); } }
public static int GetPriority(this Pawn pawn, WorkGiverDef workgiver, int hour) { if (hour < 0) { hour = GenLocalDate.HourOfDay(pawn); } Logger.Trace($"Getting {pawn.LabelShort}'s {workgiver.defName} priority for {hour}"); if (Find.PlaySettings.useWorkPriorities) { return(PriorityManager.Get[pawn][workgiver][hour]); } // or in simple mode, 3 or 0 return(PriorityManager.Get[pawn][workgiver][hour] > 0 ? 3 : 0); }