Exemplo n.º 1
0
        public static IntVec3 SpotToChewStandingNear(Pawn pawn, Thing ingestible)
        {
            IntVec3             root         = pawn.Position;
            Room                rootRoom     = pawn.GetRoom();
            bool                desperate    = false;
            bool                ignoreDanger = false;
            float               maxDist      = 4f;
            Predicate <IntVec3> validator    = delegate(IntVec3 c)
            {
                IntVec3 placeSpot = root - c;
                if ((float)placeSpot.LengthHorizontalSquared > maxDist * maxDist)
                {
                    return(false);
                }
                if (pawn.HostFaction != null && c.GetRoom(pawn.Map) != rootRoom)
                {
                    return(false);
                }
                if (!desperate)
                {
                    if (!c.Standable(pawn.Map))
                    {
                        return(false);
                    }
                    if (GenPlace.HaulPlaceBlockerIn(null, c, pawn.Map, checkBlueprintsAndFrames: false) != null)
                    {
                        return(false);
                    }
                    if (c.GetRegion(pawn.Map).type == RegionType.Portal)
                    {
                        return(false);
                    }
                }
                if (!ignoreDanger && c.GetDangerFor(pawn, pawn.Map) != Danger.None)
                {
                    return(false);
                }
                if (c.ContainsStaticFire(pawn.Map) || c.ContainsTrap(pawn.Map))
                {
                    return(false);
                }
                if (!pawn.Map.pawnDestinationReservationManager.CanReserve(c, pawn))
                {
                    return(false);
                }
                return(Toils_Ingest.TryFindAdjacentIngestionPlaceSpot(c, ingestible.def, pawn, out placeSpot) ? true : false);
            };
            int    maxRegions = 1;
            Region region     = pawn.GetRegion();

            for (int i = 0; i < 30; i++)
            {
                switch (i)
                {
                case 1:
                    desperate = true;
                    break;

                case 2:
                    desperate  = false;
                    maxRegions = 4;
                    break;

                case 6:
                    desperate = true;
                    break;

                case 10:
                    desperate  = false;
                    maxDist    = 8f;
                    maxRegions = 12;
                    break;

                case 15:
                    desperate = true;
                    break;

                case 20:
                    maxDist    = 15f;
                    maxRegions = 16;
                    break;

                case 26:
                    maxDist      = 5f;
                    maxRegions   = 4;
                    ignoreDanger = true;
                    break;

                case 29:
                    maxDist    = 15f;
                    maxRegions = 16;
                    break;
                }
                if (CellFinder.RandomRegionNear(region, maxRegions, TraverseParms.For(pawn)).TryFindRandomCellInRegionUnforbidden(pawn, validator, out IntVec3 result))
                {
                    if (DebugViewSettings.drawDestSearch)
                    {
                        pawn.Map.debugDrawer.FlashCell(result, 0.5f, "go!");
                    }
                    return(result);
                }
                if (DebugViewSettings.drawDestSearch)
                {
                    pawn.Map.debugDrawer.FlashCell(result, 0f, i.ToString());
                }
            }
            return(region.RandomCell);
        }
Exemplo n.º 2
0
        public static IntVec3 SpotToChewStandingNear(Pawn pawn, Thing ingestible)
        {
            IntVec3             root         = pawn.Position;
            Room                rootRoom     = pawn.GetRoom(RegionType.Set_Passable);
            bool                desperate    = false;
            bool                ignoreDanger = false;
            float               maxDist      = 4f;
            Predicate <IntVec3> validator    = delegate(IntVec3 c)
            {
                if ((float)(root - c).LengthHorizontalSquared > maxDist * maxDist)
                {
                    return(false);
                }
                if (pawn.HostFaction != null && c.GetRoom(pawn.Map, RegionType.Set_Passable) != rootRoom)
                {
                    return(false);
                }
                if (!desperate)
                {
                    if (!c.Standable(pawn.Map))
                    {
                        return(false);
                    }
                    if (GenPlace.HaulPlaceBlockerIn(null, c, pawn.Map, false) != null)
                    {
                        return(false);
                    }
                    if (c.GetRegion(pawn.Map, RegionType.Set_Passable).type == RegionType.Portal)
                    {
                        return(false);
                    }
                }
                IntVec3 intVec2;
                return((ignoreDanger || c.GetDangerFor(pawn, pawn.Map) == Danger.None) && !c.ContainsStaticFire(pawn.Map) && !c.ContainsTrap(pawn.Map) && pawn.Map.pawnDestinationReservationManager.CanReserve(c, pawn, false) && Toils_Ingest.TryFindAdjacentIngestionPlaceSpot(c, ingestible.def, pawn, out intVec2));
            };
            int    maxRegions = 1;
            Region region     = pawn.GetRegion(RegionType.Set_Passable);

            for (int i = 0; i < 30; i++)
            {
                if (i == 1)
                {
                    desperate = true;
                }
                else if (i == 2)
                {
                    desperate  = false;
                    maxRegions = 4;
                }
                else if (i == 6)
                {
                    desperate = true;
                }
                else if (i == 10)
                {
                    desperate  = false;
                    maxDist    = 8f;
                    maxRegions = 12;
                }
                else if (i == 15)
                {
                    desperate = true;
                }
                else if (i == 20)
                {
                    maxDist    = 15f;
                    maxRegions = 16;
                }
                else if (i == 26)
                {
                    maxDist      = 5f;
                    maxRegions   = 4;
                    ignoreDanger = true;
                }
                else if (i == 29)
                {
                    maxDist    = 15f;
                    maxRegions = 16;
                }
                Region  reg = CellFinder.RandomRegionNear(region, maxRegions, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), null, null, RegionType.Set_Passable);
                IntVec3 intVec;
                if (reg.TryFindRandomCellInRegionUnforbidden(pawn, validator, out intVec))
                {
                    if (DebugViewSettings.drawDestSearch)
                    {
                        pawn.Map.debugDrawer.FlashCell(intVec, 0.5f, "go!", 50);
                    }
                    return(intVec);
                }
                if (DebugViewSettings.drawDestSearch)
                {
                    pawn.Map.debugDrawer.FlashCell(intVec, 0f, i.ToString(), 50);
                }
            }
            return(region.RandomCell);
        }