Пример #1
0
        public static List<Pawn> GetMasterOptions( this PawnKindDef pawnkind, Map map, MasterMode mode )
        {
            // check if we have a cached version
            IEnumerable<Pawn> cached;

            // does it exist at all?
            var key = new Triplet<PawnKindDef, Map, MasterMode>( pawnkind, map, mode );
            bool cacheExists = _masterCache.ContainsKey(key);

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

            // if not, get a new list.
            cached = map.mapPawns.FreeColonistsSpawned
                .Where( p => !p.Dead &&

                    // matches mode
                    ( p.GetMasterMode() & mode ) != MasterMode.Default
                );
            
            // update if key exists
            if (cacheExists)
                _masterCache[key].Update(cached);

            // else add it
            else
            {
                // severely limit cache to only apply for one cycle (one job)
                _masterCache.Add(key, new Utilities.CachedValue<IEnumerable<Pawn>>(cached, 2));
            }
            return cached.ToList();
        }
Пример #2
0
        public static IEnumerable <Pawn> GetAll(this PawnKindDef pawnKind, Map map, AgeAndSex ageSex)
        {
            var key = new Triplet <PawnKindDef, Map, AgeAndSex>(pawnKind, map, ageSex);

            if (AllSexedCache.TryGetValue(key, out var pawns))
            {
                return(pawns);
            }

            Func <IEnumerable <Pawn> > getter = () => pawnKind.GetAll(map).Where(p => PawnIsOfAgeSex(p, ageSex));    // is of age and sex we want

            AllSexedCache.Add(key, getter);
            return(getter());
        }
Пример #3
0
        public static IEnumerable <Pawn> GetTame(this PawnKindDef pawnKind, Map map, AgeAndSex ageSex)
        {
#if DEBUG_LIFESTOCK_COUNTS
            List <Pawn> tame = GetAll(ageSex).Where(p => p.Faction == Faction.OfPlayer).ToList();
            Log.Message("Tamecount " + ageSex + ": " + tame.Count);
            return(tame);
#else
            var key = new Triplet <PawnKindDef, Map, AgeAndSex>(pawnKind, map, ageSex);
            if (TameSexedCache.TryGetValue(key, out var pawns))
            {
                return(pawns);
            }

            Func <IEnumerable <Pawn> > getter = () => pawnKind.GetAll(map, ageSex).Where(p => p.Faction == Faction.OfPlayer);
            TameSexedCache.Add(key, getter);
            return(getter());
#endif
        }
Пример #4
0
        public static IEnumerable <Pawn> GetWild(this PawnKindDef pawnKind, Map map, AgeAndSex ageSex)
        {
#if DEBUG_LIFESTOCK_COUNTS
            foreach (Pawn p in GetAll(ageSex))
            {
                Log.Message(p.Faction?.GetCallLabel() ?? "NULL");
            }
            List <Pawn> wild = GetAll(ageSex).Where(p => p.Faction == null).ToList();
            Log.Message("Wildcount " + ageSex + ": " + wild.Count);
            return(wild);
#else
            var key = new Triplet <PawnKindDef, Map, AgeAndSex>(pawnKind, map, ageSex);
            if (WildSexedCache.TryGetValue(key, out var pawns))
            {
                return(pawns);
            }

            Func <IEnumerable <Pawn> > getter = () => pawnKind.GetAll(map, ageSex).Where(p => p.Faction == null);
            WildSexedCache.Add(key, getter);
            return(getter());
#endif
        }
Пример #5
0
 public bool Equals(Triplet <T1, T2, T3> other)
 {
     return(EqualityComparer <T1> .Default.Equals(First, other.First) &&
            EqualityComparer <T2> .Default.Equals(Second, other.Second) &&
            EqualityComparer <T3> .Default.Equals(Third, other.Third));
 }
Пример #6
0
 public bool Equals(Triplet <T1, T2, T3> other)
 {
     return(EqualityComparer <T1> .Default.Equals(first, other.first) && EqualityComparer <T2> .Default.Equals(second, other.second) && EqualityComparer <T3> .Default.Equals(third, other.third));
 }