void UpdateTileInfo(IntVector3 p) { if (m_terrain.Size.Plane.Contains(p.ToIntVector2()) == false) { return; } int h = m_terrain.GetSurfaceLevel(p.ToIntVector2()); zTextBlock.Text = String.Format("{0} ({1})", p, h); IntVector3 mp; if (p.Z == m_size.Depth) { mp = new IntVector3(p.X, p.Y, h); } else if (p.Z >= 0) { mp = p; } else { return; } terrainTextBlock.Text = m_terrain.GetTileID(mp).ToString(); terrainMatTextBlock.Text = m_terrain.GetMaterialID(mp).ToString(); //interiorTextBlock.Text = m_terrain.GetInteriorID(mp).ToString(); //interiorMatTextBlock.Text = m_terrain.GetInteriorMaterialID(mp).ToString(); }
/// <summary> /// Note: this does not change tile flags! /// </summary> public void SetTileData(IntVector3 p, TileData data) { Debug.Assert(this.IsInitialized); Debug.Assert(this.World.IsWritable); this.Version += 1; var oldData = GetTileData(p); // retain the old flags Debug.Assert(data.Flags == oldData.Flags || data.Flags == 0); data.Flags = oldData.Flags; m_tileGrid[p.Z, p.Y, p.X] = data; var p2d = p.ToIntVector2(); int oldSurfaceLevel = GetSurfaceLevel(p2d); int newSurfaceLevel = oldSurfaceLevel; if (data.IsWall && oldSurfaceLevel <= p.Z) { // Surface level has risen Debug.Assert(p.Z >= 0 && p.Z < 256); newSurfaceLevel = p.Z + 1; } else if (data.IsWall == false && oldSurfaceLevel == p.Z + 1) { // Surface level has possibly lowered if (p.Z == 0) throw new Exception(); for (int z = p.Z - 1; z >= 0; --z) { if (GetTileData(p.X, p.Y, z).IsWall) { Debug.Assert(z >= 0 && z < 256); newSurfaceLevel = z + 1; break; } } } if (newSurfaceLevel != oldSurfaceLevel) SetSurfaceLevel(p2d, (byte)newSurfaceLevel); MapChanged(p, data); if (this.TerrainOrInteriorChanged != null) this.TerrainOrInteriorChanged(p, oldData, data); if (data.WaterLevel > 0) m_waterHandler.AddWater(p); else m_waterHandler.RemoveWater(p); if (newSurfaceLevel > oldSurfaceLevel) { for (int z = oldSurfaceLevel; z < newSurfaceLevel; ++z) SetTileFlags(new IntVector3(p2d, z), TileFlags.Subterranean, true); } else if (newSurfaceLevel < oldSurfaceLevel) { for (int z = oldSurfaceLevel - 1; z >= newSurfaceLevel; --z) SetTileFlags(new IntVector3(p2d, z), TileFlags.Subterranean, false); } // ZZZ notify up if (Contains(p.Up)) { // ZZZ if this tile was the only support for the tile above, it should crash down var pu = p.Up; // if support is removed, clear greenery above if (oldData.IsSupporting && data.IsSupporting == false) { if (m_tileGrid[pu.Z, pu.Y, pu.X].IsGreen) { m_tileGrid[pu.Z, pu.Y, pu.X].ID = TileID.Empty; m_tileGrid[pu.Z, pu.Y, pu.X].MaterialID = MaterialID.Undefined; } } if (data.IsSupporting) m_tileGrid[pu.Z, pu.Y, pu.X].Flags |= TileFlags.HasSupport; else m_tileGrid[pu.Z, pu.Y, pu.X].Flags &= ~TileFlags.HasSupport; if (data.IsWall) m_tileGrid[pu.Z, pu.Y, pu.X].Flags |= TileFlags.HasWallBelow; else m_tileGrid[pu.Z, pu.Y, pu.X].Flags &= ~TileFlags.HasWallBelow; MapChanged(pu, GetTileData(pu)); //if (this.TerrainOrInteriorChanged != null) // this.TerrainOrInteriorChanged(p, oldData, data); } }
void UpdateTileInfo(IntVector3 p) { if (m_terrain.Size.Plane.Contains(p.ToIntVector2()) == false) return; int h = m_terrain.GetSurfaceLevel(p.ToIntVector2()); zTextBlock.Text = String.Format("{0} ({1})", p, h); IntVector3 mp; if (p.Z == m_size.Depth) mp = new IntVector3(p.X, p.Y, h); else if (p.Z >= 0) mp = p; else return; terrainTextBlock.Text = m_terrain.GetTileID(mp).ToString(); terrainMatTextBlock.Text = m_terrain.GetMaterialID(mp).ToString(); //interiorTextBlock.Text = m_terrain.GetInteriorID(mp).ToString(); //interiorMatTextBlock.Text = m_terrain.GetInteriorMaterialID(mp).ToString(); }
/// <summary> /// Note: this does not change tile flags! /// </summary> public void SetTileData(IntVector3 p, TileData data) { Debug.Assert(this.IsInitialized); Debug.Assert(this.World.IsWritable); this.Version += 1; var oldData = GetTileData(p); // retain the old flags Debug.Assert(data.Flags == oldData.Flags || data.Flags == 0); data.Flags = oldData.Flags; m_tileGrid[p.Z, p.Y, p.X] = data; var p2d = p.ToIntVector2(); int oldSurfaceLevel = GetSurfaceLevel(p2d); int newSurfaceLevel = oldSurfaceLevel; if (data.IsWall && oldSurfaceLevel <= p.Z) { // Surface level has risen Debug.Assert(p.Z >= 0 && p.Z < 256); newSurfaceLevel = p.Z + 1; } else if (data.IsWall == false && oldSurfaceLevel == p.Z + 1) { // Surface level has possibly lowered if (p.Z == 0) { throw new Exception(); } for (int z = p.Z - 1; z >= 0; --z) { if (GetTileData(p.X, p.Y, z).IsWall) { Debug.Assert(z >= 0 && z < 256); newSurfaceLevel = z + 1; break; } } } if (newSurfaceLevel != oldSurfaceLevel) { SetSurfaceLevel(p2d, (byte)newSurfaceLevel); } MapChanged(p, data); if (this.TerrainOrInteriorChanged != null) { this.TerrainOrInteriorChanged(p, oldData, data); } if (data.WaterLevel > 0) { m_waterHandler.AddWater(p); } else { m_waterHandler.RemoveWater(p); } if (newSurfaceLevel > oldSurfaceLevel) { for (int z = oldSurfaceLevel; z < newSurfaceLevel; ++z) { SetTileFlags(new IntVector3(p2d, z), TileFlags.Subterranean, true); } } else if (newSurfaceLevel < oldSurfaceLevel) { for (int z = oldSurfaceLevel - 1; z >= newSurfaceLevel; --z) { SetTileFlags(new IntVector3(p2d, z), TileFlags.Subterranean, false); } } // ZZZ notify up if (Contains(p.Up)) { // ZZZ if this tile was the only support for the tile above, it should crash down var pu = p.Up; // if support is removed, clear greenery above if (oldData.IsSupporting && data.IsSupporting == false) { if (m_tileGrid[pu.Z, pu.Y, pu.X].IsGreen) { m_tileGrid[pu.Z, pu.Y, pu.X].ID = TileID.Empty; m_tileGrid[pu.Z, pu.Y, pu.X].MaterialID = MaterialID.Undefined; } } if (data.IsSupporting) { m_tileGrid[pu.Z, pu.Y, pu.X].Flags |= TileFlags.HasSupport; } else { m_tileGrid[pu.Z, pu.Y, pu.X].Flags &= ~TileFlags.HasSupport; } if (data.IsWall) { m_tileGrid[pu.Z, pu.Y, pu.X].Flags |= TileFlags.HasWallBelow; } else { m_tileGrid[pu.Z, pu.Y, pu.X].Flags &= ~TileFlags.HasWallBelow; } MapChanged(pu, GetTileData(pu)); //if (this.TerrainOrInteriorChanged != null) // this.TerrainOrInteriorChanged(p, oldData, data); } }