private bool ShouldStartEscaping( Pawn pawn ) { if( ( !pawn.guest.IsPrisoner )|| ( pawn.guest.HostFaction != Faction.OfPlayer )|| ( pawn.guest.PrisonerIsSecure ) ) { return false; } // Compare pawn mood to visibility to colonists and cameras var breakOdds = pawn.EscapeProbability(); if( pawn.needs.mood.CurLevel > breakOdds ) { // Pawn is happy enough not to chance it return false; } var room = pawn.GetRoom(); if( room.TouchesMapEdge ) { // Pawn is outside return true; } // Try to find an exit path var root = room.Regions[ 0 ]; var exitFound = false; RegionTraverser.BreadthFirstTraverse( root, (from,to) => { if( to.portal == null ) { return true; } return ( ( to.portal.FreePassage )|| ( to.portal.PawnCanOpen( pawn) ) ); }, (reg) => { if( !reg.Room.TouchesMapEdge ) { return false; } exitFound = true; return true; }, MaxRegionsToCheckWhenEscapingThroughOpenDoors ); return exitFound; }