public void FloodFill(IntVec3 root, Predicate <IntVec3> passCheck, Func <IntVec3, int, bool> processor, int maxCellsToProcess = 2147483647, bool rememberParents = false, IEnumerable <IntVec3> extraRoots = null) { if (this.working) { Log.Error("Nested FloodFill calls are not allowed. This will cause bugs.", false); } this.working = true; this.ClearVisited(); if (rememberParents && this.parentGrid == null) { this.parentGrid = new CellGrid(this.map); } if (root.IsValid && extraRoots == null && !passCheck(root)) { if (rememberParents) { this.parentGrid[root] = IntVec3.Invalid; } this.working = false; return; } int area = this.map.Area; IntVec3[] cardinalDirectionsAround = GenAdj.CardinalDirectionsAround; int num = cardinalDirectionsAround.Length; CellIndices cellIndices = this.map.cellIndices; int num2 = 0; this.openSet.Clear(); if (root.IsValid) { int num3 = cellIndices.CellToIndex(root); this.visited.Add(num3); this.traversalDistance[num3] = 0; this.openSet.Enqueue(root); } if (extraRoots != null) { IList <IntVec3> list = extraRoots as IList <IntVec3>; if (list != null) { for (int i = 0; i < list.Count; i++) { int num4 = cellIndices.CellToIndex(list[i]); this.visited.Add(num4); this.traversalDistance[num4] = 0; this.openSet.Enqueue(list[i]); } } else { foreach (IntVec3 intVec in extraRoots) { int num5 = cellIndices.CellToIndex(intVec); this.visited.Add(num5); this.traversalDistance[num5] = 0; this.openSet.Enqueue(intVec); } } } if (rememberParents) { for (int j = 0; j < this.visited.Count; j++) { IntVec3 intVec2 = cellIndices.IndexToCell(this.visited[j]); this.parentGrid[this.visited[j]] = ((!passCheck(intVec2)) ? IntVec3.Invalid : intVec2); } } while (this.openSet.Count > 0) { IntVec3 intVec3 = this.openSet.Dequeue(); int num6 = this.traversalDistance[cellIndices.CellToIndex(intVec3)]; if (processor(intVec3, num6)) { break; } num2++; if (num2 == maxCellsToProcess) { break; } for (int k = 0; k < num; k++) { IntVec3 intVec4 = intVec3 + cardinalDirectionsAround[k]; int num7 = cellIndices.CellToIndex(intVec4); if (intVec4.InBounds(this.map) && this.traversalDistance[num7] == -1 && passCheck(intVec4)) { this.visited.Add(num7); this.openSet.Enqueue(intVec4); this.traversalDistance[num7] = num6 + 1; if (rememberParents) { this.parentGrid[num7] = intVec3; } } } if (this.openSet.Count > area) { Log.Error("Overflow on flood fill (>" + area + " cells). Make sure we're not flooding over the same area after we check it.", false); this.working = false; return; } } this.working = false; }
private bool CheckCellBasedReachability(IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams) { IntVec3 foundCell = IntVec3.Invalid; Region[] directRegionGrid = regionGrid.DirectGrid; PathGrid pathGrid = map.pathGrid; CellIndices cellIndices = map.cellIndices; map.floodFiller.FloodFill(start, delegate(IntVec3 c) { int num = cellIndices.CellToIndex(c); if ((traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParams.mode == TraverseMode.NoPassClosedDoorsOrWater) && c.GetTerrain(map).IsWater) { return(false); } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings || traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater) { if (!pathGrid.WalkableFast(num)) { Building edifice = c.GetEdifice(map); if (edifice == null || !PathFinder.IsDestroyable(edifice)) { return(false); } } } else if (traverseParams.mode != TraverseMode.NoPassClosedDoorsOrWater) { Log.ErrorOnce("Do not use this method for non-cell based modes!", 938476762); if (!pathGrid.WalkableFast(num)) { return(false); } } Region region = directRegionGrid[num]; return((region == null || region.Allows(traverseParams, isDestination: false)) ? true : false); }, delegate(IntVec3 c) { if (ReachabilityImmediate.CanReachImmediate(c, dest, map, peMode, traverseParams.pawn)) { foundCell = c; return(true); } return(false); }); if (foundCell.IsValid) { if (CanUseCache(traverseParams.mode)) { Region validRegionAt = regionGrid.GetValidRegionAt(foundCell); if (validRegionAt != null) { for (int i = 0; i < startingRegions.Count; i++) { cache.AddCachedResult(startingRegions[i].Room, validRegionAt.Room, traverseParams, reachable: true); } } } return(true); } if (CanUseCache(traverseParams.mode)) { for (int j = 0; j < startingRegions.Count; j++) { for (int k = 0; k < destRegions.Count; k++) { cache.AddCachedResult(startingRegions[j].Room, destRegions[k].Room, traverseParams, reachable: false); } } } return(false); }
public override void Regenerate() { if (!MatBases.SunShadow.shader.isSupported) { return; } LayerSubMesh subMesh = GetSubMesh(MatBases.IndoorMask); subMesh.Clear(MeshParts.All); Building[] innerArray = base.Map.edificeGrid.InnerArray; CellRect cellRect = new CellRect(section.botLeft.x, section.botLeft.z, 17, 17); cellRect.ClipInsideMap(base.Map); subMesh.verts.Capacity = cellRect.Area * 2; subMesh.tris.Capacity = cellRect.Area * 4; float y = AltitudeLayer.MetaOverlays.AltitudeFor(); CellIndices cellIndices = base.Map.cellIndices; for (int i = cellRect.minX; i <= cellRect.maxX; i++) { for (int j = cellRect.minZ; j <= cellRect.maxZ; j++) { IntVec3 intVec = new IntVec3(i, 0, j); if (!HideRainPrimary(intVec)) { bool flag = intVec.Roofed(base.Map); bool flag2 = false; if (flag) { for (int k = 0; k < 8; k++) { IntVec3 c = intVec + GenAdj.AdjacentCells[k]; if (c.InBounds(base.Map) && HideRainPrimary(c)) { flag2 = true; break; } } } if (!flag || !flag2) { continue; } } Thing thing = innerArray[cellIndices.CellToIndex(i, j)]; float num = ((thing == null || (thing.def.passability != Traversability.Impassable && !thing.def.IsDoor)) ? 0.16f : 0f); subMesh.verts.Add(new Vector3((float)i - num, y, (float)j - num)); subMesh.verts.Add(new Vector3((float)i - num, y, (float)(j + 1) + num)); subMesh.verts.Add(new Vector3((float)(i + 1) + num, y, (float)(j + 1) + num)); subMesh.verts.Add(new Vector3((float)(i + 1) + num, y, (float)j - num)); int count = subMesh.verts.Count; subMesh.tris.Add(count - 4); subMesh.tris.Add(count - 3); subMesh.tris.Add(count - 2); subMesh.tris.Add(count - 4); subMesh.tris.Add(count - 2); subMesh.tris.Add(count - 1); } } if (subMesh.verts.Count > 0) { subMesh.FinalizeMesh(MeshParts.Verts | MeshParts.Tris); } }
public void ConstructComponents() { this.spawnedThings = new ThingOwner <Thing>(this); this.cellIndices = new CellIndices(this); this.listerThings = new ListerThings(ListerThingsUse.Global); this.listerBuildings = new ListerBuildings(); this.mapPawns = new MapPawns(this); this.dynamicDrawManager = new DynamicDrawManager(this); this.mapDrawer = new MapDrawer(this); this.tooltipGiverList = new TooltipGiverList(); this.pawnDestinationReservationManager = new PawnDestinationReservationManager(); this.reservationManager = new ReservationManager(this); this.physicalInteractionReservationManager = new PhysicalInteractionReservationManager(); this.designationManager = new DesignationManager(this); this.lordManager = new LordManager(this); this.debugDrawer = new DebugCellDrawer(); this.passingShipManager = new PassingShipManager(this); this.haulDestinationManager = new HaulDestinationManager(this); this.gameConditionManager = new GameConditionManager(this); this.weatherManager = new WeatherManager(this); this.zoneManager = new ZoneManager(this); this.resourceCounter = new ResourceCounter(this); this.mapTemperature = new MapTemperature(this); this.temperatureCache = new TemperatureCache(this); this.areaManager = new AreaManager(this); this.attackTargetsCache = new AttackTargetsCache(this); this.attackTargetReservationManager = new AttackTargetReservationManager(this); this.lordsStarter = new VoluntarilyJoinableLordsStarter(this); this.thingGrid = new ThingGrid(this); this.coverGrid = new CoverGrid(this); this.edificeGrid = new EdificeGrid(this); this.blueprintGrid = new BlueprintGrid(this); this.fogGrid = new FogGrid(this); this.glowGrid = new GlowGrid(this); this.regionGrid = new RegionGrid(this); this.terrainGrid = new TerrainGrid(this); this.pathGrid = new PathGrid(this); this.roofGrid = new RoofGrid(this); this.fertilityGrid = new FertilityGrid(this); this.snowGrid = new SnowGrid(this); this.deepResourceGrid = new DeepResourceGrid(this); this.exitMapGrid = new ExitMapGrid(this); this.avoidGrid = new AvoidGrid(this); this.linkGrid = new LinkGrid(this); this.glowFlooder = new GlowFlooder(this); this.powerNetManager = new PowerNetManager(this); this.powerNetGrid = new PowerNetGrid(this); this.regionMaker = new RegionMaker(this); this.pathFinder = new PathFinder(this); this.pawnPathPool = new PawnPathPool(this); this.regionAndRoomUpdater = new RegionAndRoomUpdater(this); this.regionLinkDatabase = new RegionLinkDatabase(); this.moteCounter = new MoteCounter(); this.gatherSpotLister = new GatherSpotLister(); this.windManager = new WindManager(this); this.listerBuildingsRepairable = new ListerBuildingsRepairable(); this.listerHaulables = new ListerHaulables(this); this.listerMergeables = new ListerMergeables(this); this.listerFilthInHomeArea = new ListerFilthInHomeArea(this); this.reachability = new Reachability(this); this.itemAvailability = new ItemAvailability(this); this.autoBuildRoofAreaSetter = new AutoBuildRoofAreaSetter(this); this.roofCollapseBufferResolver = new RoofCollapseBufferResolver(this); this.roofCollapseBuffer = new RoofCollapseBuffer(); this.wildAnimalSpawner = new WildAnimalSpawner(this); this.wildPlantSpawner = new WildPlantSpawner(this); this.steadyEnvironmentEffects = new SteadyEnvironmentEffects(this); this.skyManager = new SkyManager(this); this.overlayDrawer = new OverlayDrawer(); this.floodFiller = new FloodFiller(this); this.weatherDecider = new WeatherDecider(this); this.fireWatcher = new FireWatcher(this); this.dangerWatcher = new DangerWatcher(this); this.damageWatcher = new DamageWatcher(); this.strengthWatcher = new StrengthWatcher(this); this.wealthWatcher = new WealthWatcher(this); this.regionDirtyer = new RegionDirtyer(this); this.cellsInRandomOrder = new MapCellsInRandomOrder(this); this.rememberedCameraPos = new RememberedCameraPos(this); this.mineStrikeManager = new MineStrikeManager(); this.storyState = new StoryState(this); this.retainedCaravanData = new RetainedCaravanData(this); this.components.Clear(); this.FillComponents(); }
public override void Regenerate() { LayerSubMesh subMesh = base.GetSubMesh(MatBases.FogOfWar); if (subMesh.mesh.vertexCount == 0) { SectionLayerGeometryMaker_Solid.MakeBaseGeometry(base.section, subMesh, AltitudeLayer.FogOfWar); } subMesh.Clear(MeshParts.Colors); bool[] fogGrid = base.Map.fogGrid.fogGrid; CellRect cellRect = base.section.CellRect; IntVec3 size = base.Map.Size; int num = size.z - 1; IntVec3 size2 = base.Map.Size; int num2 = size2.x - 1; bool flag = false; CellIndices cellIndices = base.Map.cellIndices; for (int i = cellRect.minX; i <= cellRect.maxX; i++) { for (int j = cellRect.minZ; j <= cellRect.maxZ; j++) { if (fogGrid[cellIndices.CellToIndex(i, j)]) { for (int k = 0; k < 9; k++) { this.vertsCovered[k] = true; } } else { for (int l = 0; l < 9; l++) { this.vertsCovered[l] = false; } if (j < num && fogGrid[cellIndices.CellToIndex(i, j + 1)]) { this.vertsCovered[2] = true; this.vertsCovered[3] = true; this.vertsCovered[4] = true; } if (j > 0 && fogGrid[cellIndices.CellToIndex(i, j - 1)]) { this.vertsCovered[6] = true; this.vertsCovered[7] = true; this.vertsCovered[0] = true; } if (i < num2 && fogGrid[cellIndices.CellToIndex(i + 1, j)]) { this.vertsCovered[4] = true; this.vertsCovered[5] = true; this.vertsCovered[6] = true; } if (i > 0 && fogGrid[cellIndices.CellToIndex(i - 1, j)]) { this.vertsCovered[0] = true; this.vertsCovered[1] = true; this.vertsCovered[2] = true; } if (j > 0 && i > 0 && fogGrid[cellIndices.CellToIndex(i - 1, j - 1)]) { this.vertsCovered[0] = true; } if (j < num && i > 0 && fogGrid[cellIndices.CellToIndex(i - 1, j + 1)]) { this.vertsCovered[2] = true; } if (j < num && i < num2 && fogGrid[cellIndices.CellToIndex(i + 1, j + 1)]) { this.vertsCovered[4] = true; } if (j > 0 && i < num2 && fogGrid[cellIndices.CellToIndex(i + 1, j - 1)]) { this.vertsCovered[6] = true; } } for (int m = 0; m < 9; m++) { byte a; if (this.vertsCovered[m]) { a = 255; flag = true; } else { a = 0; } subMesh.colors.Add(new Color32(255, 255, 255, a)); } } } if (flag) { subMesh.disabled = false; subMesh.FinalizeMesh(MeshParts.Colors); } else { subMesh.disabled = true; } }
public override void Regenerate() { if (!MatBases.SunShadow.shader.isSupported) { return; } Building[] innerArray = base.Map.edificeGrid.InnerArray; float y = AltitudeLayer.Shadows.AltitudeFor(); CellRect cellRect = new CellRect(this.section.botLeft.x, this.section.botLeft.z, 17, 17); cellRect.ClipInsideMap(base.Map); LayerSubMesh subMesh = base.GetSubMesh(MatBases.SunShadow); subMesh.Clear(MeshParts.All); subMesh.verts.Capacity = cellRect.Area * 2; subMesh.tris.Capacity = cellRect.Area * 4; subMesh.colors.Capacity = cellRect.Area * 2; CellIndices cellIndices = base.Map.cellIndices; for (int i = cellRect.minX; i <= cellRect.maxX; i++) { for (int j = cellRect.minZ; j <= cellRect.maxZ; j++) { Thing thing = innerArray[cellIndices.CellToIndex(i, j)]; if (thing != null && thing.def.staticSunShadowHeight > 0f) { float staticSunShadowHeight = thing.def.staticSunShadowHeight; Color32 item = new Color32(0, 0, 0, (byte)(255f * staticSunShadowHeight)); int count = subMesh.verts.Count; subMesh.verts.Add(new Vector3((float)i, y, (float)j)); subMesh.verts.Add(new Vector3((float)i, y, (float)(j + 1))); subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1))); subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)j)); subMesh.colors.Add(SectionLayer_SunShadows.LowVertexColor); subMesh.colors.Add(SectionLayer_SunShadows.LowVertexColor); subMesh.colors.Add(SectionLayer_SunShadows.LowVertexColor); subMesh.colors.Add(SectionLayer_SunShadows.LowVertexColor); int count2 = subMesh.verts.Count; subMesh.tris.Add(count2 - 4); subMesh.tris.Add(count2 - 3); subMesh.tris.Add(count2 - 2); subMesh.tris.Add(count2 - 4); subMesh.tris.Add(count2 - 2); subMesh.tris.Add(count2 - 1); if (i > 0) { thing = innerArray[cellIndices.CellToIndex(i - 1, j)]; if (thing == null || thing.def.staticSunShadowHeight < staticSunShadowHeight) { int count3 = subMesh.verts.Count; subMesh.verts.Add(new Vector3((float)i, y, (float)j)); subMesh.verts.Add(new Vector3((float)i, y, (float)(j + 1))); subMesh.colors.Add(item); subMesh.colors.Add(item); subMesh.tris.Add(count + 1); subMesh.tris.Add(count); subMesh.tris.Add(count3); subMesh.tris.Add(count3); subMesh.tris.Add(count3 + 1); subMesh.tris.Add(count + 1); } } if (i < base.Map.Size.x - 1) { thing = innerArray[cellIndices.CellToIndex(i + 1, j)]; if (thing == null || thing.def.staticSunShadowHeight < staticSunShadowHeight) { int count4 = subMesh.verts.Count; subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1))); subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)j)); subMesh.colors.Add(item); subMesh.colors.Add(item); subMesh.tris.Add(count + 2); subMesh.tris.Add(count4); subMesh.tris.Add(count4 + 1); subMesh.tris.Add(count4 + 1); subMesh.tris.Add(count + 3); subMesh.tris.Add(count + 2); } } if (j > 0) { thing = innerArray[cellIndices.CellToIndex(i, j - 1)]; if (thing == null || thing.def.staticSunShadowHeight < staticSunShadowHeight) { int count5 = subMesh.verts.Count; subMesh.verts.Add(new Vector3((float)i, y, (float)j)); subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)j)); subMesh.colors.Add(item); subMesh.colors.Add(item); subMesh.tris.Add(count); subMesh.tris.Add(count + 3); subMesh.tris.Add(count5); subMesh.tris.Add(count + 3); subMesh.tris.Add(count5 + 1); subMesh.tris.Add(count5); } } } } } if (subMesh.verts.Count > 0) { subMesh.FinalizeMesh(MeshParts.Verts | MeshParts.Tris | MeshParts.Colors); float num = Mathf.Max(15f, 15f); Vector3 size = subMesh.mesh.bounds.size; size.x += 2f * num + 2f; size.z += 2f * num + 2f; subMesh.mesh.bounds = new Bounds(subMesh.mesh.bounds.center, size); } }
public override void Regenerate() { LayerSubMesh subMesh = GetSubMesh(MatBases.LightOverlay); if (subMesh.verts.Count == 0) { MakeBaseGeometry(subMesh); } Color32[] array = new Color32[subMesh.verts.Count]; int maxX = sectRect.maxX; int maxZ = sectRect.maxZ; int width = sectRect.Width; Map map = base.Map; int x = map.Size.x; Thing[] innerArray = map.edificeGrid.InnerArray; Thing[] array2 = innerArray; int num = array2.Length; RoofGrid roofGrid = map.roofGrid; CellIndices cellIndices = map.cellIndices; CalculateVertexIndices(sectRect.minX, sectRect.minZ, out int botLeft, out int _, out int _, out int _, out int _); int num2 = cellIndices.CellToIndex(new IntVec3(sectRect.minX, 0, sectRect.minZ)); int[] array3 = new int[4] { -map.Size.x - 1, -map.Size.x, -1, 0 }; int[] array4 = new int[4] { -1, -1, 0, 0 }; for (int i = sectRect.minZ; i <= maxZ + 1; i++) { int num3 = num2 / x; int num4 = sectRect.minX; while (num4 <= maxX + 1) { ColorInt a = new ColorInt(0, 0, 0, 0); int num5 = 0; bool flag = false; for (int j = 0; j < 4; j++) { int num6 = num2 + array3[j]; if (num6 >= 0 && num6 < num && num6 / x == num3 + array4[j]) { Thing thing = array2[num6]; RoofDef roofDef = roofGrid.RoofAt(num6); if (roofDef != null && (roofDef.isThickRoof || thing == null || !thing.def.holdsRoof || thing.def.altitudeLayer == AltitudeLayer.DoorMoveable)) { flag = true; } if (thing == null || !thing.def.blockLight) { a += glowGrid[num6]; num5++; } } } if (num5 > 0) { array[botLeft] = (a / num5).ToColor32; } else { array[botLeft] = new Color32(0, 0, 0, 0); } if (flag && array[botLeft].a < 100) { array[botLeft].a = 100; } num4++; botLeft++; num2++; } int num7 = maxX + 2 - sectRect.minX; botLeft -= num7; num2 -= num7; botLeft += width + 1; num2 += map.Size.x; } CalculateVertexIndices(sectRect.minX, sectRect.minZ, out int botLeft2, out int _, out int _, out int _, out int center2); int num8 = cellIndices.CellToIndex(sectRect.minX, sectRect.minZ); for (int k = sectRect.minZ; k <= maxZ; k++) { int num9 = sectRect.minX; while (num9 <= maxX) { ColorInt colorInt = default(ColorInt) + array[botLeft2]; colorInt += array[botLeft2 + 1]; colorInt += array[botLeft2 + width + 1]; colorInt += array[botLeft2 + width + 2]; array[center2] = new Color32((byte)(colorInt.r / 4), (byte)(colorInt.g / 4), (byte)(colorInt.b / 4), (byte)(colorInt.a / 4)); if (array[center2].a < 100 && roofGrid.Roofed(num8)) { Thing thing2 = array2[num8]; if (thing2 == null || !thing2.def.holdsRoof) { array[center2].a = 100; } } num9++; botLeft2++; center2++; num8++; } botLeft2++; num8 -= width; num8 += map.Size.x; } subMesh.mesh.colors32 = array; }
public void AddFloodGlowFor(CompGlower theGlower, Color32[] glowGrid) { cellIndices = map.cellIndices; this.glowGrid = glowGrid; glower = theGlower; attenLinearSlope = -1f / theGlower.Props.glowRadius; Building[] innerArray = map.edificeGrid.InnerArray; IntVec3 position = theGlower.parent.Position; int num = Mathf.RoundToInt(glower.Props.glowRadius * 100f); int curIndex = cellIndices.CellToIndex(position); int num2 = 0; bool flag = UnityData.isDebugBuild && DebugViewSettings.drawGlow; InitStatusesAndPushStartNode(ref curIndex, position); while (openSet.Count != 0) { curIndex = openSet.Pop(); IntVec3 c = cellIndices.IndexToCell(curIndex); calcGrid[curIndex].status = statusFinalizedValue; SetGlowGridFromDist(curIndex); if (flag) { map.debugDrawer.FlashCell(c, (float)calcGrid[curIndex].intDist / 10f, calcGrid[curIndex].intDist.ToString("F2")); num2++; } for (int i = 0; i < 8; i++) { uint num3 = (uint)(c.x + Directions[i, 0]); uint num4 = (uint)(c.z + Directions[i, 1]); if (num3 < mapSizeX && num4 < mapSizeZ) { int x = (int)num3; int z = (int)num4; int num5 = cellIndices.CellToIndex(x, z); if (calcGrid[num5].status != statusFinalizedValue) { blockers[i] = innerArray[num5]; if (blockers[i] != null) { if (blockers[i].def.blockLight) { continue; } blockers[i] = null; } int num6 = (i >= 4) ? 141 : 100; int num7 = calcGrid[curIndex].intDist + num6; if (num7 <= num) { switch (i) { case 4: if (blockers[0] != null && blockers[1] != null) { break; } goto default; case 5: if (blockers[1] != null && blockers[2] != null) { break; } goto default; case 6: if (blockers[2] != null && blockers[3] != null) { break; } goto default; case 7: if (blockers[0] != null && blockers[3] != null) { break; } goto default; default: if (calcGrid[num5].status <= statusUnseenValue) { calcGrid[num5].intDist = 999999; calcGrid[num5].status = statusOpenValue; } if (num7 < calcGrid[num5].intDist) { calcGrid[num5].intDist = num7; calcGrid[num5].status = statusOpenValue; openSet.Push(num5); } break; } } } } } } }
public void AddFloodGlowFor(CompGlower theGlower, Color32[] glowGrid) { cellIndices = map.cellIndices; this.glowGrid = glowGrid; glower = theGlower; attenLinearSlope = -1f / theGlower.Props.glowRadius; Building[] innerArray = map.edificeGrid.InnerArray; IntVec3 position = theGlower.parent.Position; int num = Mathf.RoundToInt(glower.Props.glowRadius * 100f); int curIndex = cellIndices.CellToIndex(position); int num2 = 0; InitStatusesAndPushStartNode(ref curIndex, position); while (openSet.Count != 0) { curIndex = openSet.Pop(); IntVec3 intVec = cellIndices.IndexToCell(curIndex); calcGrid[curIndex].status = statusFinalizedValue; SetGlowGridFromDist(curIndex); for (int i = 0; i < 8; i++) { uint num3 = (uint)(intVec.x + Directions[i, 0]); uint num4 = (uint)(intVec.z + Directions[i, 1]); if (num3 >= mapSizeX || num4 >= mapSizeZ) { continue; } int x = (int)num3; int z = (int)num4; int num5 = cellIndices.CellToIndex(x, z); if (calcGrid[num5].status == statusFinalizedValue) { continue; } blockers[i] = innerArray[num5]; if (blockers[i] != null) { if (blockers[i].def.blockLight) { continue; } blockers[i] = null; } int num6 = (i >= 4) ? 141 : 100; int num7 = calcGrid[curIndex].intDist + num6; if (num7 > num) { continue; } switch (i) { case 4: if (blockers[0] != null && blockers[1] != null) { continue; } break; case 5: if (blockers[1] != null && blockers[2] != null) { continue; } break; case 6: if (blockers[2] != null && blockers[3] != null) { continue; } break; case 7: if (blockers[0] != null && blockers[3] != null) { continue; } break; } if (calcGrid[num5].status <= statusUnseenValue) { calcGrid[num5].intDist = 999999; calcGrid[num5].status = statusOpenValue; } if (num7 < calcGrid[num5].intDist) { calcGrid[num5].intDist = num7; calcGrid[num5].status = statusOpenValue; openSet.Push(num5); } } } }
public override void Regenerate() { Building[] innerArray = base.Map.edificeGrid.InnerArray; float y = AltitudeLayer.Shadows.AltitudeFor(); CellRect cellRect = new CellRect(this.section.botLeft.x, this.section.botLeft.z, 17, 17); cellRect.ClipInsideMap(base.Map); LayerSubMesh sm = base.GetSubMesh(MatBases.EdgeShadow); sm.Clear(MeshParts.All); sm.verts.Capacity = cellRect.Area * 4; sm.colors.Capacity = cellRect.Area * 4; sm.tris.Capacity = cellRect.Area * 8; bool[] array = new bool[4]; bool[] array2 = new bool[4]; bool[] array3 = new bool[4]; CellIndices cellIndices = base.Map.cellIndices; for (int i = cellRect.minX; i <= cellRect.maxX; i++) { for (int j = cellRect.minZ; j <= cellRect.maxZ; j++) { Thing thing = innerArray[cellIndices.CellToIndex(i, j)]; if (thing != null && thing.def.castEdgeShadows) { sm.verts.Add(new Vector3((float)i, y, (float)j)); sm.verts.Add(new Vector3((float)i, y, (float)(j + 1))); sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1))); sm.verts.Add(new Vector3((float)(i + 1), y, (float)j)); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); int count = sm.verts.Count; sm.tris.Add(count - 4); sm.tris.Add(count - 3); sm.tris.Add(count - 2); sm.tris.Add(count - 4); sm.tris.Add(count - 2); sm.tris.Add(count - 1); } else { array[0] = false; array[1] = false; array[2] = false; array[3] = false; array2[0] = false; array2[1] = false; array2[2] = false; array2[3] = false; array3[0] = false; array3[1] = false; array3[2] = false; array3[3] = false; IntVec3 a = new IntVec3(i, 0, j); IntVec3[] cardinalDirectionsAround = GenAdj.CardinalDirectionsAround; for (int k = 0; k < 4; k++) { IntVec3 c = a + cardinalDirectionsAround[k]; if (c.InBounds(base.Map)) { thing = innerArray[cellIndices.CellToIndex(c)]; if (thing != null && thing.def.castEdgeShadows) { array2[k] = true; array[(k + 3) % 4] = true; array[k] = true; } } } IntVec3[] diagonalDirectionsAround = GenAdj.DiagonalDirectionsAround; for (int l = 0; l < 4; l++) { if (!array[l]) { IntVec3 c = a + diagonalDirectionsAround[l]; if (c.InBounds(base.Map)) { thing = innerArray[cellIndices.CellToIndex(c)]; if (thing != null && thing.def.castEdgeShadows) { array[l] = true; array3[l] = true; } } } } Action <int> action = delegate(int idx) { sm.tris.Add(sm.verts.Count - 2); sm.tris.Add(idx); sm.tris.Add(sm.verts.Count - 1); sm.tris.Add(sm.verts.Count - 1); sm.tris.Add(idx); sm.tris.Add(idx + 1); }; Action action2 = delegate() { sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.colors.Add(SectionLayer_EdgeShadows.Lit); sm.colors.Add(SectionLayer_EdgeShadows.Lit); sm.tris.Add(sm.verts.Count - 3); sm.tris.Add(sm.verts.Count - 2); sm.tris.Add(sm.verts.Count - 1); }; int count2 = sm.verts.Count; if (array[0]) { if (array2[0] || array2[1]) { float num2; float num = num2 = 0f; if (array2[0]) { num = 0.45f; } if (array2[1]) { num2 = 0.45f; } sm.verts.Add(new Vector3((float)i, y, (float)j)); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.verts.Add(new Vector3((float)i + num2, y, (float)j + num)); sm.colors.Add(SectionLayer_EdgeShadows.Lit); if (array[1] && !array3[1]) { action(sm.verts.Count); } } else { sm.verts.Add(new Vector3((float)i, y, (float)j)); sm.verts.Add(new Vector3((float)i, y, (float)j + 0.45f)); sm.verts.Add(new Vector3((float)i + 0.45f, y, (float)j)); action2(); } } if (array[1]) { if (array2[1] || array2[2]) { float num2; float num = num2 = 0f; if (array2[1]) { num2 = 0.45f; } if (array2[2]) { num = -0.45f; } sm.verts.Add(new Vector3((float)i, y, (float)(j + 1))); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.verts.Add(new Vector3((float)i + num2, y, (float)(j + 1) + num)); sm.colors.Add(SectionLayer_EdgeShadows.Lit); if (array[2] && !array3[2]) { action(sm.verts.Count); } } else { sm.verts.Add(new Vector3((float)i, y, (float)(j + 1))); sm.verts.Add(new Vector3((float)i + 0.45f, y, (float)(j + 1))); sm.verts.Add(new Vector3((float)i, y, (float)(j + 1) - 0.45f)); action2(); } } if (array[2]) { if (array2[2] || array2[3]) { float num2; float num = num2 = 0f; if (array2[2]) { num = -0.45f; } if (array2[3]) { num2 = -0.45f; } sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1))); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.verts.Add(new Vector3((float)(i + 1) + num2, y, (float)(j + 1) + num)); sm.colors.Add(SectionLayer_EdgeShadows.Lit); if (array[3] && !array3[3]) { action(sm.verts.Count); } } else { sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1))); sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1) - 0.45f)); sm.verts.Add(new Vector3((float)(i + 1) - 0.45f, y, (float)(j + 1))); action2(); } } if (array[3]) { if (array2[3] || array2[0]) { float num2; float num = num2 = 0f; if (array2[3]) { num2 = -0.45f; } if (array2[0]) { num = 0.45f; } sm.verts.Add(new Vector3((float)(i + 1), y, (float)j)); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.verts.Add(new Vector3((float)(i + 1) + num2, y, (float)j + num)); sm.colors.Add(SectionLayer_EdgeShadows.Lit); if (array[0] && !array3[0]) { action(count2); } } else { sm.verts.Add(new Vector3((float)(i + 1), y, (float)j)); sm.verts.Add(new Vector3((float)(i + 1) - 0.45f, y, (float)j)); sm.verts.Add(new Vector3((float)(i + 1), y, (float)j + 0.45f)); action2(); } } } } } if (sm.verts.Count > 0) { sm.FinalizeMesh(MeshParts.Verts | MeshParts.Tris | MeshParts.Colors); } }
public override void Regenerate() { LayerSubMesh subMesh = base.GetSubMesh(MatBases.Snow); if (subMesh.mesh.vertexCount == 0) { SectionLayerGeometryMaker_Solid.MakeBaseGeometry(this.section, subMesh, AltitudeLayer.Terrain); } subMesh.Clear(MeshParts.Colors); float[] depthGridDirect_Unsafe = base.Map.snowGrid.DepthGridDirect_Unsafe; CellRect cellRect = this.section.CellRect; int num = base.Map.Size.z - 1; int num2 = base.Map.Size.x - 1; bool flag = false; CellIndices cellIndices = base.Map.cellIndices; for (int i = cellRect.minX; i <= cellRect.maxX; i++) { for (int j = cellRect.minZ; j <= cellRect.maxZ; j++) { float num3 = depthGridDirect_Unsafe[cellIndices.CellToIndex(i, j)]; int num4 = cellIndices.CellToIndex(i, j - 1); float num5 = (j <= 0) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i - 1, j - 1); float num6 = (j <= 0 || i <= 0) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i - 1, j); float num7 = (i <= 0) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i - 1, j + 1); float num8 = (j >= num || i <= 0) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i, j + 1); float num9 = (j >= num) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i + 1, j + 1); float num10 = (j >= num || i >= num2) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i + 1, j); float num11 = (i >= num2) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i + 1, j - 1); float num12 = (j <= 0 || i >= num2) ? num3 : depthGridDirect_Unsafe[num4]; this.vertDepth[0] = (num5 + num6 + num7 + num3) / 4f; this.vertDepth[1] = (num7 + num3) / 2f; this.vertDepth[2] = (num7 + num8 + num9 + num3) / 4f; this.vertDepth[3] = (num9 + num3) / 2f; this.vertDepth[4] = (num9 + num10 + num11 + num3) / 4f; this.vertDepth[5] = (num11 + num3) / 2f; this.vertDepth[6] = (num11 + num12 + num5 + num3) / 4f; this.vertDepth[7] = (num5 + num3) / 2f; this.vertDepth[8] = num3; for (int k = 0; k < 9; k++) { if (this.vertDepth[k] > 0.01f) { flag = true; } subMesh.colors.Add(SectionLayer_Snow.SnowDepthColor(this.vertDepth[k])); } } } if (flag) { subMesh.disabled = false; subMesh.FinalizeMesh(MeshParts.Colors); } else { subMesh.disabled = true; } }
public void AddFloodGlowFor(CompGlower theGlower, Color32[] glowGrid) { this.cellIndices = this.map.cellIndices; this.glowGrid = glowGrid; this.glower = theGlower; this.attenLinearSlope = (float)(-1.0 / theGlower.Props.glowRadius); Building[] innerArray = this.map.edificeGrid.InnerArray; IntVec3 position = theGlower.parent.Position; int num = Mathf.RoundToInt((float)(this.glower.Props.glowRadius * 100.0)); int num2 = this.cellIndices.CellToIndex(position); int num3 = 0; bool flag = UnityData.isDebugBuild && DebugViewSettings.drawGlow; this.InitStatusesAndPushStartNode(ref num2, position); while (this.openSet.Count != 0) { num2 = this.openSet.Pop(); IntVec3 c = this.cellIndices.IndexToCell(num2); this.calcGrid[num2].status = this.statusFinalizedValue; this.SetGlowGridFromDist(num2); if (flag) { this.map.debugDrawer.FlashCell(c, (float)((float)this.calcGrid[num2].intDist / 10.0), this.calcGrid[num2].intDist.ToString("F2"), 50); num3++; } for (int i = 0; i < 8; i++) { uint num4 = (uint)(c.x + GlowFlooder.Directions[i, 0]); uint num5 = (uint)(c.z + GlowFlooder.Directions[i, 1]); if (num4 < this.mapSizeX && num5 < this.mapSizeZ) { int x = (int)num4; int z = (int)num5; int num6 = this.cellIndices.CellToIndex(x, z); if (this.calcGrid[num6].status != this.statusFinalizedValue) { this.blockers[i] = innerArray[num6]; if (this.blockers[i] != null) { if (this.blockers[i].def.blockLight) { continue; } this.blockers[i] = null; } int num7 = (i >= 4) ? 141 : 100; int num8 = this.calcGrid[num2].intDist + num7; if (num8 <= num) { switch (i) { case 4: if (this.blockers[0] != null && this.blockers[1] != null) { break; } goto default; case 5: if (this.blockers[1] != null && this.blockers[2] != null) { break; } goto default; case 6: if (this.blockers[2] != null && this.blockers[3] != null) { break; } goto default; case 7: if (this.blockers[0] != null && this.blockers[3] != null) { break; } goto default; default: if (this.calcGrid[num6].status <= this.statusUnseenValue) { this.calcGrid[num6].intDist = 999999; this.calcGrid[num6].status = this.statusOpenValue; } if (num8 < this.calcGrid[num6].intDist) { this.calcGrid[num6].intDist = num8; this.calcGrid[num6].status = this.statusOpenValue; this.openSet.Push(num6); } break; } } } } } } }