Ejemplo n.º 1
0
    public Color GetMapColor()
    {
        Color biomeCol = Biome.GetColor();

        if (ChunkFeature != null)
        {
            if (ChunkFeature is ChunkRiverNode)
            {
                ChunkRiverNode rn = ChunkFeature as ChunkRiverNode;
                if (rn.HasBridge)
                {
                    return(Color.grey);
                }
                return(new Color(0, 0, 0.4f));
            }
            else if (ChunkFeature is ChunkRoad)
            {
                ChunkRoad r = ChunkFeature as ChunkRoad;
                if (r.Type == ChunkRoad.RoadType.Dirt)
                {
                    return(new Color(165f / 255f, 42f / 255f, 42f / 255f));
                }
                //Debug.Log("road at " + Pos);
                return(Color.grey);
            }
            else if (ChunkFeature is ChunkLake)
            {
                return(Color.blue);
            }
        }
        return(biomeCol);
    }
Ejemplo n.º 2
0
        public override void Init(LocationCreator lc)
        {
            if (MainBiomeUp == null)
            {
                MainBiomeUp = MainBiome;
            }

            Generate(lc);

            for (int i = 0; i < SmoothCount; i++)
            {
                Smooth(lc);
            }

            if (minp == null || maxp == null)
            {
                int minv = int.MaxValue;
                int maxv = int.MinValue;
                for (int x = 0; x < lc.sizeX; x++)
                {
                    for (int y = 0; y < lc.sizeZ; y++)
                    {
                        minv = Math.Min(minv, lc.Land[x, y]);
                        maxv = Math.Max(maxv, lc.Land[x, y]);
                    }
                }

                for (int x = 0; x < lc.sizeX; x++)
                {
                    for (int y = 0; y < lc.sizeZ; y++)
                    {
                        lc.Land[x, y] = (lc.Land[x, y] - minv) * (maxH - minH) / (maxv - minv) + minH;
                    }
                }
            }
            else
            {
                for (int x = 0; x < lc.sizeX; x++)
                {
                    for (int y = 0; y < lc.sizeZ; y++)
                    {
                        try
                        {
                            var minv = GetMin(lc, x, y);
                            var maxv = GetMax(lc, x, y);
                            lc.Land[x, y] = (int)((lc.Land[x, y] + sizeBlock) / (2f * sizeBlock) * (maxv - minv) + minv);
                        }
                        catch (Exception)
                        {
                            lc.Land[x, y] = -10;
                        }
                    }
                }
            }

            if (delH > 1)
            {
                for (int x = 0; x < lc.sizeX; x++)
                {
                    for (int y = 0; y < lc.sizeZ; y++)
                    {
                        lc.Land[x, y] = lc.Land[x / delH * delH, y / delH * delH] / delH * delH;
                    }
                }
            }

            for (int x = 0; x < lc.sizeX; x++)
            {
                for (int z = 0; z < lc.sizeZ; z++)
                {
                    var y = lc.Land[x, z];
                    lc.Colors[x, z]   = MainBiome.GetColor(y);
                    lc.UpColors[x, z] = MainBiomeUp.GetColor(y);
                }
            }
        }
Ejemplo n.º 3
0
    public void Execute(int index)
    {
        int localX = index % width;
        int localZ = index / width % height;

        // X and Z offsets are just the chunk's world position
        int worldX = localX + xOffset;
        int worldZ = localZ + zOffset;

        int solidGroundHeight = 42;

        // Range 0-1 for all of these
        float precipitation = GetPrecipitation(worldX, worldZ);
        float temperature   = GetTemperature(worldX, worldZ);
        float master        = GetMaster(worldX, worldZ);
        Biome biome         = DetermineBiome(precipitation, temperature, master, seaLevel);
        float terrainHeight = biome.GetHeight(worldX, worldZ) + solidGroundHeight;

        float heightSum = 0;

        if (!(biome is OceanBiome))
        {
            // Perform blending
            for (int offsetX = -blending; offsetX <= blending; offsetX++)
            {
                for (int offsetY = -blending; offsetY <= blending; offsetY++)
                {
                    float offsetPrecipitation = GetPrecipitation(worldX + offsetX, worldZ + offsetY);
                    float offsetTemperature   = GetTemperature(worldX + offsetX, worldZ + offsetY);
                    float offsetMaster        = GetMaster(worldX + offsetX, worldZ + offsetY);
                    Biome offsetBiome         = DetermineBiome(offsetPrecipitation, offsetTemperature, offsetMaster, seaLevel);
                    float offsetTerrainHeight = offsetBiome.GetHeight(worldX + offsetX, worldZ + offsetY) + solidGroundHeight;

                    heightSum += offsetTerrainHeight;
                }
            }

            int sampleCount = (blending * 2 + 1) * (blending * 2 + 1);
            terrainHeight = heightSum / sampleCount;
        }

        vertices[index] = new Vector3(localX, terrainHeight, localZ);

        Color color;

        switch (terrainDisplayMode)
        {
        case TerrainDisplayMode.Normal:
            color = biome.GetColor();
            break;

        case TerrainDisplayMode.Precipitation:
            color = GetMapColor(precipitation);
            break;

        case TerrainDisplayMode.Temperature:
            color = GetMapColor(temperature);
            break;

        case TerrainDisplayMode.MasterNoise:
            color = Color.white * master;
            break;

        default:
            color = Color.magenta;
            break;
        }
        ;

        colors[index] = color;
    }