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); 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 num2 = (uint)(intVec.x + Directions[i, 0]); uint num3 = (uint)(intVec.z + Directions[i, 1]); if (num2 >= mapSizeX || num3 >= mapSizeZ) { continue; } int x = (int)num2; int z = (int)num3; int num4 = cellIndices.CellToIndex(x, z); if (calcGrid[num4].status == statusFinalizedValue) { continue; } blockers[i] = innerArray[num4]; if (blockers[i] != null) { if (blockers[i].def.blockLight) { continue; } blockers[i] = null; } int num5 = ((i >= 4) ? 141 : 100); int num6 = calcGrid[curIndex].intDist + num5; if (num6 > 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[num4].status <= statusUnseenValue) { calcGrid[num4].intDist = 999999; calcGrid[num4].status = statusOpenValue; } if (num6 < calcGrid[num4].intDist) { calcGrid[num4].intDist = num6; calcGrid[num4].status = statusOpenValue; openSet.Push(num4); } } } }
public void FloodFill(IntVec3 root, Predicate <IntVec3> passCheck, Func <IntVec3, int, bool> processor, int maxCellsToProcess = int.MaxValue, bool rememberParents = false, IEnumerable <IntVec3> extraRoots = null) { if (working) { Log.Error("Nested FloodFill calls are not allowed. This will cause bugs."); } working = true; ClearVisited(); if (rememberParents && parentGrid == null) { parentGrid = new CellGrid(map); } if (root.IsValid && extraRoots == null && !passCheck(root)) { if (rememberParents) { parentGrid[root] = IntVec3.Invalid; } working = false; return; } int area = map.Area; IntVec3[] cardinalDirectionsAround = GenAdj.CardinalDirectionsAround; int num = cardinalDirectionsAround.Length; CellIndices cellIndices = map.cellIndices; int num2 = 0; openSet.Clear(); if (root.IsValid) { int num3 = cellIndices.CellToIndex(root); visited.Add(num3); traversalDistance[num3] = 0; 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]); visited.Add(num4); traversalDistance[num4] = 0; openSet.Enqueue(list[i]); } } else { foreach (IntVec3 extraRoot in extraRoots) { int num5 = cellIndices.CellToIndex(extraRoot); visited.Add(num5); traversalDistance[num5] = 0; openSet.Enqueue(extraRoot); } } } if (rememberParents) { for (int j = 0; j < visited.Count; j++) { IntVec3 intVec = cellIndices.IndexToCell(visited[j]); parentGrid[visited[j]] = (passCheck(intVec) ? intVec : IntVec3.Invalid); } } while (openSet.Count > 0) { IntVec3 intVec2 = openSet.Dequeue(); int num6 = traversalDistance[cellIndices.CellToIndex(intVec2)]; if (processor(intVec2, num6)) { break; } num2++; if (num2 == maxCellsToProcess) { break; } for (int k = 0; k < num; k++) { IntVec3 intVec3 = intVec2 + cardinalDirectionsAround[k]; int num7 = cellIndices.CellToIndex(intVec3); if (intVec3.InBounds(map) && traversalDistance[num7] == -1 && passCheck(intVec3)) { visited.Add(num7); openSet.Enqueue(intVec3); traversalDistance[num7] = num6 + 1; if (rememberParents) { parentGrid[num7] = intVec2; } } } if (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."); working = false; return; } } working = false; }
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; } } } } } } }