public override void MapComponentTick() { if ((Find.TickManager.TicksGame % 30) != 0) { return; } var pawns = Find.MapPawns.FreeColonists.ToList(); if (pawns.NullOrEmpty()) { return; } // Go through each pawn and see if they are sleeping in their own room // If they are, and no other pawn is in the room, forbid the door until // the pawn wakes up. foreach (var pawn in pawns) { var lockState = LockState.Untouched; var room = pawn.GetRoom(); if ( (room == null) || (room.Owners.Contains <Pawn>(pawn)) ) { // Not in their own private room continue; } // Find any other pawns in the same room if ( (Find.MapPawns.AllPawns.Any(p => ( (p != pawn) && (p.GetRoom() == room) ))) ) { // Not alone in room lockState = LockState.WantUnlock; } else if ( (pawn.CurrentBed() != null) && (!HealthUtility.PawnShouldGetImmediateTending(pawn)) && (pawn.needs.food.CurCategory < HungerCategory.UrgentlyHungry) && (pawn.needs.joy.CurCategory > JoyCategory.Low) ) { // In bed, // Not needing doctors care, // Not urgently hungry // Not joy deprived lockState = LockState.WantLock; } else if ( (pawn.CurJob != null) && (pawn.CurJob.def.driverClass == typeof(JobDriver_RelaxAlone)) ) { // Doing something that want's privacy lockState = LockState.WantLock; } else { // Pawn is awake and not doing anything they want privacy for lockState = LockState.WantUnlock; } if (lockState == LockState.WantUnlock) { // Unlock room SetRoomDoors(room, false); } else if (lockState == LockState.WantLock) { // Lock room SetRoomDoors(room, true); } } }