public static IntVec3 RandomWanderDestFor(Pawn pawn, IntVec3 root, float radius, Func <Pawn, IntVec3, bool> validator, Danger maxDanger) { if (radius > 12.0) { Log.Warning("wanderRadius of " + radius + " is greater than Region.GridSize of " + 12 + " and will break."); } bool flag = UnityData.isDebugBuild && DebugViewSettings.drawDestSearch; if (root.GetRegion(pawn.Map, RegionType.Set_Passable) != null) { int maxRegions = Mathf.Max((int)radius / 3, 13); CellFinder.AllRegionsNear(RCellFinder.regions, root.GetRegion(pawn.Map, RegionType.Set_Passable), maxRegions, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), (Region reg) => reg.extentsClose.ClosestDistSquaredTo(root) <= radius * radius, null, RegionType.Set_Passable); if (flag) { pawn.Map.debugDrawer.FlashCell(root, 0.6f, "root", 50); } if (RCellFinder.regions.Count > 0) { for (int i = 0; i < 35; i++) { IntVec3 randomCell = RCellFinder.regions.RandomElementByWeight((Region reg) => (float)reg.CellCount).RandomCell; if ((float)randomCell.DistanceToSquared(root) > radius * radius) { if (flag) { pawn.Map.debugDrawer.FlashCell(randomCell, 0.32f, "distance", 50); } continue; } if (!RCellFinder.CanWanderToCell(randomCell, pawn, root, validator, i, maxDanger)) { if (flag) { pawn.Map.debugDrawer.FlashCell(randomCell, 0.6f, "validation", 50); } continue; } if (flag) { pawn.Map.debugDrawer.FlashCell(randomCell, 0.9f, "go!", 50); } return(randomCell); } } } IntVec3 position = default(IntVec3); if (!CellFinder.TryFindRandomCellNear(root, pawn.Map, Mathf.FloorToInt(radius), (Predicate <IntVec3>)((IntVec3 c) => c.InBounds(pawn.Map) && pawn.CanReach(c, PathEndMode.OnCell, Danger.None, false, TraverseMode.ByPawn) && !c.IsForbidden(pawn)), out position) && !CellFinder.TryFindRandomCellNear(root, pawn.Map, Mathf.FloorToInt(radius), (Predicate <IntVec3>)((IntVec3 c) => c.InBounds(pawn.Map) && pawn.CanReach(c, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)), out position) && !CellFinder.TryFindRandomCellNear(root, pawn.Map, 20, (Predicate <IntVec3>)((IntVec3 c) => c.InBounds(pawn.Map) && pawn.CanReach(c, PathEndMode.OnCell, Danger.None, false, TraverseMode.ByPawn) && !c.IsForbidden(pawn)), out position) && !CellFinder.TryFindRandomCellNear(root, pawn.Map, 30, (Predicate <IntVec3>)((IntVec3 c) => c.InBounds(pawn.Map) && pawn.CanReach(c, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)), out position) && !CellFinder.TryFindRandomCellNear(pawn.Position, pawn.Map, 5, (Predicate <IntVec3>)((IntVec3 c) => c.InBounds(pawn.Map) && pawn.CanReach(c, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)), out position)) { position = pawn.Position; } if (flag) { pawn.Map.debugDrawer.FlashCell(position, 0.4f, "fallback", 50); } return(position); }
private static Region ClosestRegionWithinTemperatureRange(IntVec3 root, Map map, FloatRange tempRange, TraverseParms traverseParms, RegionType traversableRegionTypes = RegionType.Set_Passable) { Region region = root.GetRegion(map, traversableRegionTypes); if (region == null) { return(null); } RegionEntryPredicate entryCondition = (Region from, Region r) => r.Allows(traverseParms, false); Region foundReg = null; RegionProcessor regionProcessor = delegate(Region r) { if (r.IsDoorway) { return(false); } if (tempRange.Includes(r.Room.Temperature)) { foundReg = r; return(true); } return(false); }; RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, 9999, traversableRegionTypes); return(foundReg); }
public static bool TradeableCellsAround(ref List <IntVec3> __result, IntVec3 pos, Map map) { if (!pos.InBounds(map)) { __result = new List <IntVec3>(); return(false); } Region region = pos.GetRegion(map); if (region == null) { __result = new List <IntVec3>(); return(false); } __result = new List <IntVec3>(); var result = __result; RegionTraverser.BreadthFirstTraverse(region, (from, r) => r.door == null, delegate(Region r) { result.AddRange(r.Cells.Where(item => item.InHorDistOf(pos, 30f))); return(false); }, 40); return(false); }
public List <IntVec3> MagNowCellsAround(IntVec3 pos, Map map, float nowrange) { var result = new List <IntVec3>(); if (!pos.InBounds(map)) { return(result); } var region = pos.GetRegion(map); if (region == null) { return(result); } RegionTraverser.BreadthFirstTraverse(region, (_, r) => r.door == null, delegate(Region r) { foreach (var item in r.Cells) { if (item.InHorDistOf(pos, nowrange) && !item.InHorDistOf(pos, nowrange - 1)) { result.Add(item); } } return(false); }, (int)nowrange); return(result); }
public List <IntVec3> VoltNowCellsAround(IntVec3 pos, Map map, float nowrange) { var result = new List <IntVec3>(); if (!pos.InBounds(map)) { return(result); } var region = pos.GetRegion(map); if (region == null) { return(result); } RegionTraverser.BreadthFirstTraverse(region, (_, r) => r.door == null, delegate(Region r) { foreach (var item in r.Cells) { float num1 = (item.x - pos.x) * (item.x - pos.x); float num2 = (item.z - pos.z) * (item.z - pos.z); var num3 = Mathf.Sqrt(num1 + num2); // Log.Warning(num3 + "/" + nowrange); if (num3 - 1f <= nowrange && num3 + 1f >= nowrange) { result.Add(item); } } return(false); }, (int)nowrange); return(result); }
public static List <IntVec3> TradeableCellsAround(IntVec3 pos, Map map) { Building_OrbitalTradeBeacon.tradeableCells.Clear(); if (!pos.InBounds(map)) { return(Building_OrbitalTradeBeacon.tradeableCells); } Region region = pos.GetRegion(map, RegionType.Set_Passable); if (region == null) { return(Building_OrbitalTradeBeacon.tradeableCells); } RegionTraverser.BreadthFirstTraverse(region, (Region from, Region r) => r.door == null, delegate(Region r) { foreach (IntVec3 item in r.Cells) { if (item.InHorDistOf(pos, 7.9f)) { Building_OrbitalTradeBeacon.tradeableCells.Add(item); } } return(false); }, 13, RegionType.Set_Passable); return(Building_OrbitalTradeBeacon.tradeableCells); }
private static Region ClosestRegionWithinTemperatureRange(IntVec3 root, Map map, TraverseParms traverseParms, RegionType traversableRegionTypes = RegionType.Set_Passable) { Region region = root.GetRegion(map, traversableRegionTypes); MapComp_Noise mapComp = map.GetComponent <MapComp_Noise>(); if (region == null || mapComp == null) { return(null); } RegionEntryPredicate entryCondition = (Region from, Region r) => r.Allows(traverseParms, false); Region foundReg = null; RegionProcessor regionProcessor = delegate(Region r) { if (r.IsDoorway) { return(false); } if (NoiseUtility.IsSilentEnough(region)) { foundReg = r; return(true); } return(false); }; RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, 9999, traversableRegionTypes); return(foundReg); }
public static List <IntVec3> PortableCellsAround(IntVec3 pos, Map map) { Building_TMArcaneCapacitor.portableCells.Clear(); if (!pos.InBounds(map)) { return(Building_TMArcaneCapacitor.portableCells); } Region region = pos.GetRegion(map, RegionType.Set_Passable); if (region == null) { return(Building_TMArcaneCapacitor.portableCells); } RegionTraverser.BreadthFirstTraverse(region, (Region from, Region r) => r.door == null, delegate(Region r) { foreach (IntVec3 current in r.Cells) { if (current.InHorDistOf(pos, Building_TMArcaneCapacitor.effectRadius)) { Building_TMArcaneCapacitor.portableCells.Add(current); } } return(false); }, 13, RegionType.Set_Passable); return(Building_TMArcaneCapacitor.portableCells); }
public static List <IntVec3> CurableCellsAround(IntVec3 pos, Map map) { Building_Curer.curableCells.Clear(); if (!pos.InBounds(map)) { return(Building_Curer.curableCells); } Region region = pos.GetRegion(map, RegionType.Set_Passable); if (region == null) { return(Building_Curer.curableCells); } RegionTraverser.BreadthFirstTraverse(region, (Region from, Region r) => r.door == null, delegate(Region r) { foreach (IntVec3 cell in r.Cells) { if (cell.InHorDistOf(pos, Building_Curer.CureRadius)) { Building_Curer.curableCells.Add(cell); } } return(false); }, 13, RegionType.Set_Passable); return(Building_Curer.curableCells); }
public static List <IntVec3> TradeableCellsAround(IntVec3 pos, Map map) { tradeableCells.Clear(); if (!pos.InBounds(map)) { return(tradeableCells); } Region region = pos.GetRegion(map); if (region == null) { return(tradeableCells); } RegionTraverser.BreadthFirstTraverse(region, (Region from, Region r) => r.door == null, delegate(Region r) { foreach (IntVec3 cell in r.Cells) { if (cell.InHorDistOf(pos, 7.9f)) { tradeableCells.Add(cell); } } return(false); }, 16); return(tradeableCells); }
public List <IntVec3> CellsAround(IntVec3 pos, Map map) { var result = new List <IntVec3>(); if (!pos.InBounds(map)) { return(result); } var region = pos.GetRegion(map, RegionType.Set_All); if (region == null) { return(result); } RegionTraverser.BreadthFirstTraverse(region, (_, r) => r.door == null, delegate(Region r) { foreach (var item in r.Cells) { if (item.InHorDistOf(pos, 6f)) { result.Add(item); } } return(false); }, 13, RegionType.Set_All); return(result); }
public override void Resolve(ResolveParams rp) { Map map = BaseGen.globalSettings.map; ThingDef thingDef = ((rp.faction != null && (int)rp.faction.def.techLevel < 4) ? ThingDefOf.TorchLamp : ThingDefOf.StandingLamp); FindNearbyGlowers(rp.rect); for (int i = 0; i < rp.rect.Area / 4; i++) { IntVec3 randomCell = rp.rect.RandomCell; if (!randomCell.Standable(map) || randomCell.GetFirstItem(map) != null || randomCell.GetFirstPawn(map) != null || randomCell.GetFirstBuilding(map) != null) { continue; } Region region = randomCell.GetRegion(map); if (region != null && region.Room.PsychologicallyOutdoors && region.Room.UsesOutdoorTemperature && !AnyGlowerNearby(randomCell) && !BaseGenUtility.AnyDoorAdjacentCardinalTo(randomCell, map)) { if (!rp.spawnBridgeIfTerrainCantSupportThing.HasValue || rp.spawnBridgeIfTerrainCantSupportThing.Value) { BaseGenUtility.CheckSpawnBridgeUnder(thingDef, randomCell, Rot4.North); } Thing thing = GenSpawn.Spawn(thingDef, randomCell, map); if (thing.def.CanHaveFaction && thing.Faction != rp.faction) { thing.SetFaction(rp.faction); } nearbyGlowers.Add(thing.TryGetComp <CompGlower>()); } } nearbyGlowers.Clear(); }
// Token: 0x06000190 RID: 400 RVA: 0x0000F358 File Offset: 0x0000D558 public override void Resolve(ResolveParams rp) { Map map = BaseGen.globalSettings.map; ThingDef glowPod = RimWorld.ThingDefOf.GlowPod; this.FindNearbyGlowers(rp.rect); for (int i = 0; i < rp.rect.Area / 4; i++) { IntVec3 randomCell = rp.rect.RandomCell; bool flag = randomCell.Standable(map) && randomCell.GetFirstItem(map) == null && randomCell.GetFirstPawn(map) == null && randomCell.GetFirstBuilding(map) == null; if (flag) { Region region = randomCell.GetRegion(map, RegionType.Set_Passable); bool flag2 = region != null && region.Room.PsychologicallyOutdoors && region.Room.UsesOutdoorTemperature && !this.AnyGlowerNearby(randomCell) && !BaseGenUtility.AnyDoorAdjacentCardinalTo(randomCell, map); if (flag2) { bool flag3 = rp.spawnBridgeIfTerrainCantSupportThing == null || rp.spawnBridgeIfTerrainCantSupportThing.Value; if (flag3) { BaseGenUtility.CheckSpawnBridgeUnder(glowPod, randomCell, Rot4.North); } Thing thing = GenSpawn.Spawn(glowPod, randomCell, map, WipeMode.Vanish); bool flag4 = thing.def.CanHaveFaction && thing.Faction != rp.faction; if (flag4) { thing.SetFaction(rp.faction, null); } SymbolResolver_OutdoorLightingHivebase.nearbyGlowers.Add(thing.TryGetComp <CompGlower>()); } } } SymbolResolver_OutdoorLightingHivebase.nearbyGlowers.Clear(); }
public static List <IntVec3> PortableCellsAround(IntVec3 pos, Map map, float cellRadius) { List <IntVec3> cellRange = new List <IntVec3>(); cellRange.Clear(); if (!pos.InBounds(map)) { return(null); } Region region = pos.GetRegion(map, RegionType.Set_All); if (region == null) { return(null); } int drawRad = (int)(cellRadius * 4); RegionTraverser.BreadthFirstTraverse(region, (Region from, Region r) => r.door == null, delegate(Region r) { foreach (IntVec3 current in r.Cells) { if (current.InHorDistOf(pos, cellRadius)) { cellRange.Add(current); } } return(false); }, drawRad, RegionType.Set_All); return(cellRange); }
/// <summary> /// Checks for cells in a 7.9 radius around for listening. /// </summary> /// <param name="pos"></param> /// <returns></returns> public static List <IntVec3> ListenableCellsAround(IntVec3 pos, Map map) { //Erase all the cells and recheck. listenableCells.Clear(); if (!pos.InBounds(map)) { return(listenableCells); } Region region = pos.GetRegion(map); if (region == null) { return(listenableCells); } RegionTraverser.BreadthFirstTraverse(region, (Region from, Region r) => r.door == null, delegate(Region r) { foreach (IntVec3 current in r.Cells) { if (current.InHorDistOf(pos, 7.9f)) //Check within a 7.9 radius { listenableCells.Add(current); } } return(false); }, 12); return(listenableCells); //Return the cells we find. }
public static void AddAllowedAdjacentRegions(LocalTargetInfo dest, TraverseParms traverseParams, Map map, List <Region> 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.InBounds(map) && !IsAdjacentCornerAndNotAllowed(intVec, BL, TL, TR, BR, map)) { Region region = intVec.GetRegion(map); if (region != null && region.Allows(traverseParams, isDestination: true)) { regions.Add(region); } } } return; } List <IntVec3> list = GenAdjFast.AdjacentCells8Way(dest); for (int j = 0; j < list.Count; j++) { if (list[j].InBounds(map) && !IsAdjacentCornerAndNotAllowed(list[j], BL, TL, TR, BR, map)) { Region region2 = list[j].GetRegion(map); if (region2 != null && region2.Allows(traverseParams, isDestination: true)) { regions.Add(region2); } } } }
public override void Resolve(ResolveParams rp) { Map map = BaseGen.globalSettings.map; ThingDef def = (rp.faction != null && (int)rp.faction.def.techLevel < 4) ? ThingDefOf.TorchLamp : ThingDefOf.StandingLamp; this.FindNearbyGlowers(rp.rect); for (int i = 0; i < rp.rect.Area / 4; i++) { IntVec3 randomCell = rp.rect.RandomCell; if (randomCell.Standable(map) && randomCell.GetFirstItem(map) == null && randomCell.GetFirstPawn(map) == null && randomCell.GetFirstBuilding(map) == null) { Region region = randomCell.GetRegion(map, RegionType.Set_Passable); if (region != null && region.Room.PsychologicallyOutdoors && region.Room.UsesOutdoorTemperature && !this.AnyGlowerNearby(randomCell) && !BaseGenUtility.AnyDoorAdjacentCardinalTo(randomCell, map)) { Thing thing = GenSpawn.Spawn(def, randomCell, map); if (thing.def.CanHaveFaction && thing.Faction != rp.faction) { thing.SetFaction(rp.faction, null); } SymbolResolver_OutdoorLighting.nearbyGlowers.Add(thing.TryGetComp <CompGlower>()); } } } SymbolResolver_OutdoorLighting.nearbyGlowers.Clear(); }
public void EvaluateCell(IntVec3 c, CastPositionRequest req, float maxRangeFromTargetSquared, float maxRangeFromLocusSquared, float maxRangeFromCasterSquared, float rangeFromCasterToCellSquared, int inRadiusMark ) { /////////////// EVALUATE CELL METHOD if (maxRangeFromTargetSquared > 0.01f && maxRangeFromTargetSquared < 250000f && (c - this.TargetA.Cell).LengthHorizontalSquared > maxRangeFromTargetSquared) { if (DebugViewSettings.drawCastPositionSearch) { req.caster.Map.debugDrawer.FlashCell(c, 0f, "range target"); } return; } if (maxRangeFromLocusSquared > 0.01 && (c - req.locus).LengthHorizontalSquared > maxRangeFromLocusSquared) { if (DebugViewSettings.drawCastPositionSearch) { req.caster.Map.debugDrawer.FlashCell(c, 0.1f, "range home"); } return; } if (maxRangeFromCasterSquared > 0.01f) { rangeFromCasterToCellSquared = (c - req.caster.Position).LengthHorizontalSquared; if (rangeFromCasterToCellSquared > maxRangeFromCasterSquared) { if (DebugViewSettings.drawCastPositionSearch) { req.caster.Map.debugDrawer.FlashCell(c, 0.2f, "range caster"); } return; } } if (!c.Walkable(req.caster.Map)) { return; } if (req.maxRegionsRadius > 0 && c.GetRegion(req.caster.Map).mark != inRadiusMark) { if (DebugViewSettings.drawCastPositionSearch) { req.caster.Map.debugDrawer.FlashCell(c, 0.64f, "reg radius"); } return; } if (!req.caster.Map.reachability.CanReach(req.caster.Position, c, PathEndMode.OnCell, TraverseParms.For(req.caster, Danger.Some, TraverseMode.ByPawn, false))) { if (DebugViewSettings.drawCastPositionSearch) { req.caster.Map.debugDrawer.FlashCell(c, 0.4f, "can't reach"); } return; } }
private static float GetScoreAt(IntVec3 cell, Map map) { if ((float)(int)InfestationCellFinder.distToColonyBuilding[cell] > 30.0) { return(0f); } if (!cell.Standable(map)) { return(0f); } if (cell.Fogged(map)) { return(0f); } if (InfestationCellFinder.CellHasBlockingThings(cell, map)) { return(0f); } if (cell.Roofed(map) && cell.GetRoof(map).isThickRoof) { Region region = cell.GetRegion(map, RegionType.Set_Passable); if (region == null) { return(0f); } if (InfestationCellFinder.closedAreaSize[cell] < 16) { return(0f); } float temperature = cell.GetTemperature(map); if (temperature < -17.0) { return(0f); } float mountainousnessScoreAt = InfestationCellFinder.GetMountainousnessScoreAt(cell, map); if (mountainousnessScoreAt < 0.17000000178813934) { return(0f); } int num = InfestationCellFinder.StraightLineDistToUnroofed(cell, map); float num2 = (float)(InfestationCellFinder.regionsDistanceToUnroofed.TryGetValue(region, out num2) ? Mathf.Min(num2, (float)((float)num * 4.0)) : ((float)num * 1.1499999761581421)); num2 = Mathf.Pow(num2, 1.55f); float num3 = Mathf.InverseLerp(0f, 12f, (float)num); float num4 = Mathf.Lerp(1f, 0.18f, map.glowGrid.GameGlowAt(cell, false)); float num5 = (float)(1.0 - Mathf.Clamp((float)(InfestationCellFinder.DistToBlocker(cell, map) / 11.0), 0f, 0.6f)); float num6 = Mathf.InverseLerp(-17f, -7f, temperature); float f = num2 * num3 * num5 * mountainousnessScoreAt * num4 * num6; f = Mathf.Pow(f, 1.2f); if (f < 7.5) { return(0f); } return(f); } return(0f); }
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) { return; } newRegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, maxRegions, traversableRegionTypes); }
protected override Job TryGiveJob(Pawn pawn) { if (pawn.TryGetAttackVerb(null) == null) { return(null); } Pawn pawn2 = this.FindPawnTarget(pawn); if (pawn2 != null && pawn.CanReach(pawn2, PathEndMode.Touch, Danger.Deadly, false, TraverseMode.ByPawn)) { return(this.MeleeAttackJob(pawn, pawn2)); } Building building = this.FindTurretTarget(pawn); if (building != null) { return(this.MeleeAttackJob(pawn, building)); } if (pawn2 != null) { using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, pawn2.Position, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings, false), PathEndMode.OnCell)) { if (!pawnPath.Found) { return(null); } IntVec3 cellBeforeBlocker; Thing thing = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn); if (thing != null) { //Job job = DigUtility.PassBlockerJob(pawn, thing, cellBeforeBlocker, true); //if (job != null) //{ return(this.MeleeAttackJob(pawn, thing)); //} } IntVec3 loc = pawnPath.LastCellBeforeBlockerOrFinalCell(pawn.MapHeld); IntVec3 randomCell = CellFinder.RandomRegionNear(loc.GetRegion(pawn.Map, RegionType.Set_Passable), 9, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), null, null, RegionType.Set_Passable).RandomCell; if (randomCell == pawn.Position) { return(new Job(JobDefOf.Wait, 30, false)); } return(new Job(JobDefOf.Goto, randomCell)); } } Building buildingDoor = this.FindDoorTarget(pawn); if (buildingDoor != null) { return(this.MeleeAttackJob(pawn, buildingDoor)); } return(null); }
private static List <Thing> FindAllFuel(Pawn pawn, Thing refuelable) { int quantity = refuelable.TryGetComp <CompFilteredRefuelable>().GetFuelCountToFullyRefuel(); ThingFilter filter = refuelable.TryGetComp <CompFilteredRefuelable>().FuelFilter; Predicate <Thing> validator = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, -1, null, false) && filter.Allows(x); IntVec3 position = refuelable.Position; Region region = position.GetRegion(pawn.Map, RegionType.Set_Passable); TraverseParms traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false); RegionEntryPredicate entryCondition = (Region from, Region r) => r.Allows(traverseParams, false); List <Thing> chosenThings = new List <Thing>(); int accumulatedQuantity = 0; RegionProcessor regionProcessor = delegate(Region r) { List <Thing> list = r.ListerThings.ThingsMatching(ThingRequest.ForGroup(ThingRequestGroup.HaulableEver)); for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; bool flag2 = validator(thing); if (flag2) { bool flag3 = !chosenThings.Contains(thing); if (flag3) { bool flag4 = ReachabilityWithinRegion.ThingFromRegionListerReachable(thing, r, PathEndMode.ClosestTouch, pawn); if (flag4) { chosenThings.Add(thing); accumulatedQuantity += thing.stackCount; bool flag5 = accumulatedQuantity >= quantity; if (flag5) { return(true); } } } } } return(false); }; RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, 99999, RegionType.Set_Passable); bool flag = accumulatedQuantity >= quantity; List <Thing> result; if (flag) { result = chosenThings; } else { result = null; } return(result); }
public static List <Thing> FindEnoughReservableThings(Pawn pawn, IntVec3 rootCell, IntRange desiredQuantity, Predicate <Thing> validThing) { Predicate <Thing> validator = delegate(Thing x) { if (x.IsForbidden(pawn) || !pawn.CanReserve(x)) { return(false); } return(validThing(x) ? true : false); }; Region region2 = rootCell.GetRegion(pawn.Map); TraverseParms traverseParams = TraverseParms.For(pawn); RegionEntryPredicate entryCondition = (Region from, Region r) => r.Allows(traverseParams, isDestination: false); List <Thing> chosenThings = new List <Thing>(); int accumulatedQuantity = 0; ThingListProcessor(rootCell.GetThingList(region2.Map), region2); if (accumulatedQuantity < desiredQuantity.max) { RegionTraverser.BreadthFirstTraverse(region2, entryCondition, RegionProcessor, 99999); } if (accumulatedQuantity >= desiredQuantity.min) { return(chosenThings); } return(null); bool RegionProcessor(Region r) { List <Thing> things2 = r.ListerThings.ThingsMatching(ThingRequest.ForGroup(ThingRequestGroup.HaulableEver)); return(ThingListProcessor(things2, r)); } bool ThingListProcessor(List <Thing> things, Region region) { for (int i = 0; i < things.Count; i++) { Thing thing = things[i]; if (validator(thing) && !chosenThings.Contains(thing) && ReachabilityWithinRegion.ThingFromRegionListerReachable(thing, region, PathEndMode.ClosestTouch, pawn)) { chosenThings.Add(thing); accumulatedQuantity += thing.stackCount; if (accumulatedQuantity >= desiredQuantity.max) { return(true); } } } return(false); } }
public void RegisterTarget(IntVec3 target) { this.target = target; this.targetRegion = target.GetRegion(map); this.OnTargetSet(); this.state = states.findingPath; }
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 TryFindSkygazeCell(IntVec3 root, Pawn searcher, out IntVec3 result) { Predicate <IntVec3> cellValidator = (IntVec3 c) => !c.Roofed(searcher.Map) && !c.GetTerrain(searcher.Map).avoidWander; IntVec3 result3; Predicate <Region> validator = (Region r) => r.Room.PsychologicallyOutdoors && !r.IsForbiddenEntirely(searcher) && r.TryFindRandomCellInRegionUnforbidden(searcher, cellValidator, out result3); TraverseParms traverseParms = TraverseParms.For(searcher); if (!CellFinder.TryFindClosestRegionWith(root.GetRegion(searcher.Map), traverseParms, validator, 300, out Region result2)) { result = root; return(false); } return(CellFinder.RandomRegionNear(result2, 14, traverseParms, validator, searcher).TryFindRandomCellInRegionUnforbidden(searcher, cellValidator, out result)); }
public void setCellsToAffect() { if (this.status == "stable") { return; } IntVec3 pos = this.parent.Position; Map map = this.parent.Map; this.affectableCells.Clear(); this.boundaryCellsRough.Clear(); this.boundaryCells.Clear(); this.affectableCellsAtmosphere.Clear(); if (!pos.InBounds(map)) { return; } int maxArea = (int)Math.Round(this.width + this.Props.borderSize + 5); Region region = pos.GetRegion(map, RegionType.Set_Passable); if (region == null) { return; } RegionTraverser.BreadthFirstTraverse(region, (Region from, Region r) => r.door == null, delegate(Region r) { foreach (IntVec3 current in r.Cells) { if (current.InHorDistOf(pos, this.width)) { this.affectableCells.Add(current); } else if (current.InHorDistOf(pos, this.width + 2)) { this.boundaryCellsRough.Add(current); } else if (current.InHorDistOf(pos, this.width + this.Props.borderSize + 1)) { this.boundaryCells.Add(current); } else if (current.InHorDistOf(pos, this.width + this.Props.borderSize + 5)) { this.affectableCellsAtmosphere.Add(current); } } return(false); }, maxArea, RegionType.Set_Passable); return; }
public static void GetWanderRoot_PostFix(JobGiver_WanderColony __instance, Pawn pawn, ref IntVec3 __result) { if (Find.Scenario.name == "Resident Evil") { if (pawn is Zombie) { return; } if (pawn.Spawned) { var map = pawn.Map; var ZombieDangerMap = map.GetComponent <ZombieDangerMap>(); if (!ZombieDangerMap.regionDangers.ContainsKey(__result.GetRegion(map))) { ZombieDangerMap.regionDangers.Add(__result.GetRegion(map), 1000); } if (ZombieDangerMap.regionDangers[__result.GetRegion(map)] > 0 || __result.Fogged(map)) { __result = pawn.GetRegion().Cells.InRandomOrder().First(x => x.Standable(map)); } } } }
private static List <Thing> FindAllFuel(Pawn pawn, Thing refuelable) { int quantity = refuelable.TryGetComp <CompRefuelable>().GetFuelCountToFullyRefuel(); ThingFilter filter = refuelable.TryGetComp <CompRefuelable>().Props.fuelFilter; Predicate <Thing> validator = delegate(Thing x) { if (x.IsForbidden(pawn) || !pawn.CanReserve(x)) { return(false); } if (!filter.Allows(x)) { return(false); } return(true); }; IntVec3 position = refuelable.Position; Region region = position.GetRegion(pawn.Map); TraverseParms traverseParams = TraverseParms.For(pawn); RegionEntryPredicate entryCondition = (Region from, Region r) => r.Allows(traverseParams, isDestination: false); List <Thing> chosenThings = new List <Thing>(); int accumulatedQuantity = 0; RegionProcessor regionProcessor = delegate(Region r) { List <Thing> list = r.ListerThings.ThingsMatching(ThingRequest.ForGroup(ThingRequestGroup.HaulableEver)); for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; if (validator(thing) && !chosenThings.Contains(thing) && ReachabilityWithinRegion.ThingFromRegionListerReachable(thing, r, PathEndMode.ClosestTouch, pawn)) { chosenThings.Add(thing); accumulatedQuantity += thing.stackCount; if (accumulatedQuantity >= quantity) { return(true); } } } return(false); }; RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, 99999); if (accumulatedQuantity >= quantity) { return(chosenThings); } return(null); }
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; this.endCell = end.CenterCell; this.cachedRegion = null; this.cachedBestLink = null; this.cachedSecondBestLink = null; this.cachedBestLinkCost = 0; this.cachedSecondBestLinkCost = 0; this.cachedRegionCellPathCost = 0; this.cachedRegionIsDestination = false; this.regionGrid = this.map.regionGrid.DirectGrid; this.destRegions.Clear(); if (end.Width == 1 && end.Height == 1) { Region region = this.endCell.GetRegion(this.map, RegionType.Set_Passable); if (region != null) { this.destRegions.Add(region); } } else { CellRect.CellRectIterator iterator = end.GetIterator(); while (!iterator.Done()) { IntVec3 intVec = iterator.Current; if (intVec.InBounds(this.map) && !disallowedCorners.Contains(this.map.cellIndices.CellToIndex(intVec))) { Region region2 = intVec.GetRegion(this.map, RegionType.Set_Passable); if (region2 != null) { if (region2.Allows(traverseParms, true)) { this.destRegions.Add(region2); } } } iterator.MoveNext(); } } if (this.destRegions.Count == 0) { Log.Error("Couldn't find any destination regions. This shouldn't ever happen because we've checked reachability.", false); } this.regionCostCalculator.Init(end, this.destRegions, traverseParms, moveTicksCardinal, moveTicksDiagonal, avoidGrid, allowedArea, drafted); }