Ejemplo n.º 1
0
        public static bool TryFindRandomSpawnCellForPawnNear(IntVec3 root, Map map, out IntVec3 result, int firstTryWithRadius = 4)
        {
            bool result2;

            if (root.Standable(map) && root.GetFirstPawn(map) == null)
            {
                result  = root;
                result2 = true;
            }
            else
            {
                bool rootFogged = root.Fogged(map);
                int  num        = firstTryWithRadius;
                for (int i = 0; i < 3; i++)
                {
                    if (CellFinder.TryFindRandomReachableCellNear(root, map, (float)num, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (IntVec3 c) => c.Standable(map) && (rootFogged || !c.Fogged(map)) && c.GetFirstPawn(map) == null, null, out result, 999999))
                    {
                        return(true);
                    }
                    num *= 2;
                }
                num = firstTryWithRadius + 1;
                while (!CellFinder.TryRandomClosewalkCellNear(root, map, num, out result, null))
                {
                    if (num > map.Size.x / 2 && num > map.Size.z / 2)
                    {
                        result = root;
                        return(false);
                    }
                    num *= 2;
                }
                result2 = true;
            }
            return(result2);
        }
Ejemplo n.º 2
0
 public static bool TryRandomClosewalkCellNear(IntVec3 root, Map map, int radius, out IntVec3 result, Predicate <IntVec3> extraValidator = null)
 {
     return(CellFinder.TryFindRandomReachableCellNear(root, map, (float)radius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (IntVec3 c) => c.Standable(map) && (extraValidator == null || extraValidator(c)), null, out result, 999999));
 }
Ejemplo n.º 3
0
        public static bool TryFindRandomReachableCellNear(IntVec3 root, Map map, float radius, TraverseParms traverseParms, Predicate <IntVec3> cellValidator, Predicate <Region> regionValidator, out IntVec3 result, int maxRegions = 999999)
        {
            bool result2;

            if (map == null)
            {
                Log.ErrorOnce("Tried to find reachable cell in a null map", 61037855, false);
                result  = IntVec3.Invalid;
                result2 = false;
            }
            else
            {
                Region region = root.GetRegion(map, RegionType.Set_Passable);
                if (region == null)
                {
                    result  = IntVec3.Invalid;
                    result2 = false;
                }
                else
                {
                    CellFinder.workingRegions.Clear();
                    float radSquared = radius * radius;
                    RegionTraverser.BreadthFirstTraverse(region, (Region from, Region r) => r.Allows(traverseParms, true) && (radius > 1000f || r.extentsClose.ClosestDistSquaredTo(root) <= radSquared) && (regionValidator == null || regionValidator(r)), delegate(Region r)
                    {
                        CellFinder.workingRegions.Add(r);
                        return(false);
                    }, maxRegions, RegionType.Set_Passable);
                    while (CellFinder.workingRegions.Count > 0)
                    {
                        Region region2 = CellFinder.workingRegions.RandomElementByWeight((Region r) => (float)r.CellCount);
                        if (region2.TryFindRandomCellInRegion((IntVec3 c) => (float)(c - root).LengthHorizontalSquared <= radSquared && (cellValidator == null || cellValidator(c)), out result))
                        {
                            CellFinder.workingRegions.Clear();
                            return(true);
                        }
                        CellFinder.workingRegions.Remove(region2);
                    }
                    result = IntVec3.Invalid;
                    CellFinder.workingRegions.Clear();
                    result2 = false;
                }
            }
            return(result2);
        }
Ejemplo n.º 4
0
 public static void AllRegionsNear(List <Region> results, Region root, int maxRegions, TraverseParms traverseParms, Predicate <Region> validator = null, Pawn pawnToAllow = null, RegionType traversableRegionTypes = RegionType.Set_Passable)
 {
     if (results == null)
     {
         Log.ErrorOnce("Attempted to call AllRegionsNear with an invalid results list", 60733193, false);
     }
     else
     {
         results.Clear();
         if (root == null)
         {
             Log.ErrorOnce("Attempted to call AllRegionsNear with an invalid root", 9107839, false);
         }
         else
         {
             RegionTraverser.BreadthFirstTraverse(root, (Region from, Region r) => (validator == null || validator(r)) && r.Allows(traverseParms, true) && (pawnToAllow == null || !r.IsForbiddenEntirely(pawnToAllow)), delegate(Region r)
             {
                 results.Add(r);
                 return(false);
             }, maxRegions, traversableRegionTypes);
         }
     }
 }
Ejemplo n.º 5
0
 public static bool CanReach(this Pawn pawn, LocalTargetInfo dest, PathEndMode peMode, Danger maxDanger, bool canBash = false, TraverseMode mode = TraverseMode.ByPawn)
 {
     return(pawn.Spawned && pawn.Map.reachability.CanReach(pawn.Position, dest, peMode, TraverseParms.For(pawn, maxDanger, mode, canBash)));
 }
Ejemplo n.º 6
0
 public static bool CanReachMapEdge(this Pawn p)
 {
     return(p.Spawned && p.Map.reachability.CanReachMapEdge(p.Position, TraverseParms.For(p, Danger.Deadly, TraverseMode.ByPawn, false)));
 }