Exemplo n.º 1
0
 public void ConstructComponents()
 {
     VehiclePathGrid = new VehiclePathGrid(map);
     ShipPathFinder  = new VehiclePathFinder(map);
     ThreadedPathFinderConstrained = new VehiclePathFinder(map, false);
     VehicleReachability           = new VehicleReachability(map);
     VehicleRegionGrid             = new VehicleRegionGrid(map);
     VehicleRegionMaker            = new VehicleRegionMaker(map);
     VehicleRegionAndRoomUpdater   = new VehicleRegionAndRoomUpdater(map);
     VehicleRegionLinkDatabase     = new VehicleRegionLinkDatabase();
     VehicleRegionDirtyer          = new VehicleRegionDirtyer(map);
 }
        private List <int> PathableNeighborIndices(int index)
        {
            tmpPathableNeighborIndices.Clear();
            VehiclePathGrid pathGrid = mapE.VehiclePathGrid;
            int             x        = map.Size.x;
            bool            flag     = index % x > 0;
            bool            flag2    = index % x < x - 1;
            bool            flag3    = index >= x;
            bool            flag4    = index / x < map.Size.z - 1;

            if (flag3 && pathGrid.WalkableFast(index - x))
            {
                tmpPathableNeighborIndices.Add(index - x);
            }
            if (flag2 && pathGrid.WalkableFast(index + 1))
            {
                tmpPathableNeighborIndices.Add(index + 1);
            }
            if (flag && pathGrid.WalkableFast(index - 1))
            {
                tmpPathableNeighborIndices.Add(index - 1);
            }
            if (flag4 && pathGrid.WalkableFast(index + x))
            {
                tmpPathableNeighborIndices.Add(index + x);
            }
            bool flag5 = !flag || VehiclePathFinder.BlocksDiagonalMovement(map, index - 1);
            bool flag6 = !flag2 || VehiclePathFinder.BlocksDiagonalMovement(map, index + 1);

            if (flag3 && !VehiclePathFinder.BlocksDiagonalMovement(map, index - x))
            {
                if (!flag6 && pathGrid.WalkableFast(index - x + 1))
                {
                    tmpPathableNeighborIndices.Add(index - x + 1);
                }
                if (!flag5 && pathGrid.WalkableFast(index - x - 1))
                {
                    tmpPathableNeighborIndices.Add(index - x - 1);
                }
            }
            if (flag4 && !VehiclePathFinder.BlocksDiagonalMovement(map, index + x))
            {
                if (!flag6 && pathGrid.WalkableFast(index + x + 1))
                {
                    tmpPathableNeighborIndices.Add(index + x + 1);
                }
                if (!flag5 && pathGrid.WalkableFast(index + x - 1))
                {
                    tmpPathableNeighborIndices.Add(index + x - 1);
                }
            }
            return(tmpPathableNeighborIndices);
        }
Exemplo n.º 3
0
        private bool CheckCellBasedReachability(IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParms)
        {
            IntVec3 foundCell = IntVec3.Invalid;

            VehicleRegion[] directionRegionGrid = regionGrid.DirectGrid;
            VehiclePathGrid pathGrid            = map.GetCachedMapComponent <VehicleMapping>().VehiclePathGrid;
            CellIndices     cellIndices         = map.cellIndices;

            map.floodFiller.FloodFill(start, delegate(IntVec3 c)
            {
                int num = cellIndices.CellToIndex(c);
                if ((traverseParms.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParms.mode == TraverseMode.NoPassClosedDoorsOrWater) &&
                    c.GetTerrain(map).IsWater)
                {
                    return(false);
                }
                if (traverseParms.mode == TraverseMode.PassAllDestroyableThings || traverseParms.mode == TraverseMode.PassAllDestroyableThingsNotWater)
                {
                    if (!pathGrid.WalkableFast(num))
                    {
                        Building edifice = c.GetEdifice(map);
                        if (edifice is null || !VehiclePathFinder.IsDestroyable(edifice))
                        {
                            return(false);
                        }
                    }
                }
                else if (traverseParms.mode != TraverseMode.NoPassClosedDoorsOrWater)
                {
                    Log.ErrorOnce("Do not use this method for non-cell based modes!", 938476762);
                    if (!pathGrid.WalkableFast(num))
                    {
                        return(false);
                    }
                }
                VehicleRegion region = directionRegionGrid[num];
                return(region is null || region.Allows(traverseParms, false));
            }, delegate(IntVec3 c)
            {
                if (VehicleReachabilityImmediate.CanReachImmediateShip(c, dest, map, peMode, traverseParms.pawn))
                {
                    foundCell = c;
                    return(true);
                }
                return(false);
            }, int.MaxValue, false, null);

            if (foundCell.IsValid)
            {
                if (CanUseCache(traverseParms.mode))
                {
                    VehicleRegion validRegionAt = regionGrid.GetValidRegionAt(foundCell);
                    if (!(validRegionAt is null))
                    {
                        foreach (VehicleRegion startRegion in startingRegions)
                        {
                            cache.AddCachedResult(startRegion.Room, validRegionAt.Room, traverseParms, true);
                        }
                    }
                }
                return(true);
            }
            if (CanUseCache(traverseParms.mode))
            {
                foreach (VehicleRegion startRegion in startingRegions)
                {
                    foreach (VehicleRegion destRegion in destRegions)
                    {
                        cache.AddCachedResult(startRegion.Room, destRegion.Room, traverseParms, false);
                    }
                }
            }
            return(false);
        }
 public int GetRegionDistance(VehicleRegion region, out VehicleRegionLink minLink)
 {
     if (regionMinLink.TryGetValue(region.id, out minLink))
     {
         return(distances[minLink]);
     }
     while (queue.Count != 0)
     {
         RegionLinkQueueEntry regionLinkQueueEntry = queue.Pop();
         int num = distances[regionLinkQueueEntry.Link];
         if (regionLinkQueueEntry.Cost == num)
         {
             VehicleRegion otherRegion = regionLinkQueueEntry.Link.GetOtherRegion(regionLinkQueueEntry.From);
             if (!(otherRegion is null) && otherRegion.valid)
             {
                 int num2 = 0;
                 if (!(otherRegion.door is null))
                 {
                     num2 = VehiclePathFinder.GetBuildingCost(otherRegion.door, traverseParms, traverseParms.pawn);
                     if (num2 == int.MaxValue)
                     {
                         continue;
                     }
                     num2 += OctileDistance(1, 0);
                 }
                 int minPathCost = RegionMedianPathCost(otherRegion);
                 foreach (VehicleRegionLink regionLink in otherRegion.links)
                 {
                     if (regionLink != regionLinkQueueEntry.Link && regionLink.GetOtherRegion(otherRegion).type.Passable())
                     {
                         int num3 = (otherRegion.door is null) ? RegionLinkDistance(regionLinkQueueEntry.Link, regionLink, minPathCost) : num2;
                         num3 = Math.Max(num3, 1);
                         int num4 = num + num3;
                         int estimatedPathCost = MinimumRegionLinkDistance(destinationCell, regionLink) + num4;
                         if (distances.TryGetValue(regionLink, out int num5))
                         {
                             if (num4 < num5)
                             {
                                 distances[regionLink] = num4;
                                 queue.Push(new RegionLinkQueueEntry(otherRegion, regionLink, num4, estimatedPathCost));
                             }
                         }
                         else
                         {
                             distances.Add(regionLink, num4);
                             queue.Push(new RegionLinkQueueEntry(otherRegion, regionLink, num4, estimatedPathCost));
                         }
                     }
                 }
                 if (!regionMinLink.ContainsKey(otherRegion.id))
                 {
                     regionMinLink.Add(otherRegion.id, regionLinkQueueEntry.Link);
                     if (otherRegion == region)
                     {
                         minLink = regionLinkQueueEntry.Link;
                         return(regionLinkQueueEntry.Cost);
                     }
                 }
             }
         }
     }
     return(10000);
 }