public static bool IsCornerTouchAllowed(int cornerX, int cornerZ, int adjCardinal1X, int adjCardinal1Z, int adjCardinal2X, int adjCardinal2Z, Map map)
 {
     Building building = map.edificeGrid[new IntVec3(cornerX, 0, cornerZ)];
     if (!(building is null) && TouchPathEndModeUtilityShips.MakesOccupiedCellsAlwaysReachableDiagonally(building.def))
         return true;
     IntVec3 intVec = new IntVec3(adjCardinal1X, 0, adjCardinal1Z);
     IntVec3 intVec2 = new IntVec3(adjCardinal2X, 0, adjCardinal2Z);
     MapExtension mapE = MapExtensionUtility.GetExtensionToMap(map);
     return (mapE.getShipPathGrid.Walkable(intVec) && intVec.GetDoor(map) is null) || (mapE.getShipPathGrid.Walkable(intVec2) && intVec2.GetDoor(map) is null);
 }
 private bool CanMoveTo(IntVec3 pos)
 {
     return
         (pos.InBounds(Map) &&
          (
              !pos.Filled(Map) ||
              (pos.GetDoor(Map)?.Open ?? false) ||
              (pos.GetFirstThing <Building_Vent>(Map) is Building_Vent vent && vent.TryGetComp <CompFlickable>().SwitchIsOn)
          ));
 }
Пример #3
0
        private bool CausesStreet(IntVec3 c, TerrainDef floorDef)
        {
            Map map = BaseGen.globalSettings.map;

            if (!c.InBounds(map))
            {
                return(false);
            }
            Building edifice = c.GetEdifice(map);

            return((edifice != null && edifice.def == ThingDefOf.Wall) || c.GetDoor(map) != null || c.GetTerrain(map) == floorDef);
        }
Пример #4
0
 public static bool AnyDoorAdjacentCardinalTo(IntVec3 cell, Map map)
 {
     for (int i = 0; i < 4; i++)
     {
         IntVec3 c = cell + GenAdj.CardinalDirections[i];
         if (c.InBounds(map) && c.GetDoor(map) != null)
         {
             return(true);
         }
     }
     return(false);
 }
        public static bool IsCornerTouchAllowed(int cornerX, int cornerZ, int adjCardinal1X, int adjCardinal1Z, int adjCardinal2X, int adjCardinal2Z, Map map)
        {
            Building building = map.edificeGrid[new IntVec3(cornerX, 0, cornerZ)];

            if (building != null && TouchPathEndModeUtility.MakesOccupiedCellsAlwaysReachableDiagonally(building.def))
            {
                return(true);
            }
            IntVec3 intVec  = new IntVec3(adjCardinal1X, 0, adjCardinal1Z);
            IntVec3 intVec2 = new IntVec3(adjCardinal2X, 0, adjCardinal2Z);

            return((map.pathGrid.Walkable(intVec) && intVec.GetDoor(map) == null) || (map.pathGrid.Walkable(intVec2) && intVec2.GetDoor(map) == null));
        }
        public static bool IsCornerTouchAllowed(int cornerX, int cornerZ, int adjCardinal1X, int adjCardinal1Z, int adjCardinal2X, int adjCardinal2Z, Map map)
        {
            Building building = map.edificeGrid[new IntVec3(cornerX, 0, cornerZ)];

            if (!(building is null) && MakesOccupiedCellsAlwaysReachableDiagonally(building.def))
            {
                return(true);
            }
            IntVec3        intVec  = new IntVec3(adjCardinal1X, 0, adjCardinal1Z);
            IntVec3        intVec2 = new IntVec3(adjCardinal2X, 0, adjCardinal2Z);
            VehicleMapping mapE    = map.GetCachedMapComponent <VehicleMapping>();

            return((mapE.VehiclePathGrid.Walkable(intVec) && intVec.GetDoor(map) is null) || (mapE.VehiclePathGrid.Walkable(intVec2) && intVec2.GetDoor(map) is null));
        }
Пример #7
0
        private int GetDistanceToExistingDoors(IntVec3 cell, CellRect rect)
        {
            Map map = BaseGen.globalSettings.map;
            int num = 2147483647;

            foreach (IntVec3 edgeCell in rect.EdgeCells)
            {
                IntVec3 current = edgeCell;
                if (current.GetDoor(map) != null)
                {
                    num = Mathf.Min(num, Mathf.Abs(cell.x - current.x) + Mathf.Abs(cell.z - current.z));
                }
            }
            return(num);
        }
 public static RegionType GetExpectedRegionType(this IntVec3 c, Map map)
 {
     if (!c.InBoundsShip(map))
     {
         return(RegionType.None);
     }
     if (!(c.GetDoor(map) is null))
     {
         return(RegionType.Portal);
     }
     if (GenGridVehicles.Walkable(c, map.GetCachedMapComponent <VehicleMapping>()))
     {
         return(RegionType.Normal);
     }
     return(RegionType.ImpassableFreeAirExchange);
 }
Пример #9
0
 public static RegionType GetExpectedRegionType(this IntVec3 c, Map map)
 {
     if (!c.InBoundsShip(map))
     {
         return(RegionType.None);
     }
     if (!(c.GetDoor(map) is null))
     {
         return(RegionType.Portal);
     }
     if (GenGridShips.Walkable(c, MapExtensionUtility.GetExtensionToMap(map)))
     {
         return(RegionType.Normal);
     }
     return(RegionType.ImpassableFreeAirExchange);
 }
Пример #10
0
        public static bool TryFindBestPawnStandCell(ref bool __result, Pawn forPawn, out IntVec3 cell, bool cellByCell = false)
        {
            cell = IntVec3.Invalid;
            int   num1   = -1;
            float radius = 10f;
            Dictionary <IntVec3, float>   tmpDistances = new Dictionary <IntVec3, float>();
            Dictionary <IntVec3, IntVec3> tmpParents   = new Dictionary <IntVec3, IntVec3>();
            DijkstraIntVec3 dijkstraIntVec3            = new DijkstraIntVec3();

            while (true)
            {
                tmpDistances.Clear();
                tmpParents.Clear();
                dijkstraIntVec3.Run(forPawn.Position, (Func <IntVec3, IEnumerable <IntVec3> >)(x => GetAdjacentCardinalCellsForBestStandCell(x, radius, forPawn)), (Func <IntVec3, IntVec3, float>)((from, to) =>
                {
                    float num2 = 1f;
                    if (from.x != to.x && from.z != to.z)
                    {
                        num2 = 1.414214f;
                    }
                    if (!to.Standable(forPawn.Map))
                    {
                        num2 += 3f;
                    }
                    if (PawnUtility.AnyPawnBlockingPathAt(to, forPawn, false, false, false))
                    {
                        if (to.GetThingList(forPawn.Map).Find((Predicate <Thing>)(x => x is Pawn && x.HostileTo((Thing)forPawn))) != null)
                        {
                            num2 += 40f;
                        }
                        else
                        {
                            num2 += 15f;
                        }
                    }
                    if (to.GetEdifice(forPawn.Map) is Building_Door edifice && !edifice.FreePassage)
                    {
                        if (edifice.PawnCanOpen(forPawn))
                        {
                            num2 += 6f;
                        }
                        else
                        {
                            num2 += 50f;
                        }
                    }
                    return(num2);
                }), tmpDistances, tmpParents);
                if (tmpDistances.Count != num1)
                {
                    float num2 = 0.0f;
                    foreach (KeyValuePair <IntVec3, float> tmpDistance in tmpDistances)
                    {
                        if ((!cell.IsValid || (double)tmpDistance.Value < (double)num2) && (tmpDistance.Key.Walkable(forPawn.Map) && !PawnUtility.AnyPawnBlockingPathAt(tmpDistance.Key, forPawn, false, false, false)))
                        {
                            Building_Door door = tmpDistance.Key.GetDoor(forPawn.Map);
                            if (door == null || door.FreePassage)
                            {
                                cell = tmpDistance.Key;
                                num2 = tmpDistance.Value;
                            }
                        }
                    }
                    if (!cell.IsValid)
                    {
                        if ((double)radius <= (double)forPawn.Map.Size.x || (double)radius <= (double)forPawn.Map.Size.z)
                        {
                            radius *= 2f;
                            num1    = tmpDistances.Count;
                        }
                        else
                        {
                            goto label_23;
                        }
                    }
                    else
                    {
                        goto label_11;
                    }
                }
                else
                {
                    break;
                }
            }
            __result = false;
            return(false);

label_11:
            if (!cellByCell)
            {
                __result = true;
                return(false);
            }
            IntVec3 c    = cell;
            int     num3 = 0;

            while (c != null && c.IsValid && c != forPawn.Position)
            {
                ++num3;
                if (num3 >= 10000)
                {
                    Log.Error("Too many iterations.", false);
                    break;
                }
                if (c.Walkable(forPawn.Map))
                {
                    Building_Door door = c.GetDoor(forPawn.Map);
                    if (door == null || door.FreePassage)
                    {
                        cell = c;
                    }
                }
                if (!tmpParents.TryGetValue(c, out c))
                {
                    break;
                }
            }

            __result = true;
            return(false);

label_23:
            __result = false;
            return(false);
        }
Пример #11
0
        private static bool CanWanderToCell(IntVec3 c, Pawn pawn, IntVec3 root, Func <Pawn, IntVec3, IntVec3, bool> validator, int tryIndex, Danger maxDanger)
        {
            bool flag = false;

            if (!c.Walkable(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0f, "walk");
                }
                return(false);
            }
            if (c.IsForbidden(pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.25f, "forbid");
                }
                return(false);
            }
            if (tryIndex < 10 && !c.Standable(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.25f, "stand");
                }
                return(false);
            }
            if (!pawn.CanReach(c, PathEndMode.OnCell, maxDanger))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.6f, "reach");
                }
                return(false);
            }
            if (PawnUtility.KnownDangerAt(c, pawn.Map, pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.1f, "trap");
                }
                return(false);
            }
            if (tryIndex < 10)
            {
                if (c.GetTerrain(pawn.Map).avoidWander)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.39f, "terr");
                    }
                    return(false);
                }
                if (pawn.Map.pathGrid.PerceivedPathCostAt(c) > 20)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.4f, "pcost");
                    }
                    return(false);
                }
                if ((int)c.GetDangerFor(pawn, pawn.Map) > 1)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.4f, "danger");
                    }
                    return(false);
                }
            }
            else if (tryIndex < 15 && c.GetDangerFor(pawn, pawn.Map) == Danger.Deadly)
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.4f, "deadly");
                }
                return(false);
            }
            if (!pawn.Map.pawnDestinationReservationManager.CanReserve(c, pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.75f, "resvd");
                }
                return(false);
            }
            if (validator != null && !validator(pawn, c, root))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.15f, "valid");
                }
                return(false);
            }
            if (c.GetDoor(pawn.Map) != null)
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.32f, "door");
                }
                return(false);
            }
            if (c.ContainsStaticFire(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.9f, "fire");
                }
                return(false);
            }
            return(true);
        }
Пример #12
0
        private static bool CanWanderToCell(IntVec3 c, Pawn pawn, IntVec3 root, Func <Pawn, IntVec3, bool> validator, int tryIndex, Danger maxDanger)
        {
            bool flag = UnityData.isDebugBuild && DebugViewSettings.drawDestSearch;

            if (!c.Walkable(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0f, "walk", 50);
                }
                return(false);
            }
            if (c.IsForbidden(pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.25f, "forbid", 50);
                }
                return(false);
            }
            if (tryIndex < 10 && !c.Standable(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.25f, "stand", 50);
                }
                return(false);
            }
            if (!pawn.CanReach(c, PathEndMode.OnCell, maxDanger, false, TraverseMode.ByPawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.6f, "reach", 50);
                }
                return(false);
            }
            if (RCellFinder.ContainsKnownTrap(c, pawn.Map, pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.1f, "trap", 50);
                }
                return(false);
            }
            if (tryIndex < 10)
            {
                if (c.GetTerrain(pawn.Map).avoidWander)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.39f, "terr", 50);
                    }
                    return(false);
                }
                if (pawn.Map.pathGrid.PerceivedPathCostAt(c) > 20)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.4f, "pcost", 50);
                    }
                    return(false);
                }
                if ((int)c.GetDangerFor(pawn, pawn.Map) > 1)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.4f, "danger", 50);
                    }
                    return(false);
                }
            }
            else if (tryIndex < 15 && c.GetDangerFor(pawn, pawn.Map) == Danger.Deadly)
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.4f, "deadly", 50);
                }
                return(false);
            }
            if (!pawn.Map.pawnDestinationReservationManager.CanReserve(c, pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.75f, "resvd", 50);
                }
                return(false);
            }
            if (validator != null && !validator(pawn, c))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.15f, "valid", 50);
                }
                return(false);
            }
            if (c.GetDoor(pawn.Map) != null)
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.32f, "door", 50);
                }
                return(false);
            }
            if (c.ContainsStaticFire(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.9f, "fire", 50);
                }
                return(false);
            }
            return(true);
        }