public static bool TryPlaceThing(Thing thing, IntVec3 center, Map map, ThingPlaceMode mode, out Thing lastResultingThing, Action <Thing, int> placedAction = null, Predicate <IntVec3> nearPlaceValidator = null)
        {
            if (map == null)
            {
                Log.Error("Tried to place thing " + thing + " in a null map.", false);
                lastResultingThing = null;
                return(false);
            }
            if (thing.def.category == ThingCategory.Filth)
            {
                mode = ThingPlaceMode.Direct;
            }
            if (mode == ThingPlaceMode.Direct)
            {
                return(GenPlace.TryPlaceDirect(thing, center, map, out lastResultingThing, placedAction));
            }
            if (mode == ThingPlaceMode.Near)
            {
                lastResultingThing = null;
                for (;;)
                {
                    int     stackCount = thing.stackCount;
                    IntVec3 loc;
                    if (!GenPlace.TryFindPlaceSpotNear(center, map, thing, true, out loc, nearPlaceValidator))
                    {
                        break;
                    }
                    if (GenPlace.TryPlaceDirect(thing, loc, map, out lastResultingThing, placedAction))
                    {
                        return(true);
                    }
                    if (thing.stackCount == stackCount)
                    {
                        goto Block_7;
                    }
                }
                return(false);

Block_7:
                Log.Error(string.Concat(new object[]
                {
                    "Failed to place ",
                    thing,
                    " at ",
                    center,
                    " in mode ",
                    mode,
                    "."
                }), false);
                lastResultingThing = null;
                return(false);
            }
            throw new InvalidOperationException();
        }
Beispiel #2
0
        public static bool TryPlaceThing(Thing thing, IntVec3 center, Map map, ThingPlaceMode mode, out Thing lastResultingThing, Action <Thing, int> placedAction = null)
        {
            if (map == null)
            {
                Log.Error("Tried to place thing " + thing + " in a null map.");
                lastResultingThing = null;
                return(false);
            }
            if (thing.def.category == ThingCategory.Filth)
            {
                mode = ThingPlaceMode.Direct;
            }
            switch (mode)
            {
            case ThingPlaceMode.Direct:
                return(GenPlace.TryPlaceDirect(thing, center, map, out lastResultingThing, placedAction));

            case ThingPlaceMode.Near:
            {
                lastResultingThing = null;
                int num = -1;
                while (true)
                {
                    num = thing.stackCount;
                    IntVec3 loc = default(IntVec3);
                    if (!GenPlace.TryFindPlaceSpotNear(center, map, thing, true, out loc))
                    {
                        return(false);
                    }
                    if (GenPlace.TryPlaceDirect(thing, loc, map, out lastResultingThing, placedAction))
                    {
                        return(true);
                    }
                    if (thing.stackCount == num)
                    {
                        break;
                    }
                }
                Log.Error("Failed to place " + thing + " at " + center + " in mode " + mode + ".");
                lastResultingThing = null;
                return(false);
            }

            default:
                throw new InvalidOperationException();
            }
        }