Ejemplo n.º 1
0
 protected virtual bool TryFindScatterCell(Map map, out IntVec3 result)
 {
     if (this.nearMapCenter)
     {
         if (RCellFinder.TryFindRandomCellNearWith(map.Center, (IntVec3 x) => this.CanScatterAt(x, map), map, out result, 3, 2147483647))
         {
             return(true);
         }
     }
     else
     {
         if (this.nearPlayerStart)
         {
             result = CellFinder.RandomClosewalkCellNear(MapGenerator.PlayerStartSpot, map, 20, (IntVec3 x) => this.CanScatterAt(x, map));
             return(true);
         }
         if (CellFinderLoose.TryFindRandomNotEdgeCellWith(5, (IntVec3 x) => this.CanScatterAt(x, map), map, out result))
         {
             return(true);
         }
     }
     if (this.warnOnFail)
     {
         Log.Warning("Scatterer " + this.ToString() + " could not find cell to generate at.", false);
     }
     return(false);
 }
Ejemplo n.º 2
0
        public static IntVec3 TryFindCentralCell(Map map, int tightness, int minCellCount, Predicate <IntVec3> extraValidator = null)
        {
            int debug_numStand            = 0;
            int debug_numRoom             = 0;
            int debug_numTouch            = 0;
            int debug_numRoomCellCount    = 0;
            int debug_numExtraValidator   = 0;
            Predicate <IntVec3> validator = delegate(IntVec3 c)
            {
                if (!c.Standable(map))
                {
                    debug_numStand++;
                    return(false);
                }
                Room room = c.GetRoom(map, RegionType.Set_Passable);
                if (room == null)
                {
                    debug_numRoom++;
                    return(false);
                }
                if (!room.TouchesMapEdge)
                {
                    debug_numTouch++;
                    return(false);
                }
                if (room.CellCount < minCellCount)
                {
                    debug_numRoomCellCount++;
                    return(false);
                }
                if (extraValidator != null && !extraValidator(c))
                {
                    debug_numExtraValidator++;
                    return(false);
                }
                return(true);
            };

            for (int num = tightness; num >= 1; num--)
            {
                IntVec3 size            = map.Size;
                int     num2            = size.x / num;
                IntVec3 size2           = map.Size;
                int     minEdgeDistance = (size2.x - num2) / 2;
                IntVec3 result          = default(IntVec3);
                if (CellFinderLoose.TryFindRandomNotEdgeCellWith(minEdgeDistance, validator, map, out result))
                {
                    return(result);
                }
            }
            Log.Error("Found no good central spot. Choosing randomly. numStand=" + debug_numStand + ", numRoom=" + debug_numRoom + ", numTouch=" + debug_numTouch + ", numRoomCellCount=" + debug_numRoomCellCount + ", numExtraValidator=" + debug_numExtraValidator);
            return(CellFinderLoose.RandomCellWith((IntVec3 x) => x.Standable(map), map, 1000));
        }
Ejemplo n.º 3
0
        public static bool TryFindSkyfallerCell(ThingDef skyfaller, Map map, out IntVec3 cell, int minDistToEdge = 10, IntVec3 nearLoc = default(IntVec3), int nearLocMaxDist = -1, bool allowRoofedCells = true, bool allowCellsWithItems = false, bool allowCellsWithBuildings = false, bool colonyReachable = false, Predicate <IntVec3> extraValidator = null)
        {
            Predicate <IntVec3> validator = delegate(IntVec3 x)
            {
                CellRect.CellRectIterator iterator = GenAdj.OccupiedRect(x, Rot4.North, skyfaller.size).GetIterator();
                while (!iterator.Done())
                {
                    IntVec3 current = iterator.Current;
                    if (current.InBounds(map) && !current.Fogged(map) && current.Standable(map) && (!current.Roofed(map) || !current.GetRoof(map).isThickRoof))
                    {
                        if (!allowRoofedCells && current.Roofed(map))
                        {
                            return(false);
                        }
                        if (!allowCellsWithItems && current.GetFirstItem(map) != null)
                        {
                            return(false);
                        }
                        if (!allowCellsWithBuildings && current.GetFirstBuilding(map) != null)
                        {
                            return(false);
                        }
                        if (current.GetFirstSkyfaller(map) != null)
                        {
                            return(false);
                        }
                        iterator.MoveNext();
                        continue;
                    }
                    return(false);
                }
                if (minDistToEdge > 0 && x.DistanceToEdge(map) < minDistToEdge)
                {
                    return(false);
                }
                if (colonyReachable && !map.reachability.CanReachColony(x))
                {
                    return(false);
                }
                if (extraValidator != null && !extraValidator(x))
                {
                    return(false);
                }
                return(true);
            };

            if (nearLocMaxDist > 0)
            {
                return(CellFinder.TryFindRandomCellNear(nearLoc, map, nearLocMaxDist, validator, out cell));
            }
            return(CellFinderLoose.TryFindRandomNotEdgeCellWith(minDistToEdge, validator, map, out cell));
        }
Ejemplo n.º 4
0
        public static bool TryFindSkyfallerCell(ThingDef skyfaller, Map map, out IntVec3 cell, int minDistToEdge = 10, IntVec3 nearLoc = default(IntVec3), int nearLocMaxDist = -1, bool allowRoofedCells = true, bool allowCellsWithItems = false, bool allowCellsWithBuildings = false, bool colonyReachable = false, bool avoidColonistsIfExplosive = true, bool alwaysAvoidColonists = false, Predicate <IntVec3> extraValidator = null)
        {
            bool avoidColonists           = (avoidColonistsIfExplosive && skyfaller.skyfaller.CausesExplosion) || alwaysAvoidColonists;
            Predicate <IntVec3> validator = delegate(IntVec3 x)
            {
                CellRect.CellRectIterator iterator = GenAdj.OccupiedRect(x, Rot4.North, skyfaller.size).GetIterator();
                while (!iterator.Done())
                {
                    IntVec3 c = iterator.Current;
                    bool    result2;
                    if (!c.InBounds(map) || c.Fogged(map) || !c.Standable(map) || (c.Roofed(map) && c.GetRoof(map).isThickRoof))
                    {
                        result2 = false;
                    }
                    else if (!allowRoofedCells && c.Roofed(map))
                    {
                        result2 = false;
                    }
                    else if (!allowCellsWithItems && c.GetFirstItem(map) != null)
                    {
                        result2 = false;
                    }
                    else if (!allowCellsWithBuildings && c.GetFirstBuilding(map) != null)
                    {
                        result2 = false;
                    }
                    else
                    {
                        if (c.GetFirstSkyfaller(map) == null)
                        {
                            iterator.MoveNext();
                            continue;
                        }
                        result2 = false;
                    }
                    return(result2);
                }
                return((!avoidColonists || !SkyfallerUtility.CanPossiblyFallOnColonist(skyfaller, x, map)) && (minDistToEdge <= 0 || x.DistanceToEdge(map) >= minDistToEdge) && (!colonyReachable || map.reachability.CanReachColony(x)) && (extraValidator == null || extraValidator(x)));
            };
            bool result;

            if (nearLocMaxDist > 0)
            {
                result = CellFinder.TryFindRandomCellNear(nearLoc, map, nearLocMaxDist, validator, out cell, -1);
            }
            else
            {
                result = CellFinderLoose.TryFindRandomNotEdgeCellWith(minDistToEdge, validator, map, out cell);
            }
            return(result);
        }
Ejemplo n.º 5
0
        public static IntVec3 TryFindCentralCell(Map map, int tightness, int minCellCount, Predicate <IntVec3> extraValidator = null)
        {
            int debug_numStand            = 0;
            int debug_numRoom             = 0;
            int debug_numTouch            = 0;
            int debug_numRoomCellCount    = 0;
            int debug_numExtraValidator   = 0;
            Predicate <IntVec3> validator = delegate(IntVec3 c)
            {
                if (!c.Standable(map))
                {
                    debug_numStand++;
                    return(false);
                }
                Room room = c.GetRoom(map, RegionType.Set_Passable);
                if (room == null)
                {
                    debug_numRoom++;
                    return(false);
                }
                if (!room.TouchesMapEdge)
                {
                    debug_numTouch++;
                    return(false);
                }
                if (room.CellCount < minCellCount)
                {
                    debug_numRoomCellCount++;
                    return(false);
                }
                if (extraValidator != null && !extraValidator(c))
                {
                    debug_numExtraValidator++;
                    return(false);
                }
                return(true);
            };

            for (int i = tightness; i >= 1; i--)
            {
                int     num             = map.Size.x / i;
                int     minEdgeDistance = (map.Size.x - num) / 2;
                IntVec3 result;
                if (CellFinderLoose.TryFindRandomNotEdgeCellWith(minEdgeDistance, validator, map, out result))
                {
                    return(result);
                }
            }
            Log.Error(string.Concat(new object[]
            {
                "Found no good central spot. Choosing randomly. numStand=",
                debug_numStand,
                ", numRoom=",
                debug_numRoom,
                ", numTouch=",
                debug_numTouch,
                ", numRoomCellCount=",
                debug_numRoomCellCount,
                ", numExtraValidator=",
                debug_numExtraValidator
            }), false);
            return(CellFinderLoose.RandomCellWith((IntVec3 x) => x.Standable(map), map, 1000));
        }