public static void DoClamor(Thing source, IntVec3 position, float radius, ClamorDef type) { if (source.MapHeld == null) { return; } Region region = position.GetRegion(source.MapHeld); if (region == null) { return; } RegionTraverser.BreadthFirstTraverse(region, (Region from, Region r) => r.door == null || r.door.Open, delegate(Region r) { List <Thing> list = r.ListerThings.ThingsInGroup(ThingRequestGroup.Pawn); for (int i = 0; i < list.Count; i++) { Pawn pawn = list[i] as Pawn; float num = Mathf.Clamp01(pawn.health.capacities.GetLevel(PawnCapacityDefOf.Hearing)); if (num > 0f && pawn.Position.InHorDistOf(position, radius * num)) { pawn.HearClamor(source, type); } } return(false); }, 15); }
public static bool WithinRegions(this IntVec3 A, IntVec3 B, Map map, int regionLookCount, TraverseParms traverseParams, RegionType traversableRegionTypes = RegionType.Set_Passable) { Region region = A.GetRegion(map, traversableRegionTypes); if (region == null) { return(false); } Region regB = B.GetRegion(map, traversableRegionTypes); if (regB == null) { return(false); } if (region == regB) { return(true); } RegionEntryPredicate entryCondition = (Region from, Region r) => r.Allows(traverseParams, isDestination: false); bool found = false; RegionProcessor regionProcessor = delegate(Region r) { if (r == regB) { found = true; return(true); } return(false); }; BreadthFirstTraverse(region, entryCondition, regionProcessor, regionLookCount, traversableRegionTypes); return(found); }
public static void BreadthFirstTraverse(IntVec3 start, Map map, RegionEntryPredicate entryCondition, RegionProcessor regionProcessor, int maxRegions = 999999, RegionType traversableRegionTypes = RegionType.Set_Passable) { Region region = start.GetRegion(map, traversableRegionTypes); if (region != null) { BreadthFirstTraverse(region, entryCondition, regionProcessor, maxRegions, traversableRegionTypes); } }
public bool CanReachMapEdge(IntVec3 c, TraverseParms traverseParms) { if (traverseParms.pawn != null) { if (!traverseParms.pawn.Spawned) { return(false); } if (traverseParms.pawn.Map != this.map) { Log.Error(string.Concat(new object[] { "Called CanReachMapEdge() with a pawn spawned not on this map. This means that we can't check his reachability here. Pawn's current map should have been used instead of this one. pawn=", traverseParms.pawn, " pawn.Map=", traverseParms.pawn.Map, " map=", this.map }), false); return(false); } } Region region = c.GetRegion(this.map, RegionType.Set_Passable); bool result; if (region == null) { result = false; } else if (region.Room.TouchesMapEdge) { result = true; } else { RegionEntryPredicate entryCondition = (Region from, Region r) => r.Allows(traverseParms, false); bool foundReg = false; RegionProcessor regionProcessor = delegate(Region r) { bool result2; if (r.Room.TouchesMapEdge) { foundReg = true; result2 = true; } else { result2 = false; } return(result2); }; RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, 9999, RegionType.Set_Passable); result = foundReg; } return(result); }
private void MarkDirty(IntVec3 c) { this.Drawer.SetDirty(); Region region = c.GetRegion(this.Map, RegionType.Set_All); if (region != null) { region.Notify_AreaChanged(this); } }
public static Danger GetDangerFor(this IntVec3 c, Pawn p, Map map) { Map mapHeld = p.MapHeld; if (mapHeld == null || mapHeld != map) { return(Danger.None); } return(c.GetRegion(mapHeld, RegionType.Set_All)?.DangerFor(p) ?? Danger.None); }
public static Thing RegionwiseBFSWorker(IntVec3 root, Map map, ThingRequest req, PathEndMode peMode, TraverseParms traverseParams, Predicate <Thing> validator, Func <Thing, float> priorityGetter, int minRegions, int maxRegions, float maxDistance, RegionType traversableRegionTypes = RegionType.Set_Passable, bool ignoreEntirelyForbiddenRegions = false) { if (traverseParams.mode == TraverseMode.PassAllDestroyableThings) { Log.Error("RegionwiseBFSWorker with traverseParams.mode PassAllDestroyableThings. Use ClosestThingGlobal."); return(null); } Region region = root.GetRegion(map, traversableRegionTypes); if (region == null) { return(null); } float maxDistSquared = maxDistance * maxDistance; RegionEntryPredicate entryCondition = (Region from, Region to) => to.Allows(traverseParams, false) && (maxDistance > 5000f || to.extentsClose.ClosestDistSquaredTo(root) < maxDistSquared); Thing closestThing = null; float closestDistSquared = 9999999f; float bestPrio = -3.40282347E+38f; int regionsSeen = 0; RegionProcessor regionProcessor = delegate(Region r) { if (r.portal == null && !r.Allows(traverseParams, true)) { return(false); } if (!ignoreEntirelyForbiddenRegions || !r.IsForbiddenEntirely(traverseParams.pawn)) { List <Thing> list = r.ListerThings.ThingsMatching(req); for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; if (ReachabilityWithinRegion.ThingFromRegionListerReachable(thing, r, peMode, traverseParams.pawn)) { float num = (priorityGetter == null) ? 0f : priorityGetter(thing); if (num >= bestPrio) { float num2 = (float)(thing.Position - root).LengthHorizontalSquared; if ((num > bestPrio || num2 < closestDistSquared) && num2 < maxDistSquared && (validator == null || validator(thing))) { closestThing = thing; closestDistSquared = num2; bestPrio = num; } } } } } regionsSeen++; return(regionsSeen >= minRegions && closestThing != null); }; RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, maxRegions, traversableRegionTypes); return(closestThing); }
public bool CanReachUnfogged(IntVec3 c, TraverseParms traverseParms) { if (traverseParms.pawn != null) { if (!traverseParms.pawn.Spawned) { return(false); } if (traverseParms.pawn.Map != this.map) { Log.Error(string.Concat(new object[] { "Called CanReachUnfogged() with a pawn spawned not on this map. This means that we can't check his reachability here. Pawn's current map should have been used instead of this one. pawn=", traverseParms.pawn, " pawn.Map=", traverseParms.pawn.Map, " map=", this.map })); return(false); } } if (!c.InBounds(this.map)) { return(false); } if (!c.Fogged(this.map)) { return(true); } Region region = c.GetRegion(this.map, RegionType.Set_Passable); if (region == null) { return(false); } RegionEntryPredicate entryCondition = (Region from, Region r) => r.Allows(traverseParms, false); bool foundReg = false; RegionProcessor regionProcessor = delegate(Region r) { if (!r.AnyCell.Fogged(this.map)) { foundReg = true; return(true); } return(false); }; RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, 9999, RegionType.Set_Passable); return(foundReg); }
public static bool CanFleeToLocation(Pawn pawn, IntVec3 location) { if (!location.Standable(pawn.Map)) { return(false); } if (!pawn.Map.pawnDestinationReservationManager.CanReserve(location, pawn, false)) { return(false); } Region region = location.GetRegion(pawn.Map, RegionType.Set_Passable); return(region.type != RegionType.Portal && pawn.CanReach(location, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)); }
public static Danger GetDangerFor(this IntVec3 c, Pawn p, Map map) { Map mapHeld = p.MapHeld; if (mapHeld != null && mapHeld == map) { Region region = c.GetRegion(mapHeld, RegionType.Set_All); if (region == null) { return(Danger.None); } return(region.DangerFor(p)); } return(Danger.None); }
private void RegenerateNewRegionsFromDirtyCells() { newRegions.Clear(); List <IntVec3> dirtyCells = map.regionDirtyer.DirtyCells; for (int i = 0; i < dirtyCells.Count; i++) { IntVec3 intVec = dirtyCells[i]; if (intVec.GetRegion(map, RegionType.Set_All) == null) { Region region = map.regionMaker.TryGenerateRegionFrom(intVec); if (region != null) { newRegions.Add(region); } } } }
public static bool TryFindRandomReachableCellNear(IntVec3 root, Map map, float radius, TraverseParms traverseParms, Predicate <IntVec3> cellValidator, Predicate <Region> regionValidator, out IntVec3 result, int maxRegions = 999999) { bool result2; if (map == null) { Log.ErrorOnce("Tried to find reachable cell in a null map", 61037855, false); result = IntVec3.Invalid; result2 = false; } else { Region region = root.GetRegion(map, RegionType.Set_Passable); if (region == null) { result = IntVec3.Invalid; result2 = false; } else { CellFinder.workingRegions.Clear(); float radSquared = radius * radius; RegionTraverser.BreadthFirstTraverse(region, (Region from, Region r) => r.Allows(traverseParms, true) && (radius > 1000f || r.extentsClose.ClosestDistSquaredTo(root) <= radSquared) && (regionValidator == null || regionValidator(r)), delegate(Region r) { CellFinder.workingRegions.Add(r); return(false); }, maxRegions, RegionType.Set_Passable); while (CellFinder.workingRegions.Count > 0) { Region region2 = CellFinder.workingRegions.RandomElementByWeight((Region r) => (float)r.CellCount); if (region2.TryFindRandomCellInRegion((IntVec3 c) => (float)(c - root).LengthHorizontalSquared <= radSquared && (cellValidator == null || cellValidator(c)), out result)) { CellFinder.workingRegions.Clear(); return(true); } CellFinder.workingRegions.Remove(region2); } result = IntVec3.Invalid; CellFinder.workingRegions.Clear(); result2 = false; } } return(result2); }
public static bool WithinRegions(this IntVec3 A, IntVec3 B, Map map, int regionLookCount, TraverseParms traverseParams, RegionType traversableRegionTypes = RegionType.Set_Passable) { Region region = A.GetRegion(map, traversableRegionTypes); bool result; if (region == null) { result = false; } else { Region regB = B.GetRegion(map, traversableRegionTypes); if (regB == null) { result = false; } else if (region == regB) { result = true; } else { RegionEntryPredicate entryCondition = (Region from, Region r) => r.Allows(traverseParams, false); bool found = false; RegionProcessor regionProcessor = delegate(Region r) { bool result2; if (r == regB) { found = true; result2 = true; } else { result2 = false; } return(result2); }; RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, regionLookCount, traversableRegionTypes); result = found; } } return(result); }
public bool CanReachUnfogged(IntVec3 c, TraverseParms traverseParms) { if (traverseParms.pawn != null) { if (!traverseParms.pawn.Spawned) { return(false); } if (traverseParms.pawn.Map != map) { Log.Error("Called CanReachUnfogged() with a pawn spawned not on this map. This means that we can't check his 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 (!c.InBounds(map)) { return(false); } if (!c.Fogged(map)) { return(true); } Region region = c.GetRegion(map); if (region == null) { return(false); } RegionEntryPredicate entryCondition = (Region from, Region r) => r.Allows(traverseParms, isDestination: false); bool foundReg = false; RegionProcessor regionProcessor = delegate(Region r) { if (!r.AnyCell.Fogged(map)) { foundReg = true; return(true); } return(false); }; RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, 9999); return(foundReg); }
public static bool CanFleeToLocation(Pawn pawn, IntVec3 location) { if (!location.Standable(pawn.Map)) { return(false); } if (!pawn.Map.pawnDestinationReservationManager.CanReserve(location, pawn)) { return(false); } if (location.GetRegion(pawn.Map).type == RegionType.Portal) { return(false); } if (!pawn.CanReach(location, PathEndMode.OnCell, Danger.Deadly)) { return(false); } return(true); }
public bool CanReachMapEdge(IntVec3 c, TraverseParms traverseParms) { if (traverseParms.pawn != null) { if (!traverseParms.pawn.Spawned) { return(false); } if (traverseParms.pawn.Map != map) { Log.Error(string.Concat("Called CanReachMapEdge() with a pawn spawned not on this map. This means that we can't check his 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); } } Region region = c.GetRegion(map); if (region == null) { return(false); } if (region.Room.TouchesMapEdge) { return(true); } RegionEntryPredicate entryCondition = (Region from, Region r) => r.Allows(traverseParms, isDestination: false); bool foundReg = false; RegionProcessor regionProcessor = delegate(Region r) { if (r.Room.TouchesMapEdge) { foundReg = true; return(true); } return(false); }; RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, 9999); return(foundReg); }
public static Danger GetDangerFor(this IntVec3 c, Pawn p, Map map) { Map mapHeld = p.MapHeld; Danger result; if (mapHeld == null || mapHeld != map) { result = Danger.None; } else { Region region = c.GetRegion(mapHeld, RegionType.Set_All); if (region == null) { result = Danger.None; } else { result = region.DangerFor(p); } } return(result); }
public static bool WithinRegions(this IntVec3 A, IntVec3 B, Map map, int regionLookCount, TraverseParms traverseParams, RegionType traversableRegionTypes = RegionType.Set_Passable) { if (traverseParams.mode == TraverseMode.PassAllDestroyableThings) { throw new ArgumentException("traverseParams (PassAllDestroyableThings not supported)"); } Region region = A.GetRegion(map, traversableRegionTypes); if (region == null) { return(false); } Region regB = B.GetRegion(map, traversableRegionTypes); if (regB == null) { return(false); } if (region == regB) { return(true); } RegionEntryPredicate entryCondition = (Region from, Region r) => r.Allows(traverseParams, false); bool found = false; RegionProcessor regionProcessor = delegate(Region r) { if (r == regB) { found = true; return(true); } return(false); }; RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, regionLookCount, traversableRegionTypes); return(found); }
public static RegionType GetRegionType(this IntVec3 c, Map map) { return(c.GetRegion(map, RegionType.Set_All)?.type ?? RegionType.None); }
private void MarkDirty(IntVec3 c) { Drawer.SetDirty(); c.GetRegion(Map, RegionType.Set_All)?.Notify_AreaChanged(this); }
private void RegenerateEqualizationData() { thickRoofCoverage = 0f; noRoofCoverage = 0f; equalizeCells.Clear(); if (roomGroup.RoomCount != 0) { Map map = Map; if (!roomGroup.UsesOutdoorTemperature) { int num = 0; foreach (IntVec3 cell in roomGroup.Cells) { RoofDef roof = cell.GetRoof(map); if (roof == null) { noRoofCoverage += 1f; } else if (roof.isThickRoof) { thickRoofCoverage += 1f; } num++; } thickRoofCoverage /= num; noRoofCoverage /= num; foreach (IntVec3 cell2 in roomGroup.Cells) { for (int i = 0; i < 4; i++) { IntVec3 intVec = cell2 + GenAdj.CardinalDirections[i]; IntVec3 intVec2 = cell2 + GenAdj.CardinalDirections[i] * 2; if (intVec.InBounds(map)) { Region region = intVec.GetRegion(map); if (region != null) { if (region.type != RegionType.Portal) { continue; } bool flag = false; for (int j = 0; j < region.links.Count; j++) { Region regionA = region.links[j].RegionA; Region regionB = region.links[j].RegionB; if (regionA.Room.Group != roomGroup && !regionA.IsDoorway) { flag = true; break; } if (regionB.Room.Group != roomGroup && !regionB.IsDoorway) { flag = true; break; } } if (flag) { continue; } } } if (intVec2.InBounds(map) && intVec2.GetRoomGroup(map) != roomGroup) { bool flag2 = false; for (int k = 0; k < 4; k++) { if ((intVec2 + GenAdj.CardinalDirections[k]).GetRoomGroup(map) == roomGroup) { flag2 = true; break; } } if (!flag2) { equalizeCells.Add(intVec2); } } } } equalizeCells.Shuffle(); } } }
public static Thing RegionwiseBFSWorker(IntVec3 root, Map map, ThingRequest req, PathEndMode peMode, TraverseParms traverseParams, Predicate <Thing> validator, Func <Thing, float> priorityGetter, int minRegions, int maxRegions, float maxDistance, out int regionsSeen, RegionType traversableRegionTypes = RegionType.Set_Passable, bool ignoreEntirelyForbiddenRegions = false) { regionsSeen = 0; if (traverseParams.mode == TraverseMode.PassAllDestroyableThings) { Log.Error("RegionwiseBFSWorker with traverseParams.mode PassAllDestroyableThings. Use ClosestThingGlobal."); return(null); } if (traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater) { Log.Error("RegionwiseBFSWorker with traverseParams.mode PassAllDestroyableThingsNotWater. Use ClosestThingGlobal."); return(null); } if (!req.IsUndefined && !req.CanBeFoundInRegion) { Log.ErrorOnce(string.Concat("RegionwiseBFSWorker with thing request group ", req.group, ". This group is never stored in regions. Most likely a global search should have been used."), 385766189); return(null); } Region region = root.GetRegion(map, traversableRegionTypes); if (region == null) { return(null); } float maxDistSquared = maxDistance * maxDistance; RegionEntryPredicate entryCondition = delegate(Region from, Region to) { if (!to.Allows(traverseParams, isDestination: false)) { return(false); } return(maxDistance > 5000f || to.extentsClose.ClosestDistSquaredTo(root) < maxDistSquared); }; Thing closestThing = null; float closestDistSquared = 9999999f; float bestPrio = float.MinValue; int regionsSeenScan = 0; RegionProcessor regionProcessor = delegate(Region r) { if (RegionTraverser.ShouldCountRegion(r)) { regionsSeenScan++; } if (!r.IsDoorway && !r.Allows(traverseParams, isDestination: true)) { return(false); } if (!ignoreEntirelyForbiddenRegions || !r.IsForbiddenEntirely(traverseParams.pawn)) { List <Thing> list = r.ListerThings.ThingsMatching(req); for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; if (ReachabilityWithinRegion.ThingFromRegionListerReachable(thing, r, peMode, traverseParams.pawn)) { float num = ((priorityGetter != null) ? priorityGetter(thing) : 0f); if (!(num < bestPrio)) { float num2 = (thing.Position - root).LengthHorizontalSquared; if ((num > bestPrio || num2 < closestDistSquared) && num2 < maxDistSquared && (validator == null || validator(thing))) { closestThing = thing; closestDistSquared = num2; bestPrio = num; } } } } } return(regionsSeenScan >= minRegions && closestThing != null); }; RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, maxRegions, traversableRegionTypes); regionsSeen = regionsSeenScan; return(closestThing); }
private void RegenerateEqualizationData() { this.thickRoofCoverage = 0f; this.noRoofCoverage = 0f; this.equalizeCells.Clear(); if (this.roomGroup.RoomCount != 0) { Map map = this.Map; if (!this.roomGroup.UsesOutdoorTemperature) { int num = 0; foreach (IntVec3 cell in this.roomGroup.Cells) { RoofDef roof = cell.GetRoof(map); if (roof == null) { this.noRoofCoverage += 1f; } else if (roof.isThickRoof) { this.thickRoofCoverage += 1f; } num++; } this.thickRoofCoverage /= (float)num; this.noRoofCoverage /= (float)num; foreach (IntVec3 cell2 in this.roomGroup.Cells) { for (int i = 0; i < 4; i++) { IntVec3 intVec = cell2 + GenAdj.CardinalDirections[i]; IntVec3 intVec2 = cell2 + GenAdj.CardinalDirections[i] * 2; if (intVec.InBounds(map)) { Region region = intVec.GetRegion(map, RegionType.Set_Passable); if (region != null) { if (region.type == RegionType.Portal) { bool flag = false; for (int j = 0; j < region.links.Count; j++) { Region regionA = region.links[j].RegionA; Region regionB = region.links[j].RegionB; if (regionA.Room.Group != this.roomGroup && regionA.portal == null) { flag = true; break; } if (regionB.Room.Group != this.roomGroup && regionB.portal == null) { flag = true; break; } } if (!flag) { goto IL_0234; } } continue; } } goto IL_0234; IL_0234: if (intVec2.InBounds(map)) { RoomGroup roomGroup = intVec2.GetRoomGroup(map); if (roomGroup != this.roomGroup) { bool flag2 = false; for (int k = 0; k < 4; k++) { IntVec3 loc = intVec2 + GenAdj.CardinalDirections[k]; if (loc.GetRoomGroup(map) == this.roomGroup) { flag2 = true; break; } } if (!flag2) { this.equalizeCells.Add(intVec2); } } } } } this.equalizeCells.Shuffle(); } } }
public static RegionType GetRegionType(this IntVec3 c, Map map) { Region region = c.GetRegion(map, RegionType.Set_All); return((region == null) ? RegionType.None : region.type); }