Beispiel #1
0
        public static bool TryMoveThing(Thing thing, IntVec3 loc, Map map)
        {
            IntVec3 position = default(IntVec3);

            if (!GenPlace.TryFindPlaceSpotNear(loc, map, thing, false, out position))
            {
                return(false);
            }
            thing.Position = position;
            return(true);
        }
        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 #3
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();
            }
        }