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 current = iterator.Current; if (!current.InBounds(map) || current.Fogged(map) || !current.Standable(map) || (current.Roofed(map) && current.GetRoof(map).isThickRoof)) { return(false); } 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(); } if (avoidColonists && SkyfallerUtility.CanPossiblyFallOnColonist(skyfaller, x, map)) { 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(TryFindRandomNotEdgeCellWith(minDistToEdge, validator, map, out cell)); }
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) { foreach (IntVec3 item in GenAdj.OccupiedRect(x, Rot4.North, skyfaller.size)) { if (!item.InBounds(map) || item.Fogged(map) || !item.Standable(map) || (item.Roofed(map) && item.GetRoof(map).isThickRoof)) { return(false); } if (!allowRoofedCells && item.Roofed(map)) { return(false); } if (!allowCellsWithItems && item.GetFirstItem(map) != null) { return(false); } if (!allowCellsWithBuildings && item.GetFirstBuilding(map) != null) { return(false); } if (item.GetFirstSkyfaller(map) != null) { return(false); } foreach (Thing thing in item.GetThingList(map)) { if (thing.def.preventSkyfallersLandingOn) { return(false); } } } if (avoidColonists && SkyfallerUtility.CanPossiblyFallOnColonist(skyfaller, x, map)) { return(false); } if (minDistToEdge > 0 && x.DistanceToEdge(map) < minDistToEdge) { return(false); } if (colonyReachable && !map.reachability.CanReachColony(x)) { return(false); } return((extraValidator == null || extraValidator(x)) ? true : false); }; if (nearLocMaxDist > 0) { return(CellFinder.TryFindRandomCellNear(nearLoc, map, nearLocMaxDist, validator, out cell)); } return(TryFindRandomNotEdgeCellWith(minDistToEdge, validator, map, out cell)); }
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); }