public bool TryGetAverageCachedRoomGroupTemp(RoomGroup r, out float result) { CellIndices cellIndices = this.map.cellIndices; foreach (IntVec3 current in r.Cells) { CachedTempInfo item = this.map.temperatureCache.tempCache[cellIndices.CellToIndex(current)]; if (item.numCells > 0 && !this.processedRoomGroupIDs.Contains(item.roomGroupID)) { this.relevantTempInfoList.Add(item); this.processedRoomGroupIDs.Add(item.roomGroupID); } } int num = 0; float num2 = 0f; foreach (CachedTempInfo current2 in this.relevantTempInfoList) { num += current2.numCells; num2 += current2.temperature * (float)current2.numCells; } result = num2 / (float)num; bool result2 = !this.relevantTempInfoList.NullOrEmpty <CachedTempInfo>(); this.processedRoomGroupIDs.Clear(); this.relevantTempInfoList.Clear(); return(result2); }
public void Register(Building ed) { CellIndices cellIndices = this.map.cellIndices; CellRect cellRect = ed.OccupiedRect(); for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { IntVec3 intVec = new IntVec3(j, 0, i); if (UnityData.isDebugBuild && this[intVec] != null && !this[intVec].Destroyed) { Log.Error(string.Concat(new object[] { "Added edifice ", ed.LabelCap, " over edifice ", this[intVec].LabelCap, " at ", intVec, ". Destroying old edifice." }), false); this[intVec].Destroy(DestroyMode.Vanish); return; } this.innerArray[cellIndices.CellToIndex(intVec)] = ed; } } }
public override void Regenerate() { if (MatBases.SunShadow.shader.isSupported) { 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 bool TryGetAverageCachedRoomGroupTemp(RoomGroup r, out float result) { CellIndices cellIndices = map.cellIndices; foreach (IntVec3 cell in r.Cells) { CachedTempInfo item = map.temperatureCache.tempCache[cellIndices.CellToIndex(cell)]; if (item.numCells > 0 && !processedRoomGroupIDs.Contains(item.roomGroupID)) { relevantTempInfoList.Add(item); processedRoomGroupIDs.Add(item.roomGroupID); } } int num = 0; float num2 = 0f; foreach (CachedTempInfo relevantTempInfo in relevantTempInfoList) { num += relevantTempInfo.numCells; num2 += relevantTempInfo.temperature * (float)relevantTempInfo.numCells; } result = num2 / (float)num; bool result2 = !relevantTempInfoList.NullOrEmpty(); processedRoomGroupIDs.Clear(); relevantTempInfoList.Clear(); return result2; }
private void InitStatusesAndPushStartNode(ref int curIndex, IntVec3 start) { statusUnseenValue += 3u; statusOpenValue += 3u; statusFinalizedValue += 3u; curIndex = cellIndices.CellToIndex(start); openSet.Clear(); calcGrid[curIndex].intDist = 100; openSet.Clear(); openSet.Push(curIndex); }
private void RebuildZoneGrid() { CellIndices cellIndices = this.map.cellIndices; this.zoneGrid = new Zone[cellIndices.NumGridCells]; foreach (Zone allZone in this.allZones) { foreach (IntVec3 item in allZone) { this.zoneGrid[cellIndices.CellToIndex(item)] = allZone; } } }
public void DeRegister(Building ed) { CellIndices cellIndices = this.map.cellIndices; CellRect cellRect = ed.OccupiedRect(); for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { this.innerArray[cellIndices.CellToIndex(j, i)] = null; } } }
private void RebuildZoneGrid() { CellIndices cellIndices = this.map.cellIndices; this.zoneGrid = new Zone[cellIndices.NumGridCells]; foreach (Zone current in this.allZones) { foreach (IntVec3 current2 in current) { this.zoneGrid[cellIndices.CellToIndex(current2)] = current; } } }
public void ApplyLoadedDataToRegions() { if (tempGrid != null) { CellIndices cellIndices = map.cellIndices; foreach (Region item in map.regionGrid.AllRegions_NoRebuild_InvalidAllowed) { if (item.Room != null) { item.Room.Group.Temperature = TempShortToFloat(tempGrid[cellIndices.CellToIndex(item.Cells.First())]); } } tempGrid = null; } }
public void DrawDynamicThings() { if (!DebugViewSettings.drawThingsDynamic) { return; } this.drawingNow = true; try { bool[] fogGrid = this.map.fogGrid.fogGrid; CellRect cellRect = Find.CameraDriver.CurrentViewRect; cellRect.ClipInsideMap(this.map); cellRect = cellRect.ExpandedBy(1); CellIndices cellIndices = this.map.cellIndices; foreach (Thing current in this.drawThings) { IntVec3 position = current.Position; if (cellRect.Contains(position) || current.def.drawOffscreen) { if (!fogGrid[cellIndices.CellToIndex(position)] || current.def.seeThroughFog) { if (current.def.hideAtSnowDepth >= 1f || this.map.snowGrid.GetDepth(current.Position) <= current.def.hideAtSnowDepth) { try { current.Draw(); } catch (Exception ex) { Log.Error(string.Concat(new object[] { "Exception drawing ", current, ": ", ex.ToString() }), false); } } } } } } catch (Exception arg) { Log.Error("Exception drawing dynamic things: " + arg, false); } this.drawingNow = false; }
public override void Regenerate() { base.ClearSubMeshes(MeshParts.All); this.scats.RemoveAll((SectionLayer_TerrainScatter.Scatterable scat) => !scat.IsOnValidTerrain); int num = 0; TerrainDef[] topGrid = base.Map.terrainGrid.topGrid; CellRect cellRect = this.section.CellRect; CellIndices cellIndices = base.Map.cellIndices; for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { if (topGrid[cellIndices.CellToIndex(j, i)].scatterType != null) { num++; } } } num /= 40; int num2 = 0; while (this.scats.Count < num && num2 < 200) { num2++; IntVec3 randomCell = this.section.CellRect.RandomCell; string terrScatType = base.Map.terrainGrid.TerrainAt(randomCell).scatterType; if (terrScatType != null && !randomCell.Filled(base.Map)) { ScatterableDef def2; if ((from def in DefDatabase <ScatterableDef> .AllDefs where def.scatterType == terrScatType select def).TryRandomElement(out def2)) { Vector3 loc = new Vector3((float)randomCell.x + Rand.Value, (float)randomCell.y, (float)randomCell.z + Rand.Value); SectionLayer_TerrainScatter.Scatterable scatterable = new SectionLayer_TerrainScatter.Scatterable(def2, loc, base.Map); this.scats.Add(scatterable); scatterable.PrintOnto(this); } } } for (int k = 0; k < this.scats.Count; k++) { this.scats[k].PrintOnto(this); } base.FinalizeMesh(MeshParts.All); }
internal void SetAllFogged() { CellIndices cellIndices = map.cellIndices; if (fogGrid == null) { fogGrid = new bool[cellIndices.NumGridCells]; } foreach (IntVec3 allCell in map.AllCells) { fogGrid[cellIndices.CellToIndex(allCell)] = true; } if (Current.ProgramState == ProgramState.Playing) { map.roofGrid.Drawer.SetDirty(); } }
public void Notify_LinkerCreatedOrDestroyed(Thing linker) { CellIndices cellIndices = map.cellIndices; foreach (IntVec3 item in linker.OccupiedRect()) { LinkFlags linkFlags = LinkFlags.None; List <Thing> list = map.thingGrid.ThingsListAt(item); for (int i = 0; i < list.Count; i++) { if (list[i].def.graphicData != null) { linkFlags |= list[i].def.graphicData.linkFlags; } } linkGrid[cellIndices.CellToIndex(item)] = linkFlags; } }
public void Register(Blueprint ed) { CellIndices cellIndices = map.cellIndices; CellRect cellRect = ed.OccupiedRect(); for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { int num = cellIndices.CellToIndex(j, i); if (innerArray[num] == null) { innerArray[num] = new List <Blueprint>(); } innerArray[num].Add(ed); } } }
public void DeRegister(Blueprint ed) { CellIndices cellIndices = map.cellIndices; CellRect cellRect = ed.OccupiedRect(); for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { int num = cellIndices.CellToIndex(j, i); innerArray[num].Remove(ed); if (innerArray[num].Count == 0) { innerArray[num] = null; } } } }
public static bool WithinRangeOfRoofHolder(IntVec3 c, Map map) { CellIndices cellIndices = map.cellIndices; Building[] innerArray = map.edificeGrid.InnerArray; for (int i = 0; i < RoofCollapseUtility.RoofSupportRadialCellsCount; i++) { IntVec3 c2 = c + GenRadial.RadialPattern[i]; if (c2.InBounds(map)) { Building building = innerArray[cellIndices.CellToIndex(c2)]; if (building != null && building.def.holdsRoof) { return(true); } } } return(false); }
public override void Regenerate() { ClearSubMeshes(MeshParts.All); scats.RemoveAll((Scatterable scat) => !scat.IsOnValidTerrain); int num = 0; TerrainDef[] topGrid = base.Map.terrainGrid.topGrid; CellRect cellRect = section.CellRect; CellIndices cellIndices = base.Map.cellIndices; for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { if (topGrid[cellIndices.CellToIndex(j, i)].scatterType != null) { num++; } } } num /= 40; int num2 = 0; while (scats.Count < num && num2 < 200) { num2++; IntVec3 randomCell = section.CellRect.RandomCell; string terrScatType = base.Map.terrainGrid.TerrainAt(randomCell).scatterType; if (terrScatType != null && !randomCell.Filled(base.Map) && DefDatabase <ScatterableDef> .AllDefs.Where((ScatterableDef def) => def.scatterType == terrScatType).TryRandomElement(out var result)) { Scatterable scatterable = new Scatterable(loc: new Vector3((float)randomCell.x + Rand.Value, randomCell.y, (float)randomCell.z + Rand.Value), def: result, map: base.Map); scats.Add(scatterable); scatterable.PrintOnto(this); } } for (int k = 0; k < scats.Count; k++) { scats[k].PrintOnto(this); } FinalizeMesh(MeshParts.All); }
public void Notify_LinkerCreatedOrDestroyed(Thing linker) { CellIndices cellIndices = map.cellIndices; CellRect.CellRectIterator iterator = linker.OccupiedRect().GetIterator(); while (!iterator.Done()) { IntVec3 current = iterator.Current; LinkFlags linkFlags = LinkFlags.None; List <Thing> list = map.thingGrid.ThingsListAt(current); for (int i = 0; i < list.Count; i++) { if (list[i].def.graphicData != null) { linkFlags |= list[i].def.graphicData.linkFlags; } } linkGrid[cellIndices.CellToIndex(current)] = linkFlags; iterator.MoveNext(); } }
private bool CheckCellBasedReachability(IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams) { IntVec3 foundCell = IntVec3.Invalid; Region[] directRegionGrid = this.regionGrid.DirectGrid; PathGrid pathGrid = this.map.pathGrid; CellIndices cellIndices = this.map.cellIndices; this.map.floodFiller.FloodFill(start, delegate(IntVec3 c) { int num = cellIndices.CellToIndex(c); if ((traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParams.mode == TraverseMode.NoPassClosedDoorsOrWater) && c.GetTerrain(this.map).IsWater) { return(false); } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings || traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater) { if (!pathGrid.WalkableFast(num)) { Building edifice = c.GetEdifice(this.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, false); if (!pathGrid.WalkableFast(num)) { return(false); } } Region region = directRegionGrid[num]; return(region == null || region.Allows(traverseParams, false)); }, delegate(IntVec3 c) { if (ReachabilityImmediate.CanReachImmediate(c, dest, this.map, peMode, traverseParams.pawn)) { foundCell = c; return(true); } return(false); }, 2147483647, false, null); if (foundCell.IsValid) { if (this.CanUseCache(traverseParams.mode)) { Region validRegionAt = this.regionGrid.GetValidRegionAt(foundCell); if (validRegionAt != null) { for (int i = 0; i < this.startingRegions.Count; i++) { this.cache.AddCachedResult(this.startingRegions[i].Room, validRegionAt.Room, traverseParams, true); } } } return(true); } if (this.CanUseCache(traverseParams.mode)) { for (int j = 0; j < this.startingRegions.Count; j++) { for (int k = 0; k < this.destRegions.Count; k++) { this.cache.AddCachedResult(this.startingRegions[j].Room, this.destRegions[k].Room, traverseParams, false); } } } return(false); }
public void DrawDynamicThings() { if (DebugViewSettings.drawThingsDynamic) { drawingNow = true; try { bool[] fogGrid = map.fogGrid.fogGrid; CellRect currentViewRect = Find.CameraDriver.CurrentViewRect; currentViewRect.ClipInsideMap(map); currentViewRect = currentViewRect.ExpandedBy(1); CellIndices cellIndices = map.cellIndices; foreach (Thing drawThing in drawThings) { IntVec3 position = drawThing.Position; if ((currentViewRect.Contains(position) || drawThing.def.drawOffscreen) && (!fogGrid[cellIndices.CellToIndex(position)] || drawThing.def.seeThroughFog) && (!(drawThing.def.hideAtSnowDepth < 1f) || !(map.snowGrid.GetDepth(drawThing.Position) > drawThing.def.hideAtSnowDepth))) { try { drawThing.Draw(); } catch (Exception ex) { Log.Error("Exception drawing " + drawThing + ": " + ex.ToString()); } } } } catch (Exception arg) { Log.Error("Exception drawing dynamic things: " + arg); } drawingNow = false; } }
public override void Regenerate() { if (!MatBases.SunShadow.shader.isSupported) { return; } SectionLayer_SunShadows.edificeGrid = base.Map.edificeGrid.InnerArray; float y = Altitudes.AltitudeFor(AltitudeLayer.Shadows); 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 = SectionLayer_SunShadows.edificeGrid[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 = SectionLayer_SunShadows.edificeGrid[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 = SectionLayer_SunShadows.edificeGrid[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 = SectionLayer_SunShadows.edificeGrid[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 void ApplyLoadedDataToRegions() { if (this.tempGrid != null) { CellIndices cellIndices = this.map.cellIndices; foreach (Region current in this.map.regionGrid.AllRegions_NoRebuild_InvalidAllowed) { if (current.Room != null) { current.Room.Group.Temperature = this.TempShortToFloat(this.tempGrid[cellIndices.CellToIndex(current.Cells.First <IntVec3>())]); } } this.tempGrid = null; } }
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 override void Regenerate() { Building[] innerArray = base.Map.edificeGrid.InnerArray; float y = Altitudes.AltitudeFor(AltitudeLayer.Shadows); CellRect cellRect = new CellRect(base.section.botLeft.x, base.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]; float num = 0f; float num2 = 0f; 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]) { num = (num2 = 0f); if (array2[0]) { num2 = 0.45f; } if (array2[1]) { num = 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 + num, y, (float)j + num2)); 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)((float)j + 0.44999998807907104))); sm.verts.Add(new Vector3((float)((float)i + 0.44999998807907104), y, (float)j)); action2(); } } if (array[1]) { if (array2[1] || array2[2]) { num = (num2 = 0f); if (array2[1]) { num = 0.45f; } if (array2[2]) { num2 = -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 + num, y, (float)(j + 1) + num2)); 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)((float)i + 0.44999998807907104), y, (float)(j + 1))); sm.verts.Add(new Vector3((float)i, y, (float)((float)(j + 1) - 0.44999998807907104))); action2(); } } if (array[2]) { if (array2[2] || array2[3]) { num = (num2 = 0f); if (array2[2]) { num2 = -0.45f; } if (array2[3]) { num = -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) + num, y, (float)(j + 1) + num2)); 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)((float)(j + 1) - 0.44999998807907104))); sm.verts.Add(new Vector3((float)((float)(i + 1) - 0.44999998807907104), y, (float)(j + 1))); action2(); } } if (array[3]) { if (array2[3] || array2[0]) { num = (num2 = 0f); if (array2[3]) { num = -0.45f; } if (array2[0]) { num2 = 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) + num, y, (float)j + num2)); 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)((float)(i + 1) - 0.44999998807907104), y, (float)j)); sm.verts.Add(new Vector3((float)(i + 1), y, (float)((float)j + 0.44999998807907104))); action2(); } } } } } if (sm.verts.Count > 0) { sm.FinalizeMesh(MeshParts.Verts | MeshParts.Tris | MeshParts.Colors); } }
public override void Regenerate() { LayerSubMesh subMesh = base.GetSubMesh(MatBases.LightOverlay); if (subMesh.verts.Count == 0) { this.MakeBaseGeometry(subMesh); } Color32[] array = new Color32[subMesh.verts.Count]; int maxX = this.sectRect.maxX; int maxZ = this.sectRect.maxZ; int width = this.sectRect.Width; Map map = base.Map; int x = map.Size.x; Thing[] innerArray = map.edificeGrid.InnerArray; int num = innerArray.Length; RoofGrid roofGrid = map.roofGrid; CellIndices cellIndices = map.cellIndices; int num2; int num3; int num4; int num5; int num6; this.CalculateVertexIndices(this.sectRect.minX, this.sectRect.minZ, out num2, out num3, out num4, out num5, out num6); int num7 = cellIndices.CellToIndex(new IntVec3(this.sectRect.minX, 0, this.sectRect.minZ)); int[] array2 = new int[4]; array2[0] = -map.Size.x - 1; array2[1] = -map.Size.x; array2[2] = -1; int[] array3 = array2; int[] array4 = new int[4]; array4[0] = -1; array4[1] = -1; int[] array5 = array4; for (int i = this.sectRect.minZ; i <= maxZ + 1; i++) { int num8 = num7 / x; int j = this.sectRect.minX; while (j <= maxX + 1) { ColorInt colorInt = new ColorInt(0, 0, 0, 0); int num9 = 0; bool flag = false; for (int k = 0; k < 4; k++) { int num10 = num7 + array3[k]; if (num10 >= 0 && num10 < num && num10 / x == num8 + array5[k]) { Thing thing = innerArray[num10]; RoofDef roofDef = roofGrid.RoofAt(num10); if (roofDef != null && (roofDef.isThickRoof || thing == null || !thing.def.holdsRoof || thing.def.altitudeLayer == AltitudeLayer.DoorMoveable)) { flag = true; } if (thing == null || !thing.def.blockLight) { colorInt += this.glowGrid[num10]; num9++; } } } if (num9 > 0) { array[num2] = (colorInt / num9).ToColor32; } else { array[num2] = new Color32(0, 0, 0, 0); } if (flag && array[num2].a < 100) { array[num2].a = 100; } j++; num2++; num7++; } int num11 = maxX + 2 - this.sectRect.minX; num2 -= num11; num7 -= num11; num2 += width + 1; num7 += map.Size.x; } int num12; int num13; int num14; int num15; int num16; this.CalculateVertexIndices(this.sectRect.minX, this.sectRect.minZ, out num12, out num13, out num14, out num15, out num16); int num17 = cellIndices.CellToIndex(this.sectRect.minX, this.sectRect.minZ); for (int l = this.sectRect.minZ; l <= maxZ; l++) { int m = this.sectRect.minX; while (m <= maxX) { ColorInt colA = default(ColorInt) + array[num12]; colA += array[num12 + 1]; colA += array[num12 + width + 1]; colA += array[num12 + width + 2]; array[num16] = new Color32((byte)(colA.r / 4), (byte)(colA.g / 4), (byte)(colA.b / 4), (byte)(colA.a / 4)); if (array[num16].a < 100 && roofGrid.Roofed(num17)) { Thing thing2 = innerArray[num17]; if (thing2 == null || !thing2.def.holdsRoof) { array[num16].a = 100; } } m++; num12++; num16++; num17++; } num12++; num17 -= width; num17 += map.Size.x; } subMesh.mesh.colors32 = array; }
public override void Regenerate() { LayerSubMesh subMesh = GetSubMesh(MatBases.FogOfWar); if (subMesh.mesh.vertexCount == 0) { SectionLayerGeometryMaker_Solid.MakeBaseGeometry(section, subMesh, AltitudeLayer.FogOfWar); } subMesh.Clear(MeshParts.Colors); bool[] fogGrid = base.Map.fogGrid.fogGrid; CellRect cellRect = 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++) { if (fogGrid[cellIndices.CellToIndex(i, j)]) { for (int k = 0; k < 9; k++) { vertsCovered[k] = true; } } else { for (int l = 0; l < 9; l++) { vertsCovered[l] = false; } if (j < num && fogGrid[cellIndices.CellToIndex(i, j + 1)]) { vertsCovered[2] = true; vertsCovered[3] = true; vertsCovered[4] = true; } if (j > 0 && fogGrid[cellIndices.CellToIndex(i, j - 1)]) { vertsCovered[6] = true; vertsCovered[7] = true; vertsCovered[0] = true; } if (i < num2 && fogGrid[cellIndices.CellToIndex(i + 1, j)]) { vertsCovered[4] = true; vertsCovered[5] = true; vertsCovered[6] = true; } if (i > 0 && fogGrid[cellIndices.CellToIndex(i - 1, j)]) { vertsCovered[0] = true; vertsCovered[1] = true; vertsCovered[2] = true; } if (j > 0 && i > 0 && fogGrid[cellIndices.CellToIndex(i - 1, j - 1)]) { vertsCovered[0] = true; } if (j < num && i > 0 && fogGrid[cellIndices.CellToIndex(i - 1, j + 1)]) { vertsCovered[2] = true; } if (j < num && i < num2 && fogGrid[cellIndices.CellToIndex(i + 1, j + 1)]) { vertsCovered[4] = true; } if (j > 0 && i < num2 && fogGrid[cellIndices.CellToIndex(i + 1, j - 1)]) { vertsCovered[6] = true; } } for (int m = 0; m < 9; m++) { byte a; if (vertsCovered[m]) { a = byte.MaxValue; flag = true; } else { a = 0; } subMesh.colors.Add(new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, a)); } } } if (flag) { subMesh.disabled = false; subMesh.FinalizeMesh(MeshParts.Colors); } else { subMesh.disabled = true; } }
public override void Regenerate() { LayerSubMesh subMesh = base.GetSubMesh(MatBases.Snow); if (subMesh.mesh.vertexCount == 0) { SectionLayerGeometryMaker_Solid.MakeBaseGeometry(base.section, subMesh, AltitudeLayer.Terrain); } subMesh.Clear(MeshParts.Colors); float[] depthGridDirect_Unsafe = base.Map.snowGrid.DepthGridDirect_Unsafe; 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++) { 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] = (float)((num5 + num6 + num7 + num3) / 4.0); this.vertDepth[1] = (float)((num7 + num3) / 2.0); this.vertDepth[2] = (float)((num7 + num8 + num9 + num3) / 4.0); this.vertDepth[3] = (float)((num9 + num3) / 2.0); this.vertDepth[4] = (float)((num9 + num10 + num11 + num3) / 4.0); this.vertDepth[5] = (float)((num11 + num3) / 2.0); this.vertDepth[6] = (float)((num11 + num12 + num5 + num3) / 4.0); this.vertDepth[7] = (float)((num5 + num3) / 2.0); this.vertDepth[8] = num3; for (int k = 0; k < 9; k++) { if (this.vertDepth[k] > 0.0099999997764825821) { 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 override void Regenerate() { LayerSubMesh subMesh = GetSubMesh(MatBases.Snow); if (subMesh.mesh.vertexCount == 0) { SectionLayerGeometryMaker_Solid.MakeBaseGeometry(section, subMesh, AltitudeLayer.Terrain); } subMesh.Clear(MeshParts.Colors); float[] depthGridDirect_Unsafe = base.Map.snowGrid.DepthGridDirect_Unsafe; CellRect cellRect = 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) ? depthGridDirect_Unsafe[num4] : num3); num4 = cellIndices.CellToIndex(i - 1, j - 1); float num6 = ((j > 0 && i > 0) ? depthGridDirect_Unsafe[num4] : num3); num4 = cellIndices.CellToIndex(i - 1, j); float num7 = ((i > 0) ? depthGridDirect_Unsafe[num4] : num3); num4 = cellIndices.CellToIndex(i - 1, j + 1); float num8 = ((j < num && i > 0) ? depthGridDirect_Unsafe[num4] : num3); num4 = cellIndices.CellToIndex(i, j + 1); float num9 = ((j < num) ? depthGridDirect_Unsafe[num4] : num3); num4 = cellIndices.CellToIndex(i + 1, j + 1); float num10 = ((j < num && i < num2) ? depthGridDirect_Unsafe[num4] : num3); num4 = cellIndices.CellToIndex(i + 1, j); float num11 = ((i < num2) ? depthGridDirect_Unsafe[num4] : num3); num4 = cellIndices.CellToIndex(i + 1, j - 1); float num12 = ((j > 0 && i < num2) ? depthGridDirect_Unsafe[num4] : num3); vertDepth[0] = (num5 + num6 + num7 + num3) / 4f; vertDepth[1] = (num7 + num3) / 2f; vertDepth[2] = (num7 + num8 + num9 + num3) / 4f; vertDepth[3] = (num9 + num3) / 2f; vertDepth[4] = (num9 + num10 + num11 + num3) / 4f; vertDepth[5] = (num11 + num3) / 2f; vertDepth[6] = (num11 + num12 + num5 + num3) / 4f; vertDepth[7] = (num5 + num3) / 2f; vertDepth[8] = num3; for (int k = 0; k < 9; k++) { if (vertDepth[k] > 0.01f) { flag = true; } subMesh.colors.Add(SnowDepthColor(vertDepth[k])); } } } if (flag) { subMesh.disabled = false; subMesh.FinalizeMesh(MeshParts.Colors); } else { subMesh.disabled = true; } }
public override void Regenerate() { LayerSubMesh subMesh = base.GetSubMesh(MatBases.LightOverlay); if (subMesh.verts.Count == 0) { this.MakeBaseGeometry(subMesh); } Color32[] array = new Color32[subMesh.verts.Count]; int maxX = this.sectRect.maxX; int maxZ = this.sectRect.maxZ; bool[] array2 = new bool[4]; Thing[] innerArray = base.Map.edificeGrid.InnerArray; RoofGrid roofGrid = base.Map.roofGrid; CellIndices cellIndices = base.Map.cellIndices; for (int i = this.sectRect.minX; i <= maxX + 1; i++) { for (int j = this.sectRect.minZ; j <= maxZ + 1; j++) { int num = default(int); int num2 = default(int); int num3 = default(int); int num4 = default(int); int num5 = default(int); this.CalculateVertexIndices(i, j, out num, out num2, out num3, out num4, out num5); IntVec3 a = new IntVec3(i, 0, j); bool flag = false; for (int k = 0; k < 4; k++) { IntVec3 c = a + SectionLayer_LightingOverlay.CheckSquareOffsets[k]; if (!c.InBounds(base.Map)) { array2[k] = true; } else { Thing thing = innerArray[cellIndices.CellToIndex(c)]; RoofDef roofDef = roofGrid.RoofAt(c.x, c.z); if (roofDef != null && (roofDef.isThickRoof || thing == null || !thing.def.holdsRoof || thing.def.altitudeLayer == AltitudeLayer.DoorMoveable)) { flag = true; } if (thing != null && thing.def.blockLight) { array2[k] = true; } else { array2[k] = false; } } } ColorInt colorInt = new ColorInt(0, 0, 0, 0); int num6 = 0; if (!array2[0]) { colorInt += this.glowGrid[cellIndices.CellToIndex(i, j - 1)].AsColorInt(); num6++; } if (!array2[1]) { colorInt += this.glowGrid[cellIndices.CellToIndex(i - 1, j - 1)].AsColorInt(); num6++; } if (!array2[2]) { colorInt += this.glowGrid[cellIndices.CellToIndex(i - 1, j)].AsColorInt(); num6++; } if (!array2[3]) { colorInt += this.glowGrid[cellIndices.CellToIndex(i, j)].AsColorInt(); num6++; } if (num6 > 0) { colorInt /= (float)num6; array[num] = colorInt.ToColor32; } else { array[num] = new Color32(0, 0, 0, 0); } if (flag && array[num].a < 100) { array[num].a = 100; } } } for (int l = this.sectRect.minX; l <= maxX; l++) { for (int m = this.sectRect.minZ; m <= maxZ; m++) { int num7 = default(int); int num8 = default(int); int num9 = default(int); int num10 = default(int); int num11 = default(int); this.CalculateVertexIndices(l, m, out num7, out num8, out num9, out num10, out num11); ColorInt colA = default(ColorInt) + array[num7]; colA += array[num8]; colA += array[num9]; colA += array[num10]; array[num11] = (colA / 4f).ToColor32; Thing thing = innerArray[cellIndices.CellToIndex(l, m)]; if (roofGrid.Roofed(l, m) && (thing == null || !thing.def.holdsRoof) && array[num11].a < 100) { array[num11].a = 100; } } } subMesh.mesh.colors32 = array; }
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; }