Exemplo n.º 1
0
        public static void BreadthFirstTraverse(VehicleRegion root, WaterRegionEntryPredicate entryCondition, WaterRegionProcessor regionProcessor, int maxRegions = 999999, RegionType traversableRegionTypes = RegionType.Set_Passable)
        {
            if (freeWorkers.Count == 0)
            {
                Log.Error("No free workers for BFS. Either BFS recurred deeper than " + NumWorkers + ", or a bug has put this system in an inconsistent state. Resetting.");
                return;
            }
            if (root is null)
            {
                Log.Error("BFS with null root region.");
                return;
            }
            BFSWorker bfsworker = freeWorkers.Dequeue();

            try
            {
                bfsworker.BreadthFirstTraverseWork(root, entryCondition, regionProcessor, maxRegions, traversableRegionTypes);
            }
            catch (Exception ex)
            {
                Log.Error("Exception in BreadthFirstTraverse: " + ex.ToString());
            }
            finally
            {
                bfsworker.Clear();
                freeWorkers.Enqueue(bfsworker);
            }
        }
Exemplo n.º 2
0
        //FloodAndSetRooms

        //FloodAndSetNewRegionIndex

        public static bool WithinRegions(this IntVec3 A, IntVec3 B, Map map, int regionLookCount, TraverseParms traverseParams, RegionType traversableRegionTypes = RegionType.Set_Passable)
        {
            WaterRegion region = WaterGridsUtility.GetRegion(A, map, traversableRegionTypes);

            if (region is null)
            {
                return(false);
            }
            WaterRegion regB = WaterGridsUtility.GetRegion(B, map, traversableRegionTypes);

            if (regB is null)
            {
                return(false);
            }
            if (region == regB)
            {
                return(true);
            }
            WaterRegionEntryPredicate entryCondition = (WaterRegion from, WaterRegion r) => r.Allows(traverseParams, false);
            bool found = false;
            WaterRegionProcessor regionProcessor = delegate(WaterRegion r)
            {
                if (r == regB)
                {
                    found = true;
                    return(true);
                }
                return(false);
            };

            WaterRegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, regionLookCount, traversableRegionTypes);
            return(found);
        }
Exemplo n.º 3
0
 public static void MarkRegionsBFS(VehicleRegion root, WaterRegionEntryPredicate entryCondition, int maxRegions, int inRadiusMark, RegionType traversableRegionTypes = RegionType.Set_Passable)
 {
     BreadthFirstTraverse(root, entryCondition, delegate(VehicleRegion r)
     {
         r.mark = inRadiusMark;
         return(false);
     }, maxRegions, traversableRegionTypes);
 }
Exemplo n.º 4
0
        public static void BreadthFirstTraverse(IntVec3 start, Map map, WaterRegionEntryPredicate entryCondition, WaterRegionProcessor regionProcessor, int maxRegions = 999999, RegionType traversableRegionTypes = RegionType.Set_Passable)
        {
            VehicleRegion region = VehicleGridsUtility.GetRegion(start, map, traversableRegionTypes);

            if (region is null)
            {
                return;
            }
            BreadthFirstTraverse(region, entryCondition, regionProcessor, maxRegions, traversableRegionTypes);
        }
Exemplo n.º 5
0
        public bool CanReachUnfogged(IntVec3 c, TraverseParms traverseParms)
        {
            if (traverseParms.pawn != null)
            {
                if (!traverseParms.pawn.Spawned)
                {
                    return(false);
                }
                if (traverseParms.pawn.Map != this.map)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Called CanReachUnfogged() with a pawn spawned not on this map. This means that we can't check his reachability here. Pawn's current map should have been used instead of this one. pawn=",
                        traverseParms.pawn,
                        " pawn.Map=",
                        traverseParms.pawn.Map,
                        " map=",
                        this.map
                    }), false);
                    return(false);
                }
            }
            if (!c.InBoundsShip(this.map))
            {
                return(false);
            }
            if (!c.Fogged(this.map))
            {
                return(true);
            }
            WaterRegion region = WaterGridsUtility.GetRegion(c, this.map, RegionType.Set_Passable);

            if (region == null)
            {
                return(false);
            }
            WaterRegionEntryPredicate entryCondition = (WaterRegion from, WaterRegion r) => r.Allows(traverseParms, false);
            bool foundReg = false;
            WaterRegionProcessor regionProcessor = delegate(WaterRegion r)
            {
                if (!r.AnyCell.Fogged(this.map))
                {
                    foundReg = true;
                    return(true);
                }
                return(false);
            };

            WaterRegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, 9999, RegionType.Set_Passable);
            return(foundReg);
        }
Exemplo n.º 6
0
 public void BreadthFirstTraverseWork(VehicleRegion root, WaterRegionEntryPredicate entryCondition, WaterRegionProcessor regionProcessor, int maxRegions, RegionType traversableRegionTypes)
 {
     if ((root.type & traversableRegionTypes) == RegionType.None)
     {
         return;
     }
     closedIndex += 1u;
     open.Clear();
     numRegionsProcessed = 0;
     QueueNewOpenRegion(root);
     while (open.Count > 0)
     {
         VehicleRegion region = open.Dequeue();
         if (VehicleHarmony.debug)
         {
             region.Debug_Notify_Traversed();
         }
         if (!(regionProcessor is null) && regionProcessor(region))
         {
             FinalizeSearch();
             return;
         }
         if (ShouldCountRegion(region))
         {
             numRegionsProcessed++;
         }
         if (numRegionsProcessed >= maxRegions)
         {
             FinalizeSearch();
             return;
         }
         for (int i = 0; i < region.links.Count; i++)
         {
             VehicleRegionLink regionLink = region.links[i];
             for (int j = 0; j < 2; j++)
             {
                 VehicleRegion region2 = regionLink.regions[j];
                 if (!(region2 is null) && region2.closedIndex[closedArrayPos] != closedIndex && (region2.type & traversableRegionTypes) != RegionType.None &&
                     (entryCondition is null || entryCondition(region, region2)))
                 {
                     QueueNewOpenRegion(region2);
                 }
             }
         }
     }
     FinalizeSearch();
 }