public StorageReservation(Comp_StorageAbstract storage, Pawn pawn, Thing thing, int stackCount = 0)
 {
     this.storage    = storage;
     def             = thing.def;
     this.stackCount = (stackCount != 0 ? stackCount : thing.stackCount);
     stuff           = thing.Stuff;
     this.pawn       = pawn;
 }
        public void Notify_ComponentDeSpawned(Comp_CoordinatedAbstract component)
        {
            Type type = component.GetType();

            if (typeof(Comp_StorageInput).IsAssignableFrom(type))
            {
                Comp_StorageInput comp      = (Comp_StorageInput)component;
                SlotGroup         slotGroup = comp.GetSlotGroup();
                List <IntVec3>    cells;
                if (slotGroup != null && map_slotGroup_inputCells.TryGetValue(slotGroup, out cells))
                {
                    foreach (var cell in comp.specificCells)
                    {
                        cells.Remove(cell);
                    }
                    if (cells.Count == 0)
                    {
                        map_slotGroup_inputCells.Remove(slotGroup);
                    }
                }
                inputs.Remove(comp);
                unconnectedInputs.Remove(comp);
                map.slotGroupManager.Notify_GroupChangedPriority();
            }
            else if (typeof(Comp_StorageOutput).IsAssignableFrom(type))
            {
                outputs.Remove((Comp_StorageOutput)component);
                previousRootCell = IntVec3.Invalid;
            }
            else if (typeof(Comp_StorageAbstract).IsAssignableFrom(type))
            {
                Comp_StorageAbstract comp = (Comp_StorageAbstract)component;
                storages.Remove(comp);
                foreach (var reservation in reservations.ToList())
                {
                    if (reservation.storage == comp)
                    {
                        reservations.Remove(reservation);
                    }
                }
            }
            foreach (var cell in component.specificCells)
            {
                List <Comp_CoordinatedAbstract> compsInCell;
                map_cell_comps.TryGetValue(cell, out compsInCell);
                compsInCell.Remove(component);
                if (compsInCell.Count == 0)
                {
                    map_cell_comps.Remove(cell);
                }
            }
        }
 public override void PostSpawnSetup(bool respawningAfterLoad)
 {
     base.PostSpawnSetup(respawningAfterLoad);
     if (properties.linkToParentsStorage != null)
     {
         linkedStorage = (Comp_StorageAbstract)AccessTools
                         .Method(typeof(Extensions), "GetStorageComponent")
                         .MakeGenericMethod(properties.linkToParentsStorage)
                         .Invoke(null, new object[] { parent.Position, parent.Map });
     }
     else
     {
         linkedStorage = parent.Map.GetStorageCoordinator().DebugGetAnyStorage();
         Utility.Debug($"{this} connected to {linkedStorage} in {GetSlotGroup()}");
     }
     linkedStorage?.Notify_IOAdded(this);
 }
Exemple #4
0
        static LocalTargetInfo ClosestOutputOrPosition(Toil toil, TargetIndex targetIndex)
        {
            LocalTargetInfo targetInfo = toil.actor.jobs.curJob.GetTarget(targetIndex);
            Thing           thing      = targetInfo.Thing;

            if (thing != null)
            {
                Comp_StorageAbstract comp = thing.Position.GetStorageComponent <Comp_StorageAbstract>(thing.Map);
                if (comp != null)
                {
                    Thing output = comp.FindClosestOutputParent(toil.actor.Position);
                    if (output != null)
                    {
                        return(new LocalTargetInfo(output));
                    }
                }
            }
            return(toil.actor.CurJob.GetTarget(targetIndex));
        }
 virtual public void Notify_StorageRemoved()
 {
     linkedStorage = null;
 }