public void Init(IntVec3 cell, CompCachedDeepStorage comp)
 {
     this.Cell                   = cell;
     _comp                       = comp;
     _minNumberStacks            = _comp.minNumberStacks;
     _maxNumberStacks            = _comp.maxNumberStacks;
     _limitintTotalFactorForCell = _comp.limitingTotalFactorForCell;
 }
Exemple #2
0
        public Cell_Storage_Collection(Building_Storage storage, CompCachedDeepStorage comp)
        {
            _comp     = comp;
            _parent   = storage;
            _settings = storage.settings;

            if (storage.Spawned)
            {
                this.Init(storage.AllSlotCellsList(), storage.Map);
            }
        }
Exemple #3
0
        public static bool IsCachedDeepStorage(this SlotGroup slotGroup, out CompCachedDeepStorage comp)
        {
            if (slotGroup?.parent is Building_Storage building)
            {
                comp = building.TryGetComp <CompCachedDeepStorage>();
                return(comp != null);
            }

            comp = null;
            return(false);
        }
Exemple #4
0
        public static bool GetCacheDeepStorageOnCell(IntVec3 cell, Map map, out CompCachedDeepStorage compCached) {
            if (GetDeepStorageOnCell(cell, map, out CompDeepStorage comp)) {
                if (comp is CompCachedDeepStorage temp) {
                    compCached = temp;
                    return true;
                }
            }

            compCached = null;
            return false;
        }
Exemple #5
0
        /*********************************************************************************/
        public override void PostExposeData()   // why not call it "ExposeData" anyway?
        {
            Scribe_Values.Look(ref cached, nameof(cached));
            Scribe_Values.Look <string>(ref buildingLabel, "LWM_DS_DSU_label", "", false);

            if (Scribe.mode == LoadSaveMode.LoadingVars)
            {
                Log.Message($"Saving cached {cached} for {this.parent}");
                if (cached)
                {
                    CompCachedDeepStorage compCached = new CompCachedDeepStorage();
                    compCached.parent = this.parent;
                    compCached.Initialize(this.props);
                    compCached.buildingLabel = this.buildingLabel;

                    int index = this.parent.AllComps.IndexOf(this);
                    this.parent.AllComps[index] = compCached;
                    compCached.PostExposeData();
                }
            }
        }
Exemple #6
0
 /// <summary>
 /// This constructor is used for substituting a CompCacheDeepStorage with CompDeepStorage
 /// for storage units that are previously saved with CompDeepStorage.
 /// </summary>
 /// <param name="compCached"></param>
 public CompDeepStorage(CompCachedDeepStorage compCached)
 {
     buildingLabel = compCached.buildingLabel;
     this.parent   = compCached.parent;
     this.Initialize(compCached.props);
 }
Exemple #7
0
        } // end TryPlaceDirect's Postfix

        private static void PostfixForCache(ref bool result, Thing thing, IntVec3 loc, Map map,
                                            ref Thing resultingThing,
                                            Action <Thing, int> placedAction, CompCachedDeepStorage compCached)
        {
            // The only time when result is true is when thing is not split and it is either fully absorbed into another stack
            // or it is placed with GenSpawn.Spawn(). In either case, there is no more work to do.
            // If result is false, it always suggests that there are some stacks left in the initial thing.
            if (result)
            {
                return;
            }

            if (!thing.def.EverStorable(false) || !compCached.StorageSettings.AllowedToAccept(thing))
            {
                return;
            }

            if (compCached.CapacityAt(thing, loc, map, out int capacity))
            {
                int stackLimit = thing.def.stackLimit;
                while (capacity > 0)
                {
                    // Possible states:
                    // 1. stackLimit > capacity >= stackCount
                    // 2. capacity >= stackLimit >= stackCount
                    // 3. capacity >= stackCount >= stackLimit
                    // 4. stackLimit > stackCount >= capacity
                    // 5. stackCount >= stackLimit >= capacity
                    // 6. stackCount >= capacity >= stackLimit
                    // 7. stackLimit = capacity = stackCount

                    // The building has only one non-full stack for storage.
                    if (capacity < stackLimit)
                    {
                        result = compCached.CellStorages.AbsorbWithNonFull(thing, loc, placedAction, ref resultingThing);
                        // Absorb whatever it can and returns.
                        break;
                    }
                    else
                    {
                        if (thing.stackCount > stackLimit)
                        {
                            // Works with one stackLimit of thing at a time.
                            Thing newThing = thing.SplitOff(stackLimit);
                            resultingThing = GenSpawn.Spawn(newThing, loc, map);
                            placedAction?.Invoke(newThing, stackLimit);
                            capacity -= stackLimit;
                            continue;
                        }
                        else
                        {
                            // At this state, there are certainly enough room for the storage to take in all stacks,
                            // given capacity >= stackLimit and thing.stackCount <= stackLimit.
                            if (thing.stackCount != stackLimit)
                            {
                                result = compCached.CellStorages.AbsorbWithNonFull(thing, loc, placedAction, ref resultingThing);
                                if (result)
                                {
                                    break;
                                }
                            }

                            // NonFull cannot finish the job, so use a empty slot in storage.
                            resultingThing = GenSpawn.Spawn(thing, loc, map);
                            result         = true;
                            placedAction?.Invoke(resultingThing, resultingThing.stackCount);
                            break;
                        }
                    }
                }
            }
        }
 public Deep_Storage_Cell_Storage_Model(IntVec3 cell, CompCachedDeepStorage comp)
 {
     this.Init(cell, comp);
 }