private void AffectCell(IntVec3 c) { if (c.InBounds(base.Map)) { bool flag = this.ShouldCellBeAffectedOnlyByDamage(c); if (!flag) { if (Rand.Chance(this.preExplosionSpawnChance) && c.Walkable(base.Map)) { this.TrySpawnExplosionThing(this.preExplosionSpawnThingDef, c, this.preExplosionSpawnThingCount); } } this.damType.Worker.ExplosionAffectCell(this, c, this.damagedThings, !flag); if (!flag) { if (Rand.Chance(this.postExplosionSpawnChance) && c.Walkable(base.Map)) { this.TrySpawnExplosionThing(this.postExplosionSpawnThingDef, c, this.postExplosionSpawnThingCount); } } float num = this.chanceToStartFire; if (this.damageFalloff) { num *= Mathf.Lerp(1f, 0.2f, c.DistanceTo(base.Position) / this.radius); } if (Rand.Chance(num)) { FireUtility.TryStartFireIn(c, base.Map, Rand.Range(0.1f, 0.925f)); } } }
internal void Notify_WalkabilityChanged(IntVec3 c) { this.regionsToDirty.Clear(); for (int i = 0; i < 9; i++) { IntVec3 c2 = c + GenAdj.AdjacentCellsAndInside[i]; if (c2.InBounds(this.map)) { Region regionAt_NoRebuild_InvalidAllowed = this.map.regionGrid.GetRegionAt_NoRebuild_InvalidAllowed(c2); if (regionAt_NoRebuild_InvalidAllowed != null && regionAt_NoRebuild_InvalidAllowed.valid) { this.map.temperatureCache.TryCacheRegionTempInfo(c, regionAt_NoRebuild_InvalidAllowed); this.regionsToDirty.Add(regionAt_NoRebuild_InvalidAllowed); } } } for (int j = 0; j < this.regionsToDirty.Count; j++) { this.SetRegionDirty(this.regionsToDirty[j], true); } this.regionsToDirty.Clear(); if (c.Walkable(this.map) && !this.dirtyCells.Contains(c)) { this.dirtyCells.Add(c); } }
public virtual IEnumerable <IntVec3> ExplosionCellsToHit(IntVec3 center, Map map, float radius) { openCells.Clear(); adjWallCells.Clear(); int num = GenRadial.NumCellsInRadius(radius); for (int i = 0; i < num; i++) { IntVec3 intVec = center + GenRadial.RadialPattern[i]; if (intVec.InBounds(map) && GenSight.LineOfSight(center, intVec, map, skipFirstCell: true)) { openCells.Add(intVec); } } for (int j = 0; j < openCells.Count; j++) { IntVec3 intVec2 = openCells[j]; if (intVec2.Walkable(map)) { for (int k = 0; k < 4; k++) { IntVec3 intVec3 = intVec2 + GenAdj.CardinalDirections[k]; if (intVec3.InHorDistOf(center, radius) && intVec3.InBounds(map) && !intVec3.Standable(map) && intVec3.GetEdifice(map) != null && !openCells.Contains(intVec3) && adjWallCells.Contains(intVec3)) { adjWallCells.Add(intVec3); } } } } return(openCells.Concat(adjWallCells)); }
public static RegionType GetExpectedRegionType(this IntVec3 c, Map map) { RegionType result; if (!c.InBounds(map)) { result = RegionType.None; } else if (c.GetDoor(map) != null) { result = RegionType.Portal; } else if (c.Walkable(map)) { result = RegionType.Normal; } else { List <Thing> thingList = c.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { if (thingList[i].def.Fillage == FillCategory.Full) { return(RegionType.None); } } result = RegionType.ImpassableFreeAirExchange; } return(result); }
private static void MakeFilthx100() { for (int i = 0; i < 100; i++) { IntVec3 c = UI.MouseCell() + GenRadial.RadialPattern[i]; if (c.InBounds(Find.CurrentMap) && c.Walkable(Find.CurrentMap)) { FilthMaker.TryMakeFilth(c, Find.CurrentMap, ThingDefOf.Filth_Dirt, 2); MoteMaker.ThrowMetaPuff(c.ToVector3Shifted(), Find.CurrentMap); } } }
public bool CanReachFactionBase(IntVec3 c, Faction factionBaseFaction) { bool result; if (Current.ProgramState != ProgramState.Playing) { result = this.CanReach(c, MapGenerator.PlayerStartSpot, PathEndMode.OnCell, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false)); } else if (!c.Walkable(this.map)) { result = false; } else { Faction faction = this.map.ParentFaction ?? Faction.OfPlayer; List <Pawn> list = this.map.mapPawns.SpawnedPawnsInFaction(faction); for (int i = 0; i < list.Count; i++) { if (list[i].CanReach(c, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)) { return(true); } } TraverseParms traverseParams = TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false); if (faction == Faction.OfPlayer) { List <Building> allBuildingsColonist = this.map.listerBuildings.allBuildingsColonist; for (int j = 0; j < allBuildingsColonist.Count; j++) { if (this.CanReach(c, allBuildingsColonist[j], PathEndMode.Touch, traverseParams)) { return(true); } } } else { List <Thing> list2 = this.map.listerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial); for (int k = 0; k < list2.Count; k++) { if (list2[k].Faction == faction && this.CanReach(c, list2[k], PathEndMode.Touch, traverseParams)) { return(true); } } } result = this.CanReachBiggestMapEdgeRoom(c); } return(result); }
public virtual IEnumerable <IntVec3> ExplosionCellsToHit(IntVec3 center, Map map, float radius) { DamageWorker.openCells.Clear(); DamageWorker.adjWallCells.Clear(); int num = GenRadial.NumCellsInRadius(radius); for (int i = 0; i < num; i++) { IntVec3 intVec = center + GenRadial.RadialPattern[i]; if (intVec.InBounds(map)) { if (GenSight.LineOfSight(center, intVec, map, true, null, 0, 0)) { DamageWorker.openCells.Add(intVec); } } } for (int j = 0; j < DamageWorker.openCells.Count; j++) { IntVec3 intVec2 = DamageWorker.openCells[j]; if (intVec2.Walkable(map)) { for (int k = 0; k < 4; k++) { IntVec3 intVec3 = intVec2 + GenAdj.CardinalDirections[k]; if (intVec3.InHorDistOf(center, radius)) { if (intVec3.InBounds(map)) { if (!intVec3.Standable(map)) { if (intVec3.GetEdifice(map) != null) { if (!DamageWorker.openCells.Contains(intVec3) && DamageWorker.adjWallCells.Contains(intVec3)) { DamageWorker.adjWallCells.Add(intVec3); } } } } } } } } return(DamageWorker.openCells.Concat(DamageWorker.adjWallCells)); }
private static IEnumerable <IntVec3> GetAdjacentCardinalCellsForBestStandCell(IntVec3 x, float radius, Pawn pawn) { if ((float)(x - pawn.Position).LengthManhattan <= radius) { for (int i = 0; i < 4; i++) { IntVec3 c = x + GenAdj.CardinalDirections[i]; if (c.InBounds(pawn.Map) && c.Walkable(pawn.Map)) { Building_Door door = c.GetEdifice(pawn.Map) as Building_Door; if (door == null || door.CanPhysicallyPass(pawn)) { yield return(c); } } } } }
public static bool TryFindBestPawnStandCell(Pawn forPawn, out IntVec3 cell, bool cellByCell = false) { cell = IntVec3.Invalid; int num = -1; float radius = 10f; while (true) { tmpDistances.Clear(); tmpParents.Clear(); Dijkstra <IntVec3> .Run(forPawn.Position, (IntVec3 x) => GetAdjacentCardinalCellsForBestStandCell(x, radius, forPawn), delegate(IntVec3 from, IntVec3 to) { float num4 = 1f; if (from.x != to.x && from.z != to.z) { num4 = 1.41421354f; } if (!to.Standable(forPawn.Map)) { num4 += 3f; } if (PawnUtility.AnyPawnBlockingPathAt(to, forPawn)) { num4 = ((to.GetThingList(forPawn.Map).Find((Thing x) => x is Pawn && x.HostileTo(forPawn)) == null) ? (num4 + 15f) : (num4 + 40f)); } Building_Door building_Door = to.GetEdifice(forPawn.Map) as Building_Door; if (building_Door != null && !building_Door.FreePassage) { num4 = ((!building_Door.PawnCanOpen(forPawn)) ? (num4 + 50f) : (num4 + 6f)); } return(num4); }, tmpDistances, tmpParents); if (tmpDistances.Count == num) { return(false); } float num2 = 0f; foreach (KeyValuePair <IntVec3, float> tmpDistance in tmpDistances) { if ((!cell.IsValid || !(tmpDistance.Value >= num2)) && tmpDistance.Key.Walkable(forPawn.Map) && !PawnUtility.AnyPawnBlockingPathAt(tmpDistance.Key, forPawn)) { Building_Door door = tmpDistance.Key.GetDoor(forPawn.Map); if (door == null || door.FreePassage) { cell = tmpDistance.Key; num2 = tmpDistance.Value; } } } if (cell.IsValid) { if (!cellByCell) { return(true); } IntVec3 intVec = cell; int num3 = 0; while (intVec.IsValid && intVec != forPawn.Position) { num3++; if (num3 >= 10000) { Log.Error("Too many iterations."); break; } if (intVec.Walkable(forPawn.Map)) { Building_Door door2 = intVec.GetDoor(forPawn.Map); if (door2 == null || door2.FreePassage) { cell = intVec; } } intVec = tmpParents[intVec]; } return(true); } if (radius > (float)forPawn.Map.Size.x && radius > (float)forPawn.Map.Size.z) { break; } radius *= 2f; num = tmpDistances.Count; } return(false); }
public static IntVec3 InteractionCellWhenAt(ThingDef def, IntVec3 center, Rot4 rot, Map map) { if (def.hasInteractionCell) { IntVec3 b = def.interactionCellOffset.RotatedBy(rot); return(center + b); } if (def.Size.x == 1 && def.Size.z == 1) { for (int i = 0; i < 8; i++) { IntVec3 intVec = center + GenAdj.AdjacentCells[i]; if (intVec.Standable(map) && intVec.GetDoor(map) == null && ReachabilityImmediate.CanReachImmediate(intVec, center, map, PathEndMode.Touch, null)) { return(intVec); } } for (int j = 0; j < 8; j++) { IntVec3 intVec2 = center + GenAdj.AdjacentCells[j]; if (intVec2.Standable(map) && ReachabilityImmediate.CanReachImmediate(intVec2, center, map, PathEndMode.Touch, null)) { return(intVec2); } } for (int k = 0; k < 8; k++) { IntVec3 intVec3 = center + GenAdj.AdjacentCells[k]; if (intVec3.Walkable(map) && ReachabilityImmediate.CanReachImmediate(intVec3, center, map, PathEndMode.Touch, null)) { return(intVec3); } } return(center); } List <IntVec3> list = GenAdjFast.AdjacentCells8Way(center, rot, def.size); CellRect rect = GenAdj.OccupiedRect(center, rot, def.size); for (int l = 0; l < list.Count; l++) { if (list[l].Standable(map) && list[l].GetDoor(map) == null && ReachabilityImmediate.CanReachImmediate(list[l], rect, map, PathEndMode.Touch, null)) { return(list[l]); } } for (int m = 0; m < list.Count; m++) { if (list[m].Standable(map) && ReachabilityImmediate.CanReachImmediate(list[m], rect, map, PathEndMode.Touch, null)) { return(list[m]); } } for (int n = 0; n < list.Count; n++) { if (list[n].Walkable(map) && ReachabilityImmediate.CanReachImmediate(list[n], rect, map, PathEndMode.Touch, null)) { return(list[n]); } } return(center); }
private static GenPlace.PlaceSpotQuality PlaceSpotQualityAt(IntVec3 c, Map map, Thing thing, IntVec3 center, bool allowStacking, Predicate <IntVec3> extraValidator = null) { if (!c.InBounds(map) || !c.Walkable(map)) { return(GenPlace.PlaceSpotQuality.Unusable); } if (extraValidator != null && !extraValidator(c)) { return(GenPlace.PlaceSpotQuality.Unusable); } List <Thing> list = map.thingGrid.ThingsListAt(c); for (int i = 0; i < list.Count; i++) { Thing thing2 = list[i]; if (thing.def.saveCompressible && thing2.def.saveCompressible) { return(GenPlace.PlaceSpotQuality.Unusable); } if (thing.def.category == ThingCategory.Item && thing2.def.category == ThingCategory.Item && (!thing2.CanStackWith(thing) || thing2.stackCount >= thing.def.stackLimit)) { return(GenPlace.PlaceSpotQuality.Unusable); } } if (c.GetRoom(map, RegionType.Set_Passable) == center.GetRoom(map, RegionType.Set_Passable)) { if (allowStacking) { for (int j = 0; j < list.Count; j++) { Thing thing3 = list[j]; if (thing3.def.category == ThingCategory.Item && thing3.CanStackWith(thing) && thing3.stackCount < thing.def.stackLimit) { return(GenPlace.PlaceSpotQuality.Perfect); } } } Pawn pawn = thing as Pawn; bool flag = pawn != null && pawn.Downed; GenPlace.PlaceSpotQuality placeSpotQuality = GenPlace.PlaceSpotQuality.Perfect; for (int k = 0; k < list.Count; k++) { Thing thing4 = list[k]; if (thing4.def.IsDoor) { return(GenPlace.PlaceSpotQuality.Bad); } if (thing4 is Building_WorkTable) { return(GenPlace.PlaceSpotQuality.Bad); } Pawn pawn2 = thing4 as Pawn; if (pawn2 != null) { if (pawn2.Downed || flag) { return(GenPlace.PlaceSpotQuality.Bad); } if (placeSpotQuality > GenPlace.PlaceSpotQuality.Okay) { placeSpotQuality = GenPlace.PlaceSpotQuality.Okay; } } if (thing4.def.category == ThingCategory.Plant && thing4.def.selectable && placeSpotQuality > GenPlace.PlaceSpotQuality.Okay) { placeSpotQuality = GenPlace.PlaceSpotQuality.Okay; } } return(placeSpotQuality); } if (!map.reachability.CanReach(center, c, PathEndMode.OnCell, TraverseMode.PassDoors, Danger.Deadly)) { return(GenPlace.PlaceSpotQuality.Awful); } return(GenPlace.PlaceSpotQuality.Bad); }
private static PlaceSpotQuality PlaceSpotQualityAt(IntVec3 c, Rot4 rot, Map map, Thing thing, IntVec3 center, bool allowStacking, Predicate <IntVec3> extraValidator = null) { if (!c.InBounds(map) || !c.Walkable(map)) { return(PlaceSpotQuality.Unusable); } if (!GenAdj.OccupiedRect(c, rot, thing.def.Size).InBounds(map)) { return(PlaceSpotQuality.Unusable); } if (extraValidator != null && !extraValidator(c)) { return(PlaceSpotQuality.Unusable); } List <Thing> list = map.thingGrid.ThingsListAt(c); for (int i = 0; i < list.Count; i++) { Thing thing2 = list[i]; if (thing.def.saveCompressible && thing2.def.saveCompressible) { return(PlaceSpotQuality.Unusable); } if (thing.def.category == ThingCategory.Item && thing2.def.category == ThingCategory.Item && (!thing2.CanStackWith(thing) || thing2.stackCount >= thing.def.stackLimit)) { return(PlaceSpotQuality.Unusable); } } if (thing is Building) { foreach (IntVec3 item in GenAdj.OccupiedRect(c, rot, thing.def.size)) { Building edifice = item.GetEdifice(map); if (edifice != null && GenSpawn.SpawningWipes(thing.def, edifice.def)) { return(PlaceSpotQuality.Awful); } } } if (c.GetRoom(map) != center.GetRoom(map)) { if (!map.reachability.CanReach(center, c, PathEndMode.OnCell, TraverseMode.PassDoors, Danger.Deadly)) { return(PlaceSpotQuality.Awful); } return(PlaceSpotQuality.Bad); } if (allowStacking) { for (int j = 0; j < list.Count; j++) { Thing thing3 = list[j]; if (thing3.def.category == ThingCategory.Item && thing3.CanStackWith(thing) && thing3.stackCount < thing.def.stackLimit) { return(PlaceSpotQuality.Perfect); } } } bool flag = (thing as Pawn)?.Downed ?? false; PlaceSpotQuality placeSpotQuality = PlaceSpotQuality.Perfect; for (int k = 0; k < list.Count; k++) { Thing thing4 = list[k]; if (thing4.def.IsDoor) { return(PlaceSpotQuality.Bad); } if (thing4 is Building_WorkTable) { return(PlaceSpotQuality.Bad); } Pawn pawn = thing4 as Pawn; if (pawn != null) { if (pawn.Downed | flag) { return(PlaceSpotQuality.Bad); } if ((int)placeSpotQuality > 3) { placeSpotQuality = PlaceSpotQuality.Okay; } } if (thing4.def.category == ThingCategory.Plant && thing4.def.selectable && (int)placeSpotQuality > 3) { placeSpotQuality = PlaceSpotQuality.Okay; } } return(placeSpotQuality); }