private Job TakeDownedToBedJob(Pawn prisoner, Pawn warden) { if (prisoner.Downed && HealthAIUtility.ShouldSeekMedicalRestUrgent(prisoner) && !prisoner.InBed() && warden.CanReserve(prisoner, 1, -1, null, false)) { Building_Bed building_Bed = RestUtility.FindBedFor(prisoner, warden, true, true, false); if (building_Bed != null) { Job job = new Job(JobDefOf.TakeWoundedPrisonerToBed, prisoner, building_Bed); job.count = 1; return(job); } return(null); } return(null); }
internal void <> m__0() { Pawn actor = this.gotoBed.actor; Building_Bed bed = (Building_Bed)actor.CurJob.GetTarget(this.bedIndex).Thing; IntVec3 bedSleepingSlotPosFor = RestUtility.GetBedSleepingSlotPosFor(actor, bed); if (actor.Position == bedSleepingSlotPosFor) { actor.jobs.curDriver.ReadyForNextToil(); } else { actor.pather.StartPath(bedSleepingSlotPosFor, PathEndMode.OnCell); } }
public static bool InBedOrRestSpotNow(Pawn pawn, LocalTargetInfo bedOrRestSpot) { if (!bedOrRestSpot.IsValid || !pawn.Spawned) { return(false); } if (bedOrRestSpot.HasThing) { if (bedOrRestSpot.Thing.Map != pawn.Map) { return(false); } return(RestUtility.GetBedSleepingSlotPosFor(pawn, (Building_Bed)bedOrRestSpot.Thing) == pawn.Position); } return(bedOrRestSpot.Cell == pawn.Position); }
private Job TakeDownedToBedJob(Pawn prisoner, Pawn warden) { if (!prisoner.Downed || !HealthAIUtility.ShouldSeekMedicalRestUrgent(prisoner) || prisoner.InBed() || !warden.CanReserve(prisoner)) { return(null); } Building_Bed building_Bed = RestUtility.FindBedFor(prisoner, warden, sleeperWillBePrisoner: true, checkSocialProperness: true); if (building_Bed != null) { Job job = JobMaker.MakeJob(JobDefOf.TakeWoundedPrisonerToBed, prisoner, building_Bed); job.count = 1; return(job); } return(null); }
private Job TakeDownedToBedJob(Pawn prisoner, Pawn warden) { if (!prisoner.Downed || !HealthAIUtility.ShouldSeekMedicalRestUrgent(prisoner) || prisoner.InBed() || !warden.CanReserve(prisoner, 1, -1, null, false)) { return(null); } Building_Bed building_Bed = RestUtility.FindBedFor(prisoner, warden, true, true, false); if (building_Bed != null) { return(new Job(JobDefOf.TakeWoundedPrisonerToBed, prisoner, building_Bed) { count = 1 }); } return(null); }
public static bool InBedOrRestSpotNow(Pawn pawn, LocalTargetInfo bedOrRestSpot) { bool result; if (!bedOrRestSpot.IsValid || !pawn.Spawned) { result = false; } else if (bedOrRestSpot.HasThing) { result = (bedOrRestSpot.Thing.Map == pawn.Map && RestUtility.GetBedSleepingSlotPosFor(pawn, (Building_Bed)bedOrRestSpot.Thing) == pawn.Position); } else { result = (bedOrRestSpot.Cell == pawn.Position); } return(result); }
private Job TakeToPreferredBedJob(Pawn prisoner, Pawn warden) { if (!prisoner.Downed && warden.CanReserve(prisoner, 1, -1, null, false)) { if (RestUtility.FindBedFor(prisoner, prisoner, true, true, false) != null) { return(null); } Room room = prisoner.GetRoom(RegionType.Set_Passable); Building_Bed building_Bed = RestUtility.FindBedFor(prisoner, warden, true, false, false); if (building_Bed != null && building_Bed.GetRoom(RegionType.Set_Passable) != room) { Job job = new Job(JobDefOf.EscortPrisonerToBed, prisoner, building_Bed); job.count = 1; return(job); } return(null); } return(null); }
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); } Lord lord = pawn.GetLord(); Building_Bed building_Bed = (((lord == null || lord.CurLordToil == null || lord.CurLordToil.AllowRestingInBed) && !pawn.IsWildMan()) ? RestUtility.FindBedFor(pawn) : null); if (building_Bed != null) { return(JobMaker.MakeJob(JobDefOf.LayDown, building_Bed)); } return(JobMaker.MakeJob(JobDefOf.LayDown, FindGroundSleepSpotFor(pawn))); }
private Job TakeToPreferredBedJob(Pawn prisoner, Pawn warden) { if (prisoner.Downed || !warden.CanReserve(prisoner)) { return(null); } if (RestUtility.FindBedFor(prisoner, prisoner, sleeperWillBePrisoner: true, checkSocialProperness: true) != null) { return(null); } Room room = prisoner.GetRoom(); Building_Bed building_Bed = RestUtility.FindBedFor(prisoner, warden, sleeperWillBePrisoner: true, checkSocialProperness: false); if (building_Bed != null && building_Bed.GetRoom() != room) { Job job = JobMaker.MakeJob(JobDefOf.EscortPrisonerToBed, prisoner, building_Bed); job.count = 1; return(job); } return(null); }
public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams) { if (!HealthAIUtility.ShouldSeekMedicalRest(pawn)) { return(ThinkResult.NoJob); } if (respectTimetable && RestUtility.TimetablePreventsLayDown(pawn) && !HealthAIUtility.ShouldHaveSurgeryDoneNow(pawn) && !HealthAIUtility.ShouldBeTendedNowByPlayer(pawn)) { return(ThinkResult.NoJob); } if (RestUtility.DisturbancePreventsLyingDown(pawn)) { return(ThinkResult.NoJob); } Thing thing = RestUtility.FindPatientBedFor(pawn); if (thing == null) { return(ThinkResult.NoJob); } return(new ThinkResult(JobMaker.MakeJob(JobDefOf.LayDown, thing), this)); }
public static Building_Bed FindPatientBedFor(Pawn pawn) { Predicate <Thing> medBedValidator = delegate(Thing t) { Building_Bed building_Bed2 = t as Building_Bed; return(building_Bed2 != null && (building_Bed2.Medical || !building_Bed2.def.building.bed_humanlike) && RestUtility.IsValidBedFor(building_Bed2, pawn, pawn, pawn.IsPrisoner, false, true, false)); }; if (pawn.InBed() && medBedValidator(pawn.CurrentBed())) { return(pawn.CurrentBed()); } for (int i = 0; i < 2; i++) { Danger maxDanger = (i != 0) ? Danger.Deadly : Danger.None; Building_Bed building_Bed = (Building_Bed)GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial), PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, (Thing b) => b.Position.GetDangerFor(pawn, pawn.Map) <= maxDanger && medBedValidator(b), null, 0, -1, false, RegionType.Set_Passable, false); if (building_Bed != null) { return(building_Bed); } } return(RestUtility.FindBedFor(pawn)); }
protected override Job TryGiveJob(Pawn pawn) { Need_Rest rest = pawn.needs.rest; Job result; if (rest == null || rest.CurCategory < this.minCategory) { result = null; } else if (RestUtility.DisturbancePreventsLyingDown(pawn)) { result = null; } else { Lord lord = pawn.GetLord(); Building_Bed building_Bed; if ((lord != null && lord.CurLordToil != null && !lord.CurLordToil.AllowRestingInBed) || pawn.IsWildMan()) { building_Bed = null; } else { building_Bed = RestUtility.FindBedFor(pawn); } if (building_Bed != null) { Job job = new Job(JobDefOf.LayDown, building_Bed); result = job; } else { result = new Job(JobDefOf.LayDown, this.FindGroundSleepSpotFor(pawn)); } } return(result); }
protected override Job TryGiveJob(Pawn pawn) { Need_Rest rest = pawn.needs.rest; Building_Bed building_Bed; if (rest != null && (int)rest.CurCategory >= (int)this.minCategory) { if (RestUtility.DisturbancePreventsLyingDown(pawn)) { return(null); } Lord lord = pawn.GetLord(); if (lord != null && lord.CurLordToil != null && !lord.CurLordToil.AllowRestingInBed) { goto IL_0065; } if (pawn.IsWildMan()) { goto IL_0065; } building_Bed = RestUtility.FindBedFor(pawn); goto IL_0073; } return(null); IL_0073: if (building_Bed != null) { return(new Job(JobDefOf.LayDown, building_Bed)); } return(new Job(JobDefOf.LayDown, this.FindGroundSleepSpotFor(pawn))); IL_0065: building_Bed = null; goto IL_0073; }
protected override Job TryGiveJob(Pawn pawn) { Predicate <Thing> validator = delegate(Thing t) { Pawn pawn3 = (Pawn)t; return(pawn3.Downed && pawn3.Faction == pawn.Faction && !pawn3.InBed() && pawn.CanReserve(pawn3, 1, -1, null, false) && !pawn3.IsForbidden(pawn) && !GenAI.EnemyIsNear(pawn3, 25f)); }; Pawn pawn2 = (Pawn)GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.Pawn), PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), this.radius, validator, null, 0, -1, false, RegionType.Set_Passable, false); if (pawn2 == null) { return(null); } Building_Bed building_Bed = RestUtility.FindBedFor(pawn2, pawn, pawn2.HostFaction == pawn.Faction, false, false); if (building_Bed == null || !pawn2.CanReserve(building_Bed, 1, -1, null, false)) { return(null); } return(new Job(JobDefOf.Rescue, pawn2, building_Bed) { count = 1 }); }
protected override Job TryGiveJob(Pawn pawn) { Predicate <Thing> validator = delegate(Thing t) { Pawn pawn3 = (Pawn)t; return((pawn3.Downed && pawn3.Faction == pawn.Faction && !pawn3.InBed() && pawn.CanReserve(pawn3) && !pawn3.IsForbidden(pawn) && !GenAI.EnemyIsNear(pawn3, 25f)) ? true : false); }; Pawn pawn2 = (Pawn)GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.Pawn), PathEndMode.OnCell, TraverseParms.For(pawn), radius, validator); if (pawn2 == null) { return(null); } Building_Bed building_Bed = RestUtility.FindBedFor(pawn2, pawn, pawn2.HostFaction == pawn.Faction, checkSocialProperness: false); if (building_Bed == null || !pawn2.CanReserve(building_Bed)) { return(null); } Job job = JobMaker.MakeJob(JobDefOf.Rescue, pawn2, building_Bed); job.count = 1; return(job); }
public static bool IsValidBedFor(Thing bedThing, Pawn sleeper, Pawn traveler, bool sleeperWillBePrisoner, bool checkSocialProperness, bool allowMedBedEvenIfSetToNoCare = false, bool ignoreOtherReservations = false) { Building_Bed building_Bed = bedThing as Building_Bed; if (building_Bed == null) { return(false); } LocalTargetInfo target = building_Bed; PathEndMode peMode = PathEndMode.OnCell; Danger maxDanger = Danger.Some; int sleepingSlotsCount = building_Bed.SleepingSlotsCount; if (!traveler.CanReserveAndReach(target, peMode, maxDanger, sleepingSlotsCount, -1, null, ignoreOtherReservations)) { return(false); } if (!RestUtility.CanUseBedEver(sleeper, building_Bed.def)) { return(false); } if (!building_Bed.AnyUnoccupiedSleepingSlot && (!sleeper.InBed() || sleeper.CurrentBed() != building_Bed) && !building_Bed.AssignedPawns.Contains(sleeper)) { return(false); } if (building_Bed.IsForbidden(traveler)) { return(false); } if (checkSocialProperness && !building_Bed.IsSociallyProper(sleeper, sleeperWillBePrisoner, false)) { return(false); } if (building_Bed.IsBurning()) { return(false); } if (sleeperWillBePrisoner) { if (!building_Bed.ForPrisoners) { return(false); } if (!building_Bed.Position.IsInPrisonCell(building_Bed.Map)) { return(false); } } else { if (building_Bed.Faction != traveler.Faction) { return(false); } if (building_Bed.ForPrisoners) { return(false); } } if (building_Bed.Medical) { if (!allowMedBedEvenIfSetToNoCare && !HealthAIUtility.ShouldEverReceiveMedicalCare(sleeper)) { return(false); } if (!HealthAIUtility.ShouldSeekMedicalRest(sleeper)) { return(false); } } else if (building_Bed.owners.Any <Pawn>() && !building_Bed.owners.Contains(sleeper)) { if (sleeper.IsPrisoner || sleeperWillBePrisoner) { if (!building_Bed.AnyUnownedSleepingSlot) { return(false); } } else { if (!RestUtility.IsAnyOwnerLovePartnerOf(building_Bed, sleeper)) { return(false); } if (!building_Bed.AnyUnownedSleepingSlot) { return(false); } } } return(true); }
private static FloatMenuOption GenerateSurgeryOption(Pawn pawn, Thing thingForMedBills, RecipeDef recipe, IEnumerable <ThingDef> missingIngredients, BodyPartRecord part = null) { string text = recipe.Worker.GetLabelWhenUsedOn(pawn, part); if (part != null && !recipe.hideBodyPartNames) { text = text + " (" + part.def.label + ")"; } FloatMenuOption floatMenuOption; if (missingIngredients.Any()) { text += " ("; bool flag = true; foreach (ThingDef missingIngredient in missingIngredients) { if (!flag) { text += ", "; } flag = false; text += "MissingMedicalBillIngredient".Translate(missingIngredient.label); } text += ")"; floatMenuOption = new FloatMenuOption(text, null, MenuOptionPriority.Default, null, null, 0f, null, null); } else { Action action = delegate { Pawn pawn2 = thingForMedBills as Pawn; if (pawn2 != null) { Bill_Medical bill_Medical = new Bill_Medical(recipe); pawn2.BillStack.AddBill(bill_Medical); bill_Medical.Part = part; if (recipe.conceptLearned != null) { PlayerKnowledgeDatabase.KnowledgeDemonstrated(recipe.conceptLearned, KnowledgeAmount.Total); } Map map = thingForMedBills.Map; if (!map.mapPawns.FreeColonists.Any((Pawn col) => recipe.PawnSatisfiesSkillRequirements(col))) { Bill.CreateNoPawnsWithSkillDialog(recipe); } if (!pawn2.InBed() && pawn2.RaceProps.IsFlesh) { if (pawn2.RaceProps.Humanlike) { if (!map.listerBuildings.allBuildingsColonist.Any((Building x) => x is Building_Bed && RestUtility.CanUseBedEver(pawn, x.def) && ((Building_Bed)x).Medical)) { Messages.Message("MessageNoMedicalBeds".Translate(), pawn2, MessageTypeDefOf.CautionInput); } } else if (!map.listerBuildings.allBuildingsColonist.Any((Building x) => x is Building_Bed && RestUtility.CanUseBedEver(pawn, x.def))) { Messages.Message("MessageNoAnimalBeds".Translate(), pawn2, MessageTypeDefOf.CautionInput); } } if (pawn2.Faction != null && !pawn2.Faction.def.hidden && !pawn2.Faction.HostileTo(Faction.OfPlayer) && recipe.Worker.IsViolationOnPawn(pawn2, part, Faction.OfPlayer)) { Messages.Message("MessageMedicalOperationWillAngerFaction".Translate(pawn2.Faction), pawn2, MessageTypeDefOf.CautionInput); } ThingDef minRequiredMedicine = HealthCardUtility.GetMinRequiredMedicine(recipe); if (minRequiredMedicine != null && pawn2.playerSettings != null && !pawn2.playerSettings.medCare.AllowsMedicine(minRequiredMedicine)) { Messages.Message("MessageTooLowMedCare".Translate(minRequiredMedicine.label, pawn2.LabelShort, pawn2.playerSettings.medCare.GetLabel()), pawn2, MessageTypeDefOf.CautionInput); } } }; floatMenuOption = new FloatMenuOption(text, action, MenuOptionPriority.Default, null, null, 0f, null, null); } floatMenuOption.extraPartWidth = 29f; floatMenuOption.extraPartOnGUI = ((Rect rect) => Widgets.InfoCardButton((float)(rect.x + 5.0), (float)(rect.y + (rect.height - 24.0) / 2.0), recipe)); return(floatMenuOption); }
public static Building_Bed FindBedFor(Pawn sleeper, Pawn traveler, bool sleeperWillBePrisoner, bool checkSocialProperness, bool ignoreOtherReservations = false) { if (HealthAIUtility.ShouldSeekMedicalRest(sleeper)) { if (sleeper.InBed() && sleeper.CurrentBed().Medical) { Building_Bed bedThing = sleeper.CurrentBed(); Pawn pawn = sleeper; Pawn pawn2 = traveler; bool flag = sleeperWillBePrisoner; bool checkSocialProperness2 = checkSocialProperness; bool flag2 = ignoreOtherReservations; if (RestUtility.IsValidBedFor(bedThing, pawn, pawn2, flag, checkSocialProperness2, false, flag2)) { return(sleeper.CurrentBed()); } } for (int i = 0; i < RestUtility.bedDefsBestToWorst_Medical.Count; i++) { ThingDef thingDef = RestUtility.bedDefsBestToWorst_Medical[i]; if (RestUtility.CanUseBedEver(sleeper, thingDef)) { for (int j = 0; j < 2; j++) { Danger maxDanger = (j != 0) ? Danger.Deadly : Danger.None; Building_Bed building_Bed = (Building_Bed)GenClosest.ClosestThingReachable(sleeper.Position, sleeper.Map, ThingRequest.ForDef(thingDef), PathEndMode.OnCell, TraverseParms.For(traveler, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, delegate(Thing b) { bool arg_92_0; if (((Building_Bed)b).Medical && b.Position.GetDangerFor(sleeper, sleeper.Map) <= maxDanger) { Pawn sleeper2 = sleeper; Pawn traveler2 = traveler; bool sleeperWillBePrisoner2 = sleeperWillBePrisoner; bool checkSocialProperness3 = checkSocialProperness; bool ignoreOtherReservations2 = ignoreOtherReservations; arg_92_0 = RestUtility.IsValidBedFor(b, sleeper2, traveler2, sleeperWillBePrisoner2, checkSocialProperness3, false, ignoreOtherReservations2); } else { arg_92_0 = false; } return(arg_92_0); }, null, 0, -1, false, RegionType.Set_Passable, false); if (building_Bed != null) { return(building_Bed); } } } } } if (sleeper.ownership != null && sleeper.ownership.OwnedBed != null) { Building_Bed bedThing = sleeper.ownership.OwnedBed; Pawn pawn2 = sleeper; Pawn pawn = traveler; bool flag2 = sleeperWillBePrisoner; bool checkSocialProperness2 = checkSocialProperness; bool flag = ignoreOtherReservations; if (RestUtility.IsValidBedFor(bedThing, pawn2, pawn, flag2, checkSocialProperness2, false, flag)) { return(sleeper.ownership.OwnedBed); } } DirectPawnRelation directPawnRelation = LovePartnerRelationUtility.ExistingMostLikedLovePartnerRel(sleeper, false); if (directPawnRelation != null) { Building_Bed ownedBed = directPawnRelation.otherPawn.ownership.OwnedBed; if (ownedBed != null) { Building_Bed bedThing = ownedBed; Pawn pawn = sleeper; Pawn pawn2 = traveler; bool flag = sleeperWillBePrisoner; bool checkSocialProperness2 = checkSocialProperness; bool flag2 = ignoreOtherReservations; if (RestUtility.IsValidBedFor(bedThing, pawn, pawn2, flag, checkSocialProperness2, false, flag2)) { return(ownedBed); } } } for (int k = 0; k < 2; k++) { Danger maxDanger = (k != 0) ? Danger.Deadly : Danger.None; for (int l = 0; l < RestUtility.bedDefsBestToWorst_RestEffectiveness.Count; l++) { ThingDef thingDef2 = RestUtility.bedDefsBestToWorst_RestEffectiveness[l]; if (RestUtility.CanUseBedEver(sleeper, thingDef2)) { Building_Bed building_Bed2 = (Building_Bed)GenClosest.ClosestThingReachable(sleeper.Position, sleeper.Map, ThingRequest.ForDef(thingDef2), PathEndMode.OnCell, TraverseParms.For(traveler, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, delegate(Thing b) { bool arg_92_0; if (!((Building_Bed)b).Medical && b.Position.GetDangerFor(sleeper, sleeper.Map) <= maxDanger) { Pawn sleeper2 = sleeper; Pawn traveler2 = traveler; bool sleeperWillBePrisoner2 = sleeperWillBePrisoner; bool checkSocialProperness3 = checkSocialProperness; bool ignoreOtherReservations2 = ignoreOtherReservations; arg_92_0 = RestUtility.IsValidBedFor(b, sleeper2, traveler2, sleeperWillBePrisoner2, checkSocialProperness3, false, ignoreOtherReservations2); } else { arg_92_0 = false; } return(arg_92_0); }, null, 0, -1, false, RegionType.Set_Passable, false); if (building_Bed2 != null) { return(building_Bed2); } } } } return(null); }
public static Building_Bed FindBedFor(Pawn p) { return(RestUtility.FindBedFor(p, p, p.IsPrisoner, true, false)); }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(TargetIndex.A); this.FailOnDestroyedOrNull(TargetIndex.B); this.FailOnAggroMentalStateAndHostile(TargetIndex.A); this.FailOn(delegate() { if (this.job.def.makeTargetPrisoner) { if (!this.DropBed.ForPrisoners) { return(true); } } else if (this.DropBed.ForPrisoners != this.Takee.IsPrisoner) { return(true); } return(false); }); yield return(Toils_Bed.ClaimBedIfNonMedical(TargetIndex.B, TargetIndex.A)); base.AddFinishAction(delegate { if (this.job.def.makeTargetPrisoner && this.Takee.ownership.OwnedBed == this.DropBed && this.Takee.Position != RestUtility.GetBedSleepingSlotPosFor(this.Takee, this.DropBed)) { this.Takee.ownership.UnclaimBed(); } }); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A).FailOnDespawnedNullOrForbidden(TargetIndex.B).FailOn(() => this.job.def == JobDefOf.Arrest && !this.Takee.CanBeArrestedBy(this.pawn)).FailOn(() => !this.pawn.CanReach(this.DropBed, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)).FailOn(() => this.job.def == JobDefOf.Rescue && !this.Takee.Downed).FailOnSomeonePhysicallyInteracting(TargetIndex.A)); yield return(new Toil { initAction = delegate() { if (this.job.def.makeTargetPrisoner) { Pawn pawn = (Pawn)this.job.targetA.Thing; Lord lord = pawn.GetLord(); if (lord != null) { lord.Notify_PawnAttemptArrested(pawn); } GenClamor.DoClamor(pawn, 10f, ClamorDefOf.Harm); if (this.job.def == JobDefOf.Arrest && !pawn.CheckAcceptArrest(this.pawn)) { this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true); } } } }); Toil startCarrying = Toils_Haul.StartCarryThing(TargetIndex.A, false, false, false).FailOnNonMedicalBedNotOwned(TargetIndex.B, TargetIndex.A); startCarrying.AddPreInitAction(new Action(this.CheckMakeTakeeGuest)); yield return(startCarrying); yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch)); yield return(new Toil { initAction = delegate() { this.CheckMakeTakeePrisoner(); if (this.Takee.playerSettings == null) { this.Takee.playerSettings = new Pawn_PlayerSettings(this.Takee); } } }); yield return(Toils_Reserve.Release(TargetIndex.B)); yield return(new Toil { initAction = delegate() { IntVec3 position = this.DropBed.Position; Thing thing; this.pawn.carryTracker.TryDropCarriedThing(position, ThingPlaceMode.Direct, out thing, null); if (!this.DropBed.Destroyed && (this.DropBed.owners.Contains(this.Takee) || (this.DropBed.Medical && this.DropBed.AnyUnoccupiedSleepingSlot) || this.Takee.ownership == null)) { this.Takee.jobs.Notify_TuckedIntoBed(this.DropBed); if (this.Takee.RaceProps.Humanlike && this.job.def != JobDefOf.Arrest && !this.Takee.IsPrisonerOfColony) { this.Takee.relations.Notify_RescuedBy(this.pawn); } this.Takee.mindState.Notify_TuckedIntoBed(); } if (this.Takee.IsPrisonerOfColony) { LessonAutoActivator.TeachOpportunity(ConceptDefOf.PrisonerTab, this.Takee, OpportunityType.GoodToKnow); } }, defaultCompleteMode = ToilCompleteMode.Instant }); yield break; }
public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; switch (num) { case 0u: this.FailOnDestroyedOrNull(TargetIndex.A); this.FailOnDestroyedOrNull(TargetIndex.B); this.FailOnAggroMentalStateAndHostile(TargetIndex.A); this.FailOn(delegate() { if (this.job.def.makeTargetPrisoner) { if (!base.DropBed.ForPrisoners) { return(true); } } else if (base.DropBed.ForPrisoners != base.Takee.IsPrisoner) { return(true); } return(false); }); this.$current = Toils_Bed.ClaimBedIfNonMedical(TargetIndex.B, TargetIndex.A); if (!this.$disposing) { this.$PC = 1; } return(true); case 1u: base.AddFinishAction(delegate { if (this.job.def.makeTargetPrisoner && base.Takee.ownership.OwnedBed == base.DropBed && base.Takee.Position != RestUtility.GetBedSleepingSlotPosFor(base.Takee, base.DropBed)) { base.Takee.ownership.UnclaimBed(); } }); this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A).FailOnDespawnedNullOrForbidden(TargetIndex.B).FailOn(() => this.job.def == JobDefOf.Arrest && !base.Takee.CanBeArrestedBy(this.pawn)).FailOn(() => !this.pawn.CanReach(base.DropBed, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)).FailOn(() => this.job.def == JobDefOf.Rescue && !base.Takee.Downed).FailOnSomeonePhysicallyInteracting(TargetIndex.A); if (!this.$disposing) { this.$PC = 2; } return(true); case 2u: { Toil checkArrestResistance = new Toil(); checkArrestResistance.initAction = delegate() { if (this.job.def.makeTargetPrisoner) { Pawn pawn = (Pawn)this.job.targetA.Thing; Lord lord = pawn.GetLord(); if (lord != null) { lord.Notify_PawnAttemptArrested(pawn); } GenClamor.DoClamor(pawn, 10f, ClamorDefOf.Harm); if (this.job.def == JobDefOf.Arrest && !pawn.CheckAcceptArrest(this.pawn)) { this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true); } } }; this.$current = checkArrestResistance; if (!this.$disposing) { this.$PC = 3; } return(true); } case 3u: startCarrying = Toils_Haul.StartCarryThing(TargetIndex.A, false, false, false).FailOnNonMedicalBedNotOwned(TargetIndex.B, TargetIndex.A); startCarrying.AddPreInitAction(new Action(base.CheckMakeTakeeGuest)); this.$current = startCarrying; if (!this.$disposing) { this.$PC = 4; } return(true); case 4u: this.$current = Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch); if (!this.$disposing) { this.$PC = 5; } return(true); case 5u: { Toil makePrisonerAndInit = new Toil(); makePrisonerAndInit.initAction = delegate() { base.CheckMakeTakeePrisoner(); if (base.Takee.playerSettings == null) { base.Takee.playerSettings = new Pawn_PlayerSettings(base.Takee); } }; this.$current = makePrisonerAndInit; if (!this.$disposing) { this.$PC = 6; } return(true); } case 6u: this.$current = Toils_Reserve.Release(TargetIndex.B); if (!this.$disposing) { this.$PC = 7; } return(true); case 7u: { Toil tuckIntoBed = new Toil(); tuckIntoBed.initAction = delegate() { IntVec3 position = base.DropBed.Position; Thing thing; this.pawn.carryTracker.TryDropCarriedThing(position, ThingPlaceMode.Direct, out thing, null); if (!base.DropBed.Destroyed && (base.DropBed.owners.Contains(base.Takee) || (base.DropBed.Medical && base.DropBed.AnyUnoccupiedSleepingSlot) || base.Takee.ownership == null)) { base.Takee.jobs.Notify_TuckedIntoBed(base.DropBed); if (base.Takee.RaceProps.Humanlike && this.job.def != JobDefOf.Arrest && !base.Takee.IsPrisonerOfColony) { base.Takee.relations.Notify_RescuedBy(this.pawn); } base.Takee.mindState.Notify_TuckedIntoBed(); } if (base.Takee.IsPrisonerOfColony) { LessonAutoActivator.TeachOpportunity(ConceptDefOf.PrisonerTab, base.Takee, OpportunityType.GoodToKnow); } }; tuckIntoBed.defaultCompleteMode = ToilCompleteMode.Instant; this.$current = tuckIntoBed; if (!this.$disposing) { this.$PC = 8; } return(true); } case 8u: this.$PC = -1; break; } return(false); }
public static Toil LayDown(TargetIndex bedOrRestSpotIndex, bool hasBed, bool lookForOtherJobs, bool canSleep = true, bool gainRestAndHealth = true) { Toil layDown = new Toil(); layDown.initAction = delegate { Pawn actor = layDown.actor; actor.pather.StopDead(); JobDriver curDriver = actor.jobs.curDriver; if (hasBed) { Building_Bed t = (Building_Bed)actor.CurJob.GetTarget(bedOrRestSpotIndex).Thing; if (!t.OccupiedRect().Contains(actor.Position)) { Log.Error("Can't start LayDown toil because pawn is not in the bed. pawn=" + actor); actor.jobs.EndCurrentJob(JobCondition.Errored, true); return; } curDriver.layingDown = LayingDownState.LayingInBed; } else { curDriver.layingDown = LayingDownState.LayingSurface; } curDriver.asleep = false; if (actor.mindState.applyBedThoughtsTick == 0) { actor.mindState.applyBedThoughtsTick = Find.TickManager.TicksGame + Rand.Range(2500, 10000); actor.mindState.applyBedThoughtsOnLeave = false; } if (actor.ownership != null && actor.CurrentBed() != actor.ownership.OwnedBed) { ThoughtUtility.RemovePositiveBedroomThoughts(actor); } }; layDown.tickAction = delegate { Pawn actor = layDown.actor; Job curJob = actor.CurJob; JobDriver curDriver = actor.jobs.curDriver; Building_Bed building_Bed = (Building_Bed)curJob.GetTarget(bedOrRestSpotIndex).Thing; actor.GainComfortFromCellIfPossible(); if (!curDriver.asleep) { if (canSleep && ((actor.needs.rest != null && actor.needs.rest.CurLevel < RestUtility.FallAsleepMaxLevel(actor)) || curJob.forceSleep)) { curDriver.asleep = true; } } else if (!canSleep) { curDriver.asleep = false; } else if ((actor.needs.rest == null || actor.needs.rest.CurLevel >= RestUtility.WakeThreshold(actor)) && !curJob.forceSleep) { curDriver.asleep = false; } if (curDriver.asleep && gainRestAndHealth && actor.needs.rest != null) { float num; if (building_Bed != null && building_Bed.def.statBases.StatListContains(StatDefOf.BedRestEffectiveness)) { num = building_Bed.GetStatValue(StatDefOf.BedRestEffectiveness, true); } else { num = 0.8f; } float num2 = RestUtility.PawnHealthRestEffectivenessFactor(actor); num = 0.7f * num + 0.3f * num * num2; actor.needs.rest.TickResting(num); } if (actor.mindState.applyBedThoughtsTick != 0 && actor.mindState.applyBedThoughtsTick <= Find.TickManager.TicksGame) { Toils_LayDown.ApplyBedThoughts(actor); actor.mindState.applyBedThoughtsTick += 60000; actor.mindState.applyBedThoughtsOnLeave = true; } if (actor.IsHashIntervalTick(100) && !actor.Position.Fogged(actor.Map)) { if (curDriver.asleep) { MoteMaker.ThrowMetaIcon(actor.Position, actor.Map, ThingDefOf.Mote_SleepZ); } if (gainRestAndHealth && actor.health.hediffSet.GetNaturallyHealingInjuredParts().Any <BodyPartRecord>()) { MoteMaker.ThrowMetaIcon(actor.Position, actor.Map, ThingDefOf.Mote_HealingCross); } } if (actor.ownership != null && building_Bed != null && !building_Bed.Medical && !building_Bed.owners.Contains(actor)) { if (actor.Downed) { actor.Position = CellFinder.RandomClosewalkCellNear(actor.Position, actor.Map, 1, null); } actor.jobs.EndCurrentJob(JobCondition.Incompletable, true); return; } if (lookForOtherJobs && actor.IsHashIntervalTick(211)) { actor.jobs.CheckForJobOverride(); return; } }; layDown.defaultCompleteMode = ToilCompleteMode.Never; if (hasBed) { layDown.FailOnBedNoLongerUsable(bedOrRestSpotIndex); } layDown.AddFinishAction(delegate { Pawn actor = layDown.actor; JobDriver curDriver = actor.jobs.curDriver; if (actor.mindState.applyBedThoughtsOnLeave) { Toils_LayDown.ApplyBedThoughts(actor); } curDriver.layingDown = LayingDownState.NotLaying; curDriver.asleep = false; }); return(layDown); }
public override void NeedInterval() { if (!base.IsFrozen) { if (this.Resting) { float num = this.lastRestEffectiveness; float num2 = RestUtility.PawnHealthRestEffectivenessFactor(this.pawn); num = 0.7f * num + 0.3f * num * num2; num *= this.pawn.GetStatValue(StatDefOf.RestRateMultiplier, true); if (num > 0f) { this.CurLevel += 0.00571428565f * num; } } else { this.CurLevel -= this.RestFallPerTick * 150f; } } if (this.CurLevel < 0.0001f) { this.ticksAtZero += 150; } else { this.ticksAtZero = 0; } if (this.ticksAtZero > 1000 && this.pawn.Spawned) { float mtb; if (this.ticksAtZero < 15000) { mtb = 0.25f; } else if (this.ticksAtZero < 30000) { mtb = 0.125f; } else if (this.ticksAtZero < 45000) { mtb = 0.0833333358f; } else { mtb = 0.0625f; } if (Rand.MTBEventOccurs(mtb, 60000f, 150f) && (this.pawn.CurJob == null || this.pawn.CurJob.def != JobDefOf.LayDown)) { this.pawn.jobs.StartJob(new Job(JobDefOf.LayDown, this.pawn.Position), JobCondition.InterruptForced, null, false, true, null, new JobTag?(JobTag.SatisfyingNeeds), false); if (this.pawn.InMentalState) { this.pawn.mindState.mentalStateHandler.CurState.RecoverFromState(); } if (PawnUtility.ShouldSendNotificationAbout(this.pawn)) { Messages.Message("MessageInvoluntarySleep".Translate(new object[] { this.pawn.LabelShort }), this.pawn, MessageTypeDefOf.NegativeEvent, true); } TaleRecorder.RecordTale(TaleDefOf.Exhausted, new object[] { this.pawn }); } } }
private static void CreateSurgeryBill(Pawn medPawn, RecipeDef recipe, BodyPartRecord part) { Bill_Medical bill_Medical = new Bill_Medical(recipe); medPawn.BillStack.AddBill(bill_Medical); bill_Medical.Part = part; if (recipe.conceptLearned != null) { PlayerKnowledgeDatabase.KnowledgeDemonstrated(recipe.conceptLearned, KnowledgeAmount.Total); } Map map = medPawn.Map; if (!map.mapPawns.FreeColonists.Any((Pawn col) => recipe.PawnSatisfiesSkillRequirements(col))) { Bill.CreateNoPawnsWithSkillDialog(recipe); } if (!medPawn.InBed() && medPawn.RaceProps.IsFlesh) { if (medPawn.RaceProps.Humanlike) { if (!map.listerBuildings.allBuildingsColonist.Any((Building x) => x is Building_Bed && RestUtility.CanUseBedEver(medPawn, x.def) && ((Building_Bed)x).Medical)) { Messages.Message("MessageNoMedicalBeds".Translate(), medPawn, MessageTypeDefOf.CautionInput, historical: false); } } else if (!map.listerBuildings.allBuildingsColonist.Any((Building x) => x is Building_Bed && RestUtility.CanUseBedEver(medPawn, x.def))) { Messages.Message("MessageNoAnimalBeds".Translate(), medPawn, MessageTypeDefOf.CautionInput, historical: false); } } if (medPawn.Faction != null && !medPawn.Faction.Hidden && !medPawn.Faction.HostileTo(Faction.OfPlayer) && recipe.Worker.IsViolationOnPawn(medPawn, part, Faction.OfPlayer)) { Messages.Message("MessageMedicalOperationWillAngerFaction".Translate(medPawn.FactionOrExtraMiniOrHomeFaction), medPawn, MessageTypeDefOf.CautionInput, historical: false); } ThingDef minRequiredMedicine = GetMinRequiredMedicine(recipe); if (minRequiredMedicine != null && medPawn.playerSettings != null && !medPawn.playerSettings.medCare.AllowsMedicine(minRequiredMedicine)) { Messages.Message("MessageTooLowMedCare".Translate(minRequiredMedicine.label, medPawn.LabelShort, medPawn.playerSettings.medCare.GetLabel(), medPawn.Named("PAWN")), medPawn, MessageTypeDefOf.CautionInput, historical: false); } recipe.Worker.CheckForWarnings(medPawn); }
public static float FallAsleepMaxLevel(Pawn p) { return(Mathf.Min(0.75f, RestUtility.WakeThreshold(p) - 0.01f)); }
public override float GetPriority(Pawn pawn) { Need_Rest rest = pawn.needs.rest; if (rest == null) { return(0f); } if ((int)rest.CurCategory < (int)minCategory) { return(0f); } if (rest.CurLevelPercentage > maxLevelPercentage) { return(0f); } if (Find.TickManager.TicksGame < pawn.mindState.canSleepTick) { return(0f); } Lord lord = pawn.GetLord(); if (lord != null && !lord.CurLordToil.AllowSatisfyLongNeeds) { return(0f); } TimeAssignmentDef timeAssignmentDef; if (pawn.RaceProps.Humanlike) { timeAssignmentDef = ((pawn.timetable == null) ? TimeAssignmentDefOf.Anything : pawn.timetable.CurrentAssignment); } else { int num = GenLocalDate.HourOfDay(pawn); timeAssignmentDef = ((num >= 7 && num <= 21) ? TimeAssignmentDefOf.Anything : TimeAssignmentDefOf.Sleep); } float curLevel = rest.CurLevel; if (timeAssignmentDef == TimeAssignmentDefOf.Anything) { if (curLevel < 0.3f) { return(8f); } return(0f); } if (timeAssignmentDef == TimeAssignmentDefOf.Work) { return(0f); } if (timeAssignmentDef == TimeAssignmentDefOf.Meditate) { if (curLevel < 0.16f) { return(8f); } return(0f); } if (timeAssignmentDef == TimeAssignmentDefOf.Joy) { if (curLevel < 0.3f) { return(8f); } return(0f); } if (timeAssignmentDef == TimeAssignmentDefOf.Sleep) { if (curLevel < RestUtility.FallAsleepMaxLevel(pawn)) { return(8f); } return(0f); } throw new NotImplementedException(); }
public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn myPawn) { if (myPawn.RaceProps.Humanlike && !this.ForPrisoners && this.Medical && !myPawn.Drafted && base.Faction == Faction.OfPlayer && RestUtility.CanUseBedEver(myPawn, this.def)) { if (!HealthAIUtility.ShouldSeekMedicalRest(myPawn) && !HealthAIUtility.ShouldSeekMedicalRestUrgent(myPawn)) { yield return(new FloatMenuOption("UseMedicalBed".Translate() + " (" + "NotInjured".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else { Action sleep = delegate { if (!this.$this.ForPrisoners && this.$this.Medical && myPawn.CanReserveAndReach(this.$this, PathEndMode.ClosestTouch, Danger.Deadly, this.$this.SleepingSlotsCount, -1, null, true)) { Job job = new Job(JobDefOf.LayDown, this.$this); job.restUntilHealed = true; myPawn.jobs.TryTakeOrderedJob(job, JobTag.Misc); myPawn.mindState.ResetLastDisturbanceTick(); } }; if (this.AnyUnoccupiedSleepingSlot) { yield return(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("UseMedicalBed".Translate(), sleep, MenuOptionPriority.Default, null, null, 0f, null, null), myPawn, this, "ReservedBy")); } else { yield return(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("UseMedicalBed".Translate(), sleep, MenuOptionPriority.Default, null, null, 0f, null, null), myPawn, this, "SomeoneElseSleeping")); } } } }
protected Building_Bed FindBed(Pawn pawn, Pawn patient) { return(RestUtility.FindBedFor(patient, pawn, patient.HostFaction == pawn.Faction, false, false)); }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(TargetIndex.A); this.FailOnDestroyedOrNull(TargetIndex.B); this.FailOnAggroMentalStateAndHostile(TargetIndex.A); this.FailOn(delegate { if (job.def.makeTargetPrisoner) { if (!DropBed.ForPrisoners) { return(true); } } else if (DropBed.ForPrisoners != Takee.IsPrisoner) { return(true); } return(false); }); yield return(Toils_Bed.ClaimBedIfNonMedical(TargetIndex.B, TargetIndex.A)); AddFinishAction(delegate { if (job.def.makeTargetPrisoner && Takee.ownership.OwnedBed == DropBed && Takee.Position != RestUtility.GetBedSleepingSlotPosFor(Takee, DropBed)) { Takee.ownership.UnclaimBed(); } }); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A).FailOnDespawnedNullOrForbidden(TargetIndex.B) .FailOn(() => job.def == JobDefOf.Arrest && !Takee.CanBeArrestedBy(pawn)) .FailOn(() => !pawn.CanReach(DropBed, PathEndMode.OnCell, Danger.Deadly)) .FailOn(() => (job.def == JobDefOf.Rescue || job.def == JobDefOf.Capture) && !Takee.Downed) .FailOnSomeonePhysicallyInteracting(TargetIndex.A)); Toil toil = new Toil(); toil.initAction = delegate { if (job.def.makeTargetPrisoner) { Pawn pawn = (Pawn)job.targetA.Thing; pawn.GetLord()?.Notify_PawnAttemptArrested(pawn); GenClamor.DoClamor(pawn, 10f, ClamorDefOf.Harm); if (job.def == JobDefOf.Arrest && !pawn.CheckAcceptArrest(base.pawn)) { base.pawn.jobs.EndCurrentJob(JobCondition.Incompletable); } if (!pawn.IsPrisoner) { QuestUtility.SendQuestTargetSignals(pawn.questTags, "Arrested", pawn.Named("SUBJECT")); } } }; yield return(toil); Toil toil2 = Toils_Haul.StartCarryThing(TargetIndex.A).FailOnNonMedicalBedNotOwned(TargetIndex.B, TargetIndex.A); toil2.AddPreInitAction(CheckMakeTakeeGuest); yield return(toil2); yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch)); Toil toil3 = new Toil(); toil3.initAction = delegate { CheckMakeTakeePrisoner(); if (Takee.playerSettings == null) { Takee.playerSettings = new Pawn_PlayerSettings(Takee); } }; yield return(toil3); yield return(Toils_Reserve.Release(TargetIndex.B)); Toil toil4 = new Toil(); toil4.initAction = delegate { IntVec3 position = DropBed.Position; pawn.carryTracker.TryDropCarriedThing(position, ThingPlaceMode.Direct, out Thing _); if (!DropBed.Destroyed && (DropBed.OwnersForReading.Contains(Takee) || (DropBed.Medical && DropBed.AnyUnoccupiedSleepingSlot) || Takee.ownership == null)) { Takee.jobs.Notify_TuckedIntoBed(DropBed); if (Takee.RaceProps.Humanlike && job.def != JobDefOf.Arrest && !Takee.IsPrisonerOfColony) { Takee.relations.Notify_RescuedBy(pawn); } Takee.mindState.Notify_TuckedIntoBed(); } if (Takee.IsPrisonerOfColony) { LessonAutoActivator.TeachOpportunity(ConceptDefOf.PrisonerTab, Takee, OpportunityType.GoodToKnow); } }; toil4.defaultCompleteMode = ToilCompleteMode.Instant; yield return(toil4); }
public override float GetPriority(Pawn pawn) { Need_Rest rest = pawn.needs.rest; float result; if (rest == null) { result = 0f; } else if (rest.CurCategory < this.minCategory) { result = 0f; } else if (Find.TickManager.TicksGame < pawn.mindState.canSleepTick) { result = 0f; } else { Lord lord = pawn.GetLord(); if (lord != null && !lord.CurLordToil.AllowSatisfyLongNeeds) { result = 0f; } else { TimeAssignmentDef timeAssignmentDef; if (pawn.RaceProps.Humanlike) { timeAssignmentDef = ((pawn.timetable != null) ? pawn.timetable.CurrentAssignment : TimeAssignmentDefOf.Anything); } else { int num = GenLocalDate.HourOfDay(pawn); if (num < 7 || num > 21) { timeAssignmentDef = TimeAssignmentDefOf.Sleep; } else { timeAssignmentDef = TimeAssignmentDefOf.Anything; } } float curLevel = rest.CurLevel; if (timeAssignmentDef == TimeAssignmentDefOf.Anything) { if (curLevel < 0.3f) { result = 8f; } else { result = 0f; } } else if (timeAssignmentDef == TimeAssignmentDefOf.Work) { result = 0f; } else if (timeAssignmentDef == TimeAssignmentDefOf.Joy) { if (curLevel < 0.3f) { result = 8f; } else { result = 0f; } } else { if (timeAssignmentDef != TimeAssignmentDefOf.Sleep) { throw new NotImplementedException(); } if (curLevel < RestUtility.FallAsleepMaxLevel(pawn)) { result = 8f; } else { result = 0f; } } } } return(result); }