public static void AddAllowedAdjacentRegions(LocalTargetInfo dest, TraverseParms traverseParams, Map map, List <VehicleRegion> regions)
 {
     GenAdj.GetAdjacentCorners(dest, out IntVec3 bl, out IntVec3 tl, out IntVec3 tr, out IntVec3 br);
     if (!dest.HasThing || (dest.Thing.def.size.x == 1 && dest.Thing.def.size.z == 1))
     {
         IntVec3 cell = dest.Cell;
         for (int i = 0; i < 8; i++)
         {
             IntVec3 intVec = GenAdj.AdjacentCells[i] + cell;
             if (intVec.InBoundsShip(map) && !TouchPathEndModeUtility.IsAdjacentCornerAndNotAllowed(intVec, bl, tl, tr, br, map))
             {
                 VehicleRegion region = VehicleGridsUtility.GetRegion(intVec, map, RegionType.Set_Passable);
                 if (region != null && region.Allows(traverseParams, true))
                 {
                     regions.Add(region);
                 }
             }
         }
     }
     else
     {
         List <IntVec3> list = GenAdjFast.AdjacentCells8Way(dest);
         for (int j = 0; j < list.Count; j++)
         {
             if (list[j].InBoundsShip(map) && !TouchPathEndModeUtility.IsAdjacentCornerAndNotAllowed(list[j], bl, tl, tr, br, map))
             {
                 VehicleRegion region2 = VehicleGridsUtility.GetRegion(list[j], map, RegionType.Set_Passable);
                 if (region2 != null && region2.Allows(traverseParams, true))
                 {
                     regions.Add(region2);
                 }
             }
         }
     }
 }
 public void Init(CellRect end, TraverseParms traverseParms, int moveTicksCardinal, int moveTicksDiagonal, ByteGrid avoidGrid, Area allowedArea, bool drafted, List <int> disallowedCorners)
 {
     this.moveTicksCardinal = moveTicksCardinal;
     this.moveTicksDiagonal = moveTicksDiagonal;
     endCell                   = end.CenterCell;
     cachedRegion              = null;
     cachedBestLink            = null;
     cachedSecondBestLink      = null;
     cachedBestLinkCost        = 0;
     cachedSecondBestLinkCost  = 0;
     cachedRegionIsDestination = false;
     regionGrid                = map.GetCachedMapComponent <VehicleMapping>().VehicleRegionGrid.DirectGrid;
     destRegions.Clear();
     if (end.Width == 1 && end.Height == 1)
     {
         VehicleRegion region = VehicleGridsUtility.GetRegion(endCell, map, RegionType.Set_Passable);
         if (region != null)
         {
             destRegions.Add(region);
         }
     }
     else
     {
         foreach (IntVec3 intVec in end)
         {
             if (intVec.InBoundsShip(map) && !disallowedCorners.Contains(map.cellIndices.CellToIndex(intVec)))
             {
                 VehicleRegion region2 = VehicleGridsUtility.GetRegion(intVec, map, RegionType.Set_Passable);
                 if (region2 != null)
                 {
                     if (region2.Allows(traverseParms, true))
                     {
                         destRegions.Add(region2);
                     }
                 }
             }
         }
     }
     if (destRegions.Count == 0)
     {
         Log.Error("Couldn't find any destination regions. This shouldn't ever happen because we've checked reachability.");
     }
     vehicleRegionCostCalculator.Init(end, destRegions, traverseParms, moveTicksCardinal, moveTicksDiagonal, avoidGrid, allowedArea, drafted);
 }
Beispiel #3
0
 private bool CheckRegionBasedReachability(TraverseParms traverseParms)
 {
     while (openQueue.Count > 0)
     {
         VehicleRegion region = openQueue.Dequeue();
         foreach (VehicleRegionLink regionLink in region.links)
         {
             for (int i = 0; i < 2; i++)
             {
                 VehicleRegion region2 = regionLink.regions[i];
                 if (!(region2 is null) && region2.reachedIndex != reachedIndex && region2.type.Passable())
                 {
                     if (region2.Allows(traverseParms, false))
                     {
                         if (destRegions.Contains(region2))
                         {
                             foreach (VehicleRegion startRegion in startingRegions)
                             {
                                 cache.AddCachedResult(startRegion.Room, region2.Room, traverseParms, true);
                             }
                             return(true);
                         }
                         QueueNewOpenRegion(region2);
                     }
                 }
             }
         }
     }
     foreach (VehicleRegion startRegion in startingRegions)
     {
         foreach (VehicleRegion destRegion in destRegions)
         {
             cache.AddCachedResult(startRegion.Room, destRegion.Room, traverseParms, false);
         }
     }
     return(false);
 }
Beispiel #4
0
        public bool CanReachShip(IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParms)
        {
            if (working)
            {
                Log.ErrorOnce("Called CanReach() while working for Ships. This should never happen. Suppressing further errors.", 7312233);
                return(false);
            }
            if (!map.terrainGrid.TerrainAt(dest.Cell).IsWater)
            {
                return(false);
            }
            if (!(traverseParms.pawn is null))
            {
                if (!traverseParms.pawn.Spawned)
                {
                    return(false);
                }
                if (traverseParms.pawn.Map != map)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Called CanReach() with a ship spawned not on this map. This means that we can't check its reachability here. Pawn's" +
                        "current map should have been used instead of this one. pawn=", traverseParms.pawn,
                        " pawn.Map=", traverseParms.pawn.Map,
                        " map=", map
                    }));
                    return(false);
                }
            }
            if (!dest.IsValid)
            {
                return(false);
            }
            if (dest.HasThing && dest.Thing.Map != map)
            {
                return(false);
            }
            if (!start.InBoundsShip(map) || !dest.Cell.InBoundsShip(map))
            {
                return(false);
            }
            if ((peMode == PathEndMode.OnCell || peMode == PathEndMode.Touch || peMode == PathEndMode.ClosestTouch) && traverseParms.mode != TraverseMode.NoPassClosedDoorsOrWater &&
                traverseParms.mode != TraverseMode.PassAllDestroyableThingsNotWater)
            {
                VehicleRoom room = VehicleRegionAndRoomQuery.RoomAtFast(start, map, RegionType.Set_Passable);
                if (!(room is null) && room == VehicleRegionAndRoomQuery.RoomAtFast(dest.Cell, map, RegionType.Set_Passable))
                {
                    return(true);
                }
            }
            if (traverseParms.mode == TraverseMode.PassAllDestroyableThings)
            {
                TraverseParms traverseParms2 = traverseParms;
                traverseParms.mode = TraverseMode.PassDoors;
                if (CanReachShip(start, dest, peMode, traverseParms2))
                {
                    return(true);
                }
            }
            dest    = (LocalTargetInfo)GenPathVehicles.ResolvePathMode(traverseParms.pawn, dest.ToTargetInfo(map), ref peMode);
            working = true;
            bool result;

            try
            {
                pathGrid      = map.GetCachedMapComponent <VehicleMapping>().VehiclePathGrid;
                regionGrid    = map.GetCachedMapComponent <VehicleMapping>().VehicleRegionGrid;
                reachedIndex += 1u;
                destRegions.Clear();
                if (peMode == PathEndMode.OnCell)
                {
                    VehicleRegion region = VehicleGridsUtility.GetRegion(dest.Cell, map, RegionType.Set_Passable);
                    if (!(region is null) && region.Allows(traverseParms, true))
                    {
                        destRegions.Add(region);
                    }
                }
                else if (peMode == PathEndMode.Touch)
                {
                    TouchPathEndModeUtilityVehicles.AddAllowedAdjacentRegions(dest, traverseParms, map, destRegions);
                }
                if (destRegions.Count == 0 && traverseParms.mode != TraverseMode.PassAllDestroyableThings && traverseParms.mode !=
                    TraverseMode.PassAllDestroyableThingsNotWater)
                {
                    FinalizeCheck();
                    result = false;
                }
                else
                {
                    destRegions.RemoveDuplicates();
                    openQueue.Clear();
                    numRegionsOpened = 0;
                    DetermineStartRegions(start);
                    if (openQueue.Count == 0 && traverseParms.mode != TraverseMode.PassAllDestroyableThings && traverseParms.mode !=
                        TraverseMode.PassAllDestroyableThingsNotWater)
                    {
                        FinalizeCheck();
                        result = false;
                    }
                    else
                    {
                        if (startingRegions.Any() && destRegions.Any() && CanUseCache(traverseParms.mode))
                        {
                            BoolUnknown cachedResult = GetCachedResult(traverseParms);
                            if (cachedResult == BoolUnknown.True)
                            {
                                FinalizeCheck();
                                return(true);
                            }
                            if (cachedResult == BoolUnknown.False)
                            {
                                FinalizeCheck();
                                return(false);
                            }
                        }
                        if (traverseParms.mode == TraverseMode.PassAllDestroyableThings || traverseParms.mode == TraverseMode.PassAllDestroyableThingsNotWater ||
                            traverseParms.mode == TraverseMode.NoPassClosedDoorsOrWater)
                        {
                            bool flag = CheckCellBasedReachability(start, dest, peMode, traverseParms);
                            FinalizeCheck();
                            result = flag;
                        }
                        else
                        {
                            bool flag2 = CheckRegionBasedReachability(traverseParms);
                            //bool flag2 = CheckCellBasedReachability(start, dest, peMode, traverseParms); //REDO?
                            FinalizeCheck();
                            result = flag2;
                        }
                    }
                }
            }
            finally
            {
                working = false;
            }
            return(result);
        }
Beispiel #5
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);
        }