private static bool TryPlaceDirect(Thing thing, IntVec3 loc, Map map, out Thing resultingThing, Action <Thing, int> placedAction = null)
        {
            Thing thing2 = thing;
            bool  flag   = false;

            if (thing.stackCount > thing.def.stackLimit)
            {
                thing = thing.SplitOff(thing.def.stackLimit);
                flag  = true;
            }
            if (thing.def.stackLimit > 1)
            {
                List <Thing> thingList = loc.GetThingList(map);
                int          i         = 0;
                while (i < thingList.Count)
                {
                    Thing thing3 = thingList[i];
                    if (!thing3.CanStackWith(thing))
                    {
                        i++;
                    }
                    else
                    {
                        int stackCount = thing.stackCount;
                        if (thing3.TryAbsorbStack(thing, true))
                        {
                            resultingThing = thing3;
                            if (placedAction != null)
                            {
                                placedAction(thing3, stackCount);
                            }
                            return(!flag);
                        }
                        resultingThing = null;
                        if (placedAction != null && stackCount != thing.stackCount)
                        {
                            placedAction(thing3, stackCount - thing.stackCount);
                        }
                        if (thing2 != thing)
                        {
                            thing2.TryAbsorbStack(thing, false);
                        }
                        return(false);
                    }
                }
            }
            resultingThing = GenSpawn.Spawn(thing, loc, map, WipeMode.Vanish);
            if (placedAction != null)
            {
                placedAction(thing, thing.stackCount);
            }
            return(!flag);
        }
Esempio n. 2
0
        private static bool TryPlaceDirect(Thing thing, IntVec3 loc, Rot4 rot, Map map, out Thing resultingThing, Action <Thing, int> placedAction = null)
        {
            Thing thing2 = thing;
            bool  flag   = false;

            if (thing.stackCount > thing.def.stackLimit)
            {
                thing = thing.SplitOff(thing.def.stackLimit);
                flag  = true;
            }
            if (thing.def.stackLimit > 1)
            {
                List <Thing> thingList = loc.GetThingList(map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    Thing thing3 = thingList[i];
                    if (thing3.CanStackWith(thing))
                    {
                        int stackCount = thing.stackCount;
                        if (thing3.TryAbsorbStack(thing, respectStackLimit: true))
                        {
                            resultingThing = thing3;
                            placedAction?.Invoke(thing3, stackCount);
                            return(!flag);
                        }
                        resultingThing = null;
                        if (placedAction != null && stackCount != thing.stackCount)
                        {
                            placedAction(thing3, stackCount - thing.stackCount);
                        }
                        if (thing2 != thing)
                        {
                            thing2.TryAbsorbStack(thing, respectStackLimit: false);
                        }
                        return(false);
                    }
                }
            }
            resultingThing = GenSpawn.Spawn(thing, loc, map, rot);
            placedAction?.Invoke(thing, thing.stackCount);
            return(!flag);
        }
        public static Thing HaulPlaceBlockerIn(Thing haulThing, IntVec3 c, Map map, bool checkBlueprints)
        {
            List <Thing> list = map.thingGrid.ThingsListAt(c);

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing = list[i];
                if (checkBlueprints && thing.def.IsBlueprint)
                {
                    return(thing);
                }
                if ((thing.def.category != ThingCategory.Plant || thing.def.passability != Traversability.Standable) && thing.def.category != ThingCategory.Filth)
                {
                    if (haulThing == null || thing.def.category != ThingCategory.Item || !thing.CanStackWith(haulThing) || thing.def.stackLimit - thing.stackCount < haulThing.stackCount)
                    {
                        if (thing.def.EverHaulable)
                        {
                            return(thing);
                        }
                        if (haulThing != null && GenSpawn.SpawningWipes(haulThing.def, thing.def))
                        {
                            return(thing);
                        }
                        if (thing.def.passability != Traversability.Standable)
                        {
                            if (thing.def.surfaceType != SurfaceType.Item)
                            {
                                return(thing);
                            }
                        }
                    }
                }
            }
            return(null);
        }
        private static GenPlace.PlaceSpotQuality PlaceSpotQualityAt(IntVec3 c, Map map, Thing thing, IntVec3 center, bool allowStacking, Predicate <IntVec3> extraValidator = null)
        {
            if (!c.InBounds(map) || !c.Walkable(map))
            {
                return(GenPlace.PlaceSpotQuality.Unusable);
            }
            if (extraValidator != null && !extraValidator(c))
            {
                return(GenPlace.PlaceSpotQuality.Unusable);
            }
            List <Thing> list = map.thingGrid.ThingsListAt(c);

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing2 = list[i];
                if (thing.def.saveCompressible && thing2.def.saveCompressible)
                {
                    return(GenPlace.PlaceSpotQuality.Unusable);
                }
                if (thing.def.category == ThingCategory.Item && thing2.def.category == ThingCategory.Item && (!thing2.CanStackWith(thing) || thing2.stackCount >= thing.def.stackLimit))
                {
                    return(GenPlace.PlaceSpotQuality.Unusable);
                }
            }
            if (c.GetRoom(map, RegionType.Set_Passable) == center.GetRoom(map, RegionType.Set_Passable))
            {
                if (allowStacking)
                {
                    for (int j = 0; j < list.Count; j++)
                    {
                        Thing thing3 = list[j];
                        if (thing3.def.category == ThingCategory.Item && thing3.CanStackWith(thing) && thing3.stackCount < thing.def.stackLimit)
                        {
                            return(GenPlace.PlaceSpotQuality.Perfect);
                        }
                    }
                }
                Pawn pawn = thing as Pawn;
                bool flag = pawn != null && pawn.Downed;
                GenPlace.PlaceSpotQuality placeSpotQuality = GenPlace.PlaceSpotQuality.Perfect;
                for (int k = 0; k < list.Count; k++)
                {
                    Thing thing4 = list[k];
                    if (thing4.def.IsDoor)
                    {
                        return(GenPlace.PlaceSpotQuality.Bad);
                    }
                    if (thing4 is Building_WorkTable)
                    {
                        return(GenPlace.PlaceSpotQuality.Bad);
                    }
                    Pawn pawn2 = thing4 as Pawn;
                    if (pawn2 != null)
                    {
                        if (pawn2.Downed || flag)
                        {
                            return(GenPlace.PlaceSpotQuality.Bad);
                        }
                        if (placeSpotQuality > GenPlace.PlaceSpotQuality.Okay)
                        {
                            placeSpotQuality = GenPlace.PlaceSpotQuality.Okay;
                        }
                    }
                    if (thing4.def.category == ThingCategory.Plant && thing4.def.selectable && placeSpotQuality > GenPlace.PlaceSpotQuality.Okay)
                    {
                        placeSpotQuality = GenPlace.PlaceSpotQuality.Okay;
                    }
                }
                return(placeSpotQuality);
            }
            if (!map.reachability.CanReach(center, c, PathEndMode.OnCell, TraverseMode.PassDoors, Danger.Deadly))
            {
                return(GenPlace.PlaceSpotQuality.Awful);
            }
            return(GenPlace.PlaceSpotQuality.Bad);
        }
Esempio n. 5
0
        private static PlaceSpotQuality PlaceSpotQualityAt(IntVec3 c, Rot4 rot, Map map, Thing thing, IntVec3 center, bool allowStacking, Predicate <IntVec3> extraValidator = null)
        {
            if (!c.InBounds(map) || !c.Walkable(map))
            {
                return(PlaceSpotQuality.Unusable);
            }
            if (!GenAdj.OccupiedRect(c, rot, thing.def.Size).InBounds(map))
            {
                return(PlaceSpotQuality.Unusable);
            }
            if (extraValidator != null && !extraValidator(c))
            {
                return(PlaceSpotQuality.Unusable);
            }
            List <Thing> list = map.thingGrid.ThingsListAt(c);

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing2 = list[i];
                if (thing.def.saveCompressible && thing2.def.saveCompressible)
                {
                    return(PlaceSpotQuality.Unusable);
                }
                if (thing.def.category == ThingCategory.Item && thing2.def.category == ThingCategory.Item && (!thing2.CanStackWith(thing) || thing2.stackCount >= thing.def.stackLimit))
                {
                    return(PlaceSpotQuality.Unusable);
                }
            }
            if (thing is Building)
            {
                foreach (IntVec3 item in GenAdj.OccupiedRect(c, rot, thing.def.size))
                {
                    Building edifice = item.GetEdifice(map);
                    if (edifice != null && GenSpawn.SpawningWipes(thing.def, edifice.def))
                    {
                        return(PlaceSpotQuality.Awful);
                    }
                }
            }
            if (c.GetRoom(map) != center.GetRoom(map))
            {
                if (!map.reachability.CanReach(center, c, PathEndMode.OnCell, TraverseMode.PassDoors, Danger.Deadly))
                {
                    return(PlaceSpotQuality.Awful);
                }
                return(PlaceSpotQuality.Bad);
            }
            if (allowStacking)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing3 = list[j];
                    if (thing3.def.category == ThingCategory.Item && thing3.CanStackWith(thing) && thing3.stackCount < thing.def.stackLimit)
                    {
                        return(PlaceSpotQuality.Perfect);
                    }
                }
            }
            bool             flag             = (thing as Pawn)?.Downed ?? false;
            PlaceSpotQuality placeSpotQuality = PlaceSpotQuality.Perfect;

            for (int k = 0; k < list.Count; k++)
            {
                Thing thing4 = list[k];
                if (thing4.def.IsDoor)
                {
                    return(PlaceSpotQuality.Bad);
                }
                if (thing4 is Building_WorkTable)
                {
                    return(PlaceSpotQuality.Bad);
                }
                Pawn pawn = thing4 as Pawn;
                if (pawn != null)
                {
                    if (pawn.Downed | flag)
                    {
                        return(PlaceSpotQuality.Bad);
                    }
                    if ((int)placeSpotQuality > 3)
                    {
                        placeSpotQuality = PlaceSpotQuality.Okay;
                    }
                }
                if (thing4.def.category == ThingCategory.Plant && thing4.def.selectable && (int)placeSpotQuality > 3)
                {
                    placeSpotQuality = PlaceSpotQuality.Okay;
                }
            }
            return(placeSpotQuality);
        }