Beispiel #1
0
        public int GetCountInDesignations()
        {
            var count = 0;

            if (_designatedCachedValue.TryGetValue(out count))
            {
                return(count);
            }

            // deconstruction jobs
            count += _designations.Where(d => d.def == DesignationDefOf.Deconstruct)
                     .Sum(d => GetCountInBuilding(d.target.Thing as Building));

            // mining jobs
            var mineralCounts = _designations.Where(d => d.def == DesignationDefOf.Mine)
                                .Select(d => manager
                                        .map.thingGrid.ThingsListAtFast(d.target.Cell)
                                        .FirstOrDefault()?.def)
                                .Where(d => d != null)
                                .GroupBy(d => d, d => d, (d, g) => new { def = d, count = g.Count() })
                                .Where(g => Allowed(g.def));

            foreach (var mineralCount in mineralCounts)
            {
                count += GetCountInMineral(mineralCount.def) * mineralCount.count;
            }

            _designatedCachedValue.Update(count);
            return(count);
        }
        public int GetMeatInDesignations()
        {
            var count = 0;

            // try get cache
            if (_designatedCachedValue.TryGetValue(out count))
            {
                return(count);
            }

            // designated animals
            foreach (Designation des in manager.map.designationManager.SpawnedDesignationsOfDef(DesignationDefOf.Hunt))
            {
                // make sure target is a pawn, is an animal, is not forbidden and somebody can reach it.
                // note: could be rolled into a fancy LINQ chain, but this is probably clearer.
                var target = des.target.Thing as Pawn;
                if (target != null &&
                    target.RaceProps.Animal &&
                    !target.IsForbidden(Faction.OfPlayer) &&
                    manager.map.reachability.CanReachColony(target.Position))
                {
                    count += target.EstimatedMeatCount();
                }
            }

            // update cache
            _designatedCachedValue.Update(count);

            return(count);
        }
        public int GetWoodInDesignations()
        {
            var count = 0;

            // try get cache
            if (_designatedWoodCachedValue.TryGetValue(out count))
            {
                return(count);
            }

            foreach (Designation des in Designations)
            {
                if (des.target.HasThing &&
                    des.target.Thing is Plant)
                {
                    var plant = des.target.Thing as Plant;
                    count += plant.YieldNow();
                }
            }

            // update cache
            _designatedWoodCachedValue.Update(count);

            return(count);
        }
        public int GetMeatInDesignations()
        {
            var count = 0;

            // try get cache
            if (_designatedCachedValue.TryGetValue(out count))
            {
                return(count);
            }

            // designated animals
            foreach (Designation des in _designations)
            {
                var target = des.target.Thing as Pawn;
                if (target != null)
                {
                    count += target.EstimatedMeatCount();
                }
            }

            // update cache
            _designatedCachedValue.Update(count);

            return(count);
        }
        public int GetMeatInCorpses()
        {
            // get current count + corpses in storage that is not a grave + designated count
            // current count in storage
            var count = 0;

            // try get cached value
            if (_corpseCachedValue.TryGetValue(out count))
            {
                return(count);
            }

            // corpses not buried / forbidden
            foreach (Thing current in Corpses)
            {
                // make sure it's a real corpse. (I dunno, poke it?)
                // and that it's not forbidden (anymore) and can be reached.
                var corpse = current as Corpse;
                if (corpse != null &&
                    !corpse.IsForbidden(Faction.OfPlayer) &&
                    manager.map.reachability.CanReachColony(corpse.Position))
                {
                    // check to see if it's buried.
                    var       buried           = false;
                    SlotGroup slotGroup        = manager.map.haulDestinationManager.SlotGroupAt(corpse.Position);
                    var       building_Storage = slotGroup?.parent as Building_Storage;

                    // Sarcophagus inherits grave
                    if (building_Storage != null &&
                        building_Storage.def == ThingDefOf.Grave)
                    {
                        buried = true;
                    }

                    // get the rottable comp and check how far gone it is.
                    var rottable = corpse.TryGetComp <CompRottable>();

                    if (!buried && rottable?.Stage == RotStage.Fresh)
                    {
                        count += corpse.EstimatedMeatCount();
                    }
                }
            }

            // set cache
            _corpseCachedValue.Update(count);

            return(count);
        }
Beispiel #6
0
        public int GetCountInChunks()
        {
            int count;

            if (_chunksCachedValue.TryGetValue(out count))
            {
                return(count);
            }

            count = manager.map.listerThings.AllThings
                    .Where(t => t.Faction == Faction.OfPlayer &&
                           !t.IsForbidden(Faction.OfPlayer) &&
                           IsChunk(t.def))
                    .Sum(GetCountInChunk);

            _chunksCachedValue.Update(count);
            return(count);
        }