Пример #1
0
        // checks if thing has it's free stockpile cell
        public bool StorageCellExists(Pawn pawn, Thing thing)
        {
            foreach (var slotGroup in Find.SlotGroupManager.AllGroupsListInPriorityOrder)
            {
                foreach (var cell in slotGroup.CellsList.Where(cell => StoreUtility.IsValidStorageFor(cell, thing) && pawn.CanReserve(cell)))
                {
                    if (cell != IntVec3.Invalid)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #2
0
        public static bool PlaceItem(Thing t, IntVec3 cell, bool forbid, Map map, bool firstAbsorbStack = false)
        {
            Action <Thing> effect = (item) =>
            {
                item.def.soundDrop.PlayOneShot(item);
                MoteMaker.ThrowDustPuff(item.Position, map, 0.5f);
            };

            Func <bool> absorb = () =>
            {
                cell.SlotGroupCells(map).SelectMany(c => c.GetThingList(map)).Where(i => i.def == t.def).ForEach(i => i.TryAbsorbStack(t, true));
                if (t.stackCount == 0)
                {
                    effect(t);
                    return(true);
                }
                return(false);
            };

            // fast check:
            if (!firstAbsorbStack && cell.GetThingList(map).Where(ti => ti.def.category == ThingCategory.Item).Count() == 0)
            {
                if (t.Spawned)
                {
                    t.DeSpawn();
                }
                GenPlace.TryPlaceThing(t, cell, map, ThingPlaceMode.Direct);
                if (forbid)
                {
                    t.SetForbidden(forbid);
                }
                effect(t);
                return(true);
            }
            if (absorb())
            {
                return(true);
            }
            // IsValidStorageFor should also work for multi-storage mods
            if (StoreUtility.IsValidStorageFor(cell, map, t))
            {
                GenPlace.TryPlaceThing(t, cell, map, ThingPlaceMode.Direct);
                if (forbid)
                {
                    t.SetForbidden(forbid);
                }
                effect(t);
                return(true);
            }
            var o = cell.SlotGroupCells(map).Where(c => c.IsValidStorageFor(map, t))
                    .Where(c => c.GetThingList(map).Where(b => b.def.category == ThingCategory.Building).All(b => !(b is Building_BeltConveyor)))
                    .FirstOption();

            if (o.HasValue)
            {
                if (t.Spawned)
                {
                    t.DeSpawn();
                }
                GenPlace.TryPlaceThing(t, o.Value, map, ThingPlaceMode.Near);
                if (forbid)
                {
                    t.SetForbidden(forbid);
                }
                effect(t);
                return(true);
            }
            return(false);
        }
Пример #3
0
        public static Toil DropTheCarriedInCell(TargetIndex StoreCellInd, ThingPlaceMode placeMode, TargetIndex CarrierInd)
        {
            Toil toil = new Toil();

            toil.initAction = () =>
            {
                Pawn         actor   = toil.actor;
                Job          curJob  = actor.jobs.curJob;
                Vehicle_Cart carrier = actor.jobs.curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart;
                if (carrier.storage.Count <= 0)
                {
                    return;
                }
                toil.actor.jobs.curJob.SetTarget(TargetIndex.A, carrier.storage.First());
                Thing   dropThing = toil.actor.jobs.curJob.targetA.Thing;
                IntVec3 destLoc   = actor.jobs.curJob.GetTarget(StoreCellInd).Cell;
                Thing   dummy;

                if (destLoc.GetStorable() == null)
                {
                    Find.DesignationManager.RemoveAllDesignationsOn(dropThing);
                    carrier.storage.TryDrop(dropThing, destLoc, placeMode, out dummy);
                }

                //Check cell queue is adjacent
                List <TargetInfo> cells = curJob.GetTargetQueue(StoreCellInd);
                for (int i = 0; i < cells.Count && i < carrier.storage.Count; i++)
                {
                    if (destLoc.AdjacentTo8Way(cells[i].Cell) && cells[i].Cell.GetStorable() == null)
                    {
                        Find.DesignationManager.RemoveAllDesignationsOn(carrier.storage[i]);
                        carrier.storage.TryDrop(carrier.storage[i], cells[i].Cell, ThingPlaceMode.Direct, out dummy);
                        cells.RemoveAt(i);
                        i--;
                    }
                }
                //Check item queue is valid storage for adjacent cell
                foreach (IntVec3 adjCell in GenAdj.CellsAdjacent8Way(destLoc))
                {
                    if (carrier.storage.Count > 0 && adjCell.GetStorable() == null && StoreUtility.IsValidStorageFor(adjCell, carrier.storage.First()))
                    {
                        Find.DesignationManager.RemoveAllDesignationsOn(carrier.storage.First());
                        carrier.storage.TryDrop(carrier.storage.First(), adjCell, ThingPlaceMode.Direct, out dummy);
                    }
                }
            };
            toil.FailOnDestroyedOrNull(CarrierInd);
            return(toil);
        }