static bool Prefix(ref bool __result, Pawn claimant, LocalTargetInfo target)
        {
            var cell = target.Cell;

            if (cell != null)
            {
                Comp_StorageInput comp = cell.GetStorageComponent <Comp_StorageInput>(claimant.Map);
                if (comp != null)
                {
                    Thing thing;
                    if (claimant.CurJob.targetA == target)
                    {
                        thing = claimant.CurJob.targetB.Thing;
                    }
                    else
                    {
                        thing = claimant.CurJob.targetA.Thing;
                    }
                    if (thing != null && thing.def.EverHaulable && comp.Reserve(claimant, thing))
                    {
                        __result = true;
                        return(false);
                    }
                }
            }
            return(true);
        }
Esempio n. 2
0
        static void Postfix(ref Job __result, Pawn p, Thing t, IntVec3 storeCell)
        {
            Comp_StorageInput comp = storeCell.GetStorageComponent <Comp_StorageInput>(p.Map);

            if (comp != null)
            {
                __result.count = comp.CanAccept(t);
            }
        }
Esempio n. 3
0
        static bool Prefix(ref bool __result, IntVec3 c, Map map, Thing storable)
        {
            Comp_StorageInput comp = c.GetStorageComponent <Comp_StorageInput>(map);

            if (comp != null)
            {
                __result = comp.GetSlotGroup().Settings.AllowedToAccept(storable);
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        static bool TryPlaceThing(Thing thing, IntVec3 dropCell, Map map, ThingPlaceMode mode,
                                  out Thing resultingThing, Action <Thing, int> placedAction = null)
        {
            Comp_StorageInput comp = dropCell.GetStorageComponent <Comp_StorageInput>(map);

            if (comp != null)
            {
                return(comp.Store(thing, out resultingThing, placedAction));
            }
            return(GenPlace.TryPlaceThing(thing, dropCell, map, mode, out resultingThing, placedAction));
        }
        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);
                }
            }
        }
Esempio n. 6
0
        static bool Prefix(ref bool __result, IntVec3 c, Map map, Thing t, Pawn carrier, Faction faction)
        {
            Comp_StorageInput comp = c.GetStorageComponent <Comp_StorageInput>(map);

            if (comp != null)
            {
                __result = comp.CanAccept(t) > 0 &&
                           (carrier == null ||
                            (carrier.Map.reachability.CanReach(
                                 (!t.SpawnedOrAnyParentSpawned) ? carrier.PositionHeld : t.PositionHeld,
                                 c,
                                 PathEndMode.ClosestTouch,
                                 TraverseParms.For(carrier, Danger.Deadly, TraverseMode.ByPawn, false))));
                return(false);
            }
            return(true);
        }
        public void Notify_ComponentSpawned(Comp_CoordinatedAbstract component)
        {
            Type type = component.GetType();

            if (typeof(Comp_StorageInput).IsAssignableFrom(type))
            {
                Comp_StorageInput comp = (Comp_StorageInput)component;
                inputs.Add(comp);
                SlotGroup slotGroup = comp.GetSlotGroup();
                if (slotGroup != null)
                {
                    List <IntVec3> cells;
                    if (!map_slotGroup_inputCells.TryGetValue(slotGroup, out cells))
                    {
                        cells = new List <IntVec3>();
                        map_slotGroup_inputCells.Add(slotGroup, cells);
                    }
                    cells.AddRange(comp.specificCells);
                }
                else
                {
                    unconnectedInputs.Add(comp);
                }
                map.slotGroupManager.Notify_GroupChangedPriority();
            }
            else if (typeof(Comp_StorageOutput).IsAssignableFrom(type))
            {
                outputs.Add((Comp_StorageOutput)component);
                previousRootCell = IntVec3.Invalid;
            }
            else if (typeof(Comp_StorageAbstract).IsAssignableFrom(type))
            {
                storages.Add((Comp_StorageAbstract)component);
            }
            foreach (var cell in component.specificCells)
            {
                List <Comp_CoordinatedAbstract> compsInCell;
                if (!map_cell_comps.TryGetValue(cell, out compsInCell))
                {
                    compsInCell = new List <Comp_CoordinatedAbstract>();
                    map_cell_comps.Add(cell, compsInCell);
                }
                compsInCell.Add(component);
            }
        }