FluffyManager.Utilities_Livestock.GetAll C# (CSharp) Method

GetAll() public static method

public static GetAll ( this pawnKind, Map map ) : IEnumerable
pawnKind this
map Map
return IEnumerable
        public static IEnumerable<Pawn> GetAll( this PawnKindDef pawnKind, Map map )
        {
            // check if we have a cached version
            IEnumerable<Pawn> cached;

            // does it exist at all?
            var key = new Pair<PawnKindDef, Map>( pawnKind, map );
            bool cacheExists = _allCache.ContainsKey( key );

            // is it up to date?
            if ( cacheExists &&
                 _allCache[key].TryGetValue( out cached ) &&
                 cached != null )
            {
                return cached;
            }

            // if not, get a new list.
            cached = map.mapPawns.AllPawns
                        .Where( p => p.RaceProps.Animal // is animal
                                     && !p.Dead // is alive
                                     && p.kindDef == pawnKind ); // is our managed pawnkind

            // update if key exists
            if ( cacheExists )
            {
                _allCache[key].Update( cached );
            }

            // else add it
            else
            {
                // severely limit cache to only apply for one cycle (one job)
                _allCache.Add( key, new Utilities.CachedValue<IEnumerable<Pawn>>( cached, 2 ) );
            }
            return cached;
        }

Same methods

Utilities_Livestock::GetAll ( this pawnKind, Map map, AgeAndSex ageSex ) : IEnumerable