Dwarrowdelf.TerrainGen.TerrainData.SetTileData C# (CSharp) Method

SetTileData() public method

public SetTileData ( IntVector3 p, TileData data ) : void
p IntVector3
data TileData
return void
        public void SetTileData(IntVector3 p, TileData data)
        {
            int oldLevel = GetSurfaceLevel(p.X, p.Y);

            if (data.IsWall && oldLevel <= p.Z)
            {
                // Surface level has risen
                Debug.Assert(p.Z >= 0 && p.Z < 256);
                SetSurfaceLevel(p.X, p.Y, p.Z + 1);
            }
            else if (data.IsWall == false && oldLevel == 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);
                        SetSurfaceLevel(p.X, p.Y, z + 1);
                        break;
                    }
                }
            }

            SetTileDataNoHeight(p, data);
        }

Usage Example

Example #1
0
        public void AdjustRiver()
        {
            int minZ = m_riverPath.Min(p => m_terrain.GetSurfaceLevel(p));

            var pos = DirectionSet.Cardinal | DirectionSet.Exact;

            var coreLocs = new HashSet <IntVector2>(m_riverPath.SelectMany(p => pos.ToSurroundingPoints(p)));

            foreach (var pp in coreLocs)
            {
                if (m_terrain.Size.Plane.Contains(pp) == false)
                {
                    continue;
                }

                for (int z = m_terrain.Depth - 1; z >= minZ - 1; --z)
                {
                    var p = new IntVector3(pp.X, pp.Y, z);

                    var td = TileData.EmptyTileData;

                    if (z == minZ - 1)
                    {
                        td.WaterLevel = TileData.MaxWaterLevel;
                    }

                    m_terrain.SetTileData(p, td);
                }
            }
        }
All Usage Examples Of Dwarrowdelf.TerrainGen.TerrainData::SetTileData