public void BuildTerrainChunks()
            {
                m_terrainChunks = new TerrainChunkObject[WORLD_CHUNK_SIZE, WORLD_CHUNK_SIZE];

                m_globalheightMap = new TerrainHeightMap(WORLD_CHUNK_SIZE * TerrainChunkObject.TERRAIN_CHUNK_TILE_SIZE);
                m_chunkHeigtmaps = new TerrainHeightMap[WORLD_CHUNK_SIZE, WORLD_CHUNK_SIZE];

                for (int x = 0; x < WORLD_CHUNK_SIZE; x++)
                {
                    for (int y = 0; y < WORLD_CHUNK_SIZE; y++)
                    {
                        GameObject terrainObject = new GameObject("Terrain - " + x + ", " + y);

                        MeshBuilder.GeneratePerlinMap(x, y, m_globalheightMap,
                            new float[] { 1.25f, 3f, 10f, 25, 0.5f }, //scale
                            new float[] { 1f, 4.15f, 0f, 0, 0f}, //additions
                            new float[] { 28, 5f, 2f, 0.5f, 55f }, //strength
                            new decimal[] { 0.55m, 1m, 0.25m, 0.2m, 55m }); //limits)

                        m_chunkHeigtmaps[x, y] = new TerrainHeightMap(TerrainChunkObject.TERRAIN_CHUNK_TILE_SIZE);
                        m_terrainChunks[x, y] = terrainObject.AddComponent<TerrainChunkObject>();
                    }
                }

                for (int x = 0; x < WORLD_CHUNK_SIZE; x++)
                {
                    for (int y = 0; y < WORLD_CHUNK_SIZE; y++)
                    {
                        m_chunkHeigtmaps[x, y].SetHeightMap(m_globalheightMap.GetPortion(x * TerrainChunkObject.TERRAIN_CHUNK_TILE_SIZE,
                            y * TerrainChunkObject.TERRAIN_CHUNK_TILE_SIZE, TerrainChunkObject.TERRAIN_CHUNK_TILE_SIZE), m_globalheightMap.highestFloat, m_globalheightMap.lowestFloat, m_globalheightMap.totalStrength);

                        m_terrainChunks[x, y].Build(x, y, m_chunkHeigtmaps[x, y]);
                    }
                }
            }
            public TerrainChunkObject Build(int x, int y, TerrainHeightMap heightMap)
            {
                worldX = x;
                worldY = y;

                transform.position = new Vector3(x * (TERRAIN_CHUNK_TILE_SIZE - 1), 0, y * (TERRAIN_CHUNK_TILE_SIZE - 1));

                MeshFilter meshFilter = GetComponent<MeshFilter>();
                if (meshFilter.sharedMesh == null)
                    meshFilter.sharedMesh = new Mesh();
                Mesh mesh = meshFilter.sharedMesh;

                mesh.name = "Terrain Chunk";
                mesh.Clear();

                m_heightMap = heightMap;

                mesh.vertices = MeshBuilder.BuildVerticesFromHeightMap(m_heightMap);
                mesh.triangles = MeshBuilder.triangles;
                mesh.uv = MeshBuilder.uv;

                mesh.RecalculateNormals();

                Material mat = Resources.Load("Materials/Terrain") as Material;
                GetComponent<Renderer>().material = mat;
                GetComponent<Renderer>().material.mainTexture = MeshBuilder.GenerateTextureFromHeightMap(m_heightMap);
                GetComponent<Renderer>().material.SetFloat("_SPECCGLOSSMAP", 0.15f);
                GetComponent<MeshCollider>().sharedMesh = mesh;

                return this;
            }
    public void MarkRiverside()
    {
        TerrainHeightMap   heightmap = TerrainMeta.HeightMap;
        TerrainTopologyMap topomap   = TerrainMeta.TopologyMap;

        int[] map = topomap.dst;
        int   res = topomap.res;

        ImageProcessing.Dilate2D(map, res, res, 49152, 6, delegate(int x, int y)
        {
            if (((uint)map[x * res + y] & 0x31u) != 0)
            {
                map[x * res + y] |= 32768;
            }
            float normX = topomap.Coordinate(x);
            float normZ = topomap.Coordinate(y);
            if (heightmap.GetSlope(normX, normZ) > 40f)
            {
                map[x * res + y] |= 2;
            }
        });
    }
Exemple #4
0
    private bool TestPlacingCloseToRoad(ref Placement placement, Target target)
    {
        TerrainHeightMap   heightMap   = TerrainMeta.HeightMap;
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;

        if (heightMap == null)
        {
            return(true);
        }
        if (topologyMap == null)
        {
            return(true);
        }
        OBB   oBB = new OBB(placement.position, Vector3.one, placement.rotation, bounds);
        float num = Mathf.Abs(heightMap.GetHeight(oBB.position) - oBB.position.y);

        if (num > 9f)
        {
            return(true);
        }
        float   radius    = Mathf.Lerp(3f, 0f, num / 9f);
        Vector3 position  = oBB.position;
        Vector3 point     = oBB.GetPoint(-1f, 0f, -1f);
        Vector3 point2    = oBB.GetPoint(-1f, 0f, 1f);
        Vector3 point3    = oBB.GetPoint(1f, 0f, -1f);
        Vector3 point4    = oBB.GetPoint(1f, 0f, 1f);
        int     topology  = topologyMap.GetTopology(position, radius);
        int     topology2 = topologyMap.GetTopology(point, radius);
        int     topology3 = topologyMap.GetTopology(point2, radius);
        int     topology4 = topologyMap.GetTopology(point3, radius);
        int     topology5 = topologyMap.GetTopology(point4, radius);

        if (((topology | topology2 | topology3 | topology4 | topology5) & 0x800) == 0)
        {
            return(true);
        }
        return(false);
    }
Exemple #5
0
    public override void Process(uint seed)
    {
        List <PathList>     pathLists   = new List <PathList>();
        TerrainHeightMap    heightMap   = TerrainMeta.HeightMap;
        TerrainTopologyMap  topologyMap = TerrainMeta.TopologyMap;
        List <MonumentInfo> monuments   = TerrainMeta.Path.Monuments;

        if (monuments.Count == 0)
        {
            return;
        }
        int num = Mathf.NextPowerOfTwo((int)((float)((float)World.Size) / 10f));

        int[,] numArray = new int[num, num];
        float single = 5f;

        for (int i = 0; i < num; i++)
        {
            float single1 = ((float)i + 0.5f) / (float)num;
            for (int j = 0; j < num; j++)
            {
                float single2  = ((float)j + 0.5f) / (float)num;
                int   num1     = SeedRandom.Range(ref seed, 100, 500);
                float slope    = heightMap.GetSlope(single2, single1);
                int   topology = topologyMap.GetTopology(single2, single1, single);
                int   num2     = 2295686;
                int   num3     = 49152;
                if (slope > 20f || (topology & num2) != 0)
                {
                    numArray[i, j] = 2147483647;
                }
                else if ((topology & num3) == 0)
                {
                    numArray[i, j] = 1 + (int)(slope * slope * 10f) + num1;
                }
                else
                {
                    numArray[i, j] = 2500;
                }
            }
        }
        PathFinder pathFinder = new PathFinder(numArray, true);
        List <GenerateRoadLayout.PathSegment> pathSegments = new List <GenerateRoadLayout.PathSegment>();
        List <GenerateRoadLayout.PathNode>    pathNodes    = new List <GenerateRoadLayout.PathNode>();
        List <GenerateRoadLayout.PathNode>    pathNodes1   = new List <GenerateRoadLayout.PathNode>();
        List <PathFinder.Point> points  = new List <PathFinder.Point>();
        List <PathFinder.Point> points1 = new List <PathFinder.Point>();
        List <PathFinder.Point> points2 = new List <PathFinder.Point>();

        foreach (MonumentInfo monument in monuments)
        {
            bool count = pathNodes.Count == 0;
            foreach (TerrainPathConnect target in monument.GetTargets(InfrastructureType.Road))
            {
                PathFinder.Node node = pathFinder.FindClosestWalkable(target.GetPoint(num), 100000);
                if (node == null)
                {
                    continue;
                }
                GenerateRoadLayout.PathNode pathNode = new GenerateRoadLayout.PathNode()
                {
                    monument = monument,
                    target   = target,
                    node     = node
                };
                if (!count)
                {
                    pathNodes1.Add(pathNode);
                }
                else
                {
                    pathNodes.Add(pathNode);
                }
            }
        }
        while (pathNodes1.Count != 0)
        {
            points1.Clear();
            points2.Clear();
            points1.AddRange(
                from x in pathNodes
                select x.node.point);
            points1.AddRange(points);
            points2.AddRange(
                from x in pathNodes1
                select x.node.point);
            PathFinder.Node node1 = pathFinder.FindPathUndirected(points1, points2, 100000);
            if (node1 != null)
            {
                GenerateRoadLayout.PathSegment pathSegment = new GenerateRoadLayout.PathSegment();
                for (PathFinder.Node k = node1; k != null; k = k.next)
                {
                    if (k == node1)
                    {
                        pathSegment.start = k;
                    }
                    if (k.next == null)
                    {
                        pathSegment.end = k;
                    }
                }
                pathSegments.Add(pathSegment);
                GenerateRoadLayout.PathNode pathNode1 = pathNodes1.Find((GenerateRoadLayout.PathNode x) => {
                    if (x.node.point == pathSegment.start.point)
                    {
                        return(true);
                    }
                    return(x.node.point == pathSegment.end.point);
                });
                pathNodes.AddRange(
                    from x in pathNodes1
                    where x.monument == pathNode1.monument
                    select x);
                pathNodes1.RemoveAll((GenerateRoadLayout.PathNode x) => x.monument == pathNode1.monument);
                int num4 = 1;
                for (PathFinder.Node l = node1; l != null; l = l.next)
                {
                    if (num4 % 8 == 0)
                    {
                        points.Add(l.point);
                    }
                    num4++;
                }
            }
            else
            {
                GenerateRoadLayout.PathNode item = pathNodes1[0];
                pathNodes.AddRange(
                    from x in pathNodes1
                    where x.monument == item.monument
                    select x);
                pathNodes1.RemoveAll((GenerateRoadLayout.PathNode x) => x.monument == item.monument);
            }
        }
        foreach (GenerateRoadLayout.PathNode pathNode2 in pathNodes)
        {
            GenerateRoadLayout.PathSegment pathSegment1 = pathSegments.Find((GenerateRoadLayout.PathSegment x) => {
                if (x.start.point == pathNode2.node.point)
                {
                    return(true);
                }
                return(x.end.point == pathNode2.node.point);
            });
            if (pathSegment1 == null)
            {
                continue;
            }
            if (pathSegment1.start.point != pathNode2.node.point)
            {
                if (pathSegment1.end.point != pathNode2.node.point)
                {
                    continue;
                }
                pathSegment1.end.next = pathNode2.node;
                pathSegment1.end      = pathFinder.FindEnd(pathNode2.node);
                pathSegment1.target   = pathNode2.target;
            }
            else
            {
                PathFinder.Node node2 = pathNode2.node;
                PathFinder.Node node3 = pathFinder.Reverse(pathNode2.node);
                node2.next          = pathSegment1.start;
                pathSegment1.start  = node3;
                pathSegment1.origin = pathNode2.target;
            }
        }
        List <Vector3> vector3s = new List <Vector3>();

        foreach (GenerateRoadLayout.PathSegment pathSegment2 in pathSegments)
        {
            bool flag  = false;
            bool flag1 = false;
            for (PathFinder.Node m = pathSegment2.start; m != null; m = m.next)
            {
                float single3 = ((float)m.point.x + 0.5f) / (float)num;
                float single4 = ((float)m.point.y + 0.5f) / (float)num;
                if (pathSegment2.start == m && pathSegment2.origin != null)
                {
                    flag    = true;
                    single3 = TerrainMeta.NormalizeX(pathSegment2.origin.transform.position.x);
                    single4 = TerrainMeta.NormalizeZ(pathSegment2.origin.transform.position.z);
                }
                else if (pathSegment2.end == m && pathSegment2.target != null)
                {
                    flag1   = true;
                    single3 = TerrainMeta.NormalizeX(pathSegment2.target.transform.position.x);
                    single4 = TerrainMeta.NormalizeZ(pathSegment2.target.transform.position.z);
                }
                float single5 = TerrainMeta.DenormalizeX(single3);
                float single6 = TerrainMeta.DenormalizeZ(single4);
                float single7 = Mathf.Max(heightMap.GetHeight(single3, single4), 1f);
                vector3s.Add(new Vector3(single5, single7, single6));
            }
            if (vector3s.Count == 0)
            {
                continue;
            }
            if (vector3s.Count >= 2)
            {
                PathList pathList = new PathList(string.Concat("Road ", pathLists.Count), vector3s.ToArray())
                {
                    Width         = 10f,
                    InnerPadding  = 1f,
                    OuterPadding  = 1f,
                    InnerFade     = 1f,
                    OuterFade     = 8f,
                    RandomScale   = 0.75f,
                    MeshOffset    = 0f,
                    TerrainOffset = -0.5f,
                    Topology      = 2048,
                    Splat         = 128,
                    Start         = flag,
                    End           = flag1
                };
                pathLists.Add(pathList);
            }
            vector3s.Clear();
        }
        foreach (PathList pathList1 in pathLists)
        {
            pathList1.Path.Smoothen(2);
        }
        TerrainMeta.Path.Roads.AddRange(pathLists);
    }
    public override void Process(uint seed)
    {
        if (World.Networked)
        {
            TerrainMeta.Path.Rivers.Clear();
            TerrainMeta.Path.Rivers.AddRange(World.GetPaths("River"));
            return;
        }
        List <PathList>    list        = new List <PathList>();
        TerrainHeightMap   heightMap   = TerrainMeta.HeightMap;
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        List <Vector3>     list2       = new List <Vector3>();

        for (float num = TerrainMeta.Position.z; num < TerrainMeta.Position.z + TerrainMeta.Size.z; num += 50f)
        {
            for (float num2 = TerrainMeta.Position.x; num2 < TerrainMeta.Position.x + TerrainMeta.Size.x; num2 += 50f)
            {
                Vector3 vector = new Vector3(num2, 0f, num);
                float   num3   = (vector.y = heightMap.GetHeight(vector));
                if (vector.y <= 5f)
                {
                    continue;
                }
                Vector3 normal = heightMap.GetNormal(vector);
                if (normal.y <= 0.01f)
                {
                    continue;
                }
                Vector2 normalized = new Vector2(normal.x, normal.z).normalized;
                list2.Add(vector);
                float radius = 18f;
                int   num4   = 18;
                for (int i = 0; i < 10000; i++)
                {
                    vector.x += normalized.x;
                    vector.z += normalized.y;
                    if (heightMap.GetSlope(vector) > 30f)
                    {
                        break;
                    }
                    float height = heightMap.GetHeight(vector);
                    if (height > num3 + 10f)
                    {
                        break;
                    }
                    float num5 = Mathf.Min(height, num3);
                    vector.y = Mathf.Lerp(vector.y, num5, 0.15f);
                    int topology  = topologyMap.GetTopology(vector, radius);
                    int topology2 = topologyMap.GetTopology(vector);
                    int num6      = 2694148;
                    int num7      = 128;
                    if ((topology & num6) != 0)
                    {
                        list2.Add(vector);
                        break;
                    }
                    if ((topology2 & num7) != 0 && --num4 <= 0)
                    {
                        list2.Add(vector);
                        if (list2.Count >= 25)
                        {
                            int      num8     = TerrainMeta.Path.Rivers.Count + list.Count;
                            PathList pathList = new PathList("River " + num8, list2.ToArray());
                            pathList.Width         = 36f;
                            pathList.InnerPadding  = 1f;
                            pathList.OuterPadding  = 1f;
                            pathList.InnerFade     = 10f;
                            pathList.OuterFade     = 20f;
                            pathList.RandomScale   = 0.75f;
                            pathList.MeshOffset    = -0.5f;
                            pathList.TerrainOffset = -1.5f;
                            pathList.Topology      = 16384;
                            pathList.Splat         = 64;
                            pathList.Start         = true;
                            pathList.End           = true;
                            list.Add(pathList);
                        }
                        break;
                    }
                    if (i % 12 == 0)
                    {
                        list2.Add(vector);
                    }
                    normal     = heightMap.GetNormal(vector);
                    normalized = new Vector2(normalized.x + 0.15f * normal.x, normalized.y + 0.15f * normal.z).normalized;
                    num3       = num5;
                }
                list2.Clear();
            }
        }
        list.Sort((PathList a, PathList b) => b.Path.Points.Length.CompareTo(a.Path.Points.Length));
        int num9  = Mathf.RoundToInt(10f * TerrainMeta.Size.x * TerrainMeta.Size.z * 1E-06f);
        int num10 = Mathf.NextPowerOfTwo((int)((float)World.Size / 36f));

        bool[,] array = new bool[num10, num10];
        for (int j = 0; j < list.Count; j++)
        {
            if (j >= num9)
            {
                list.RemoveUnordered(j--);
                continue;
            }
            PathList pathList2 = list[j];
            bool     flag      = false;
            for (int k = 0; k < j; k++)
            {
                if (Vector3.Distance(list[k].Path.GetStartPoint(), pathList2.Path.GetStartPoint()) < 100f)
                {
                    list.RemoveUnordered(j--);
                    flag = true;
                    break;
                }
            }
            if (flag)
            {
                continue;
            }
            int num11 = -1;
            int num12 = -1;
            for (int l = 0; l < pathList2.Path.Points.Length; l++)
            {
                Vector3 vector2 = pathList2.Path.Points[l];
                int     num13   = Mathf.Clamp((int)(TerrainMeta.NormalizeX(vector2.x) * (float)num10), 0, num10 - 1);
                int     num14   = Mathf.Clamp((int)(TerrainMeta.NormalizeZ(vector2.z) * (float)num10), 0, num10 - 1);
                if (num11 == num13 && num12 == num14)
                {
                    continue;
                }
                if (array[num14, num13])
                {
                    list.RemoveUnordered(j--);
                    flag = true;
                    break;
                }
                if (num11 != num13 && num12 != num14)
                {
                    if (num11 != -1)
                    {
                        array[num14, num11] = true;
                    }
                    if (num12 != -1)
                    {
                        array[num12, num13] = true;
                    }
                    num11 = num13;
                    num12 = num14;
                    array[num14, num13] = true;
                }
                else
                {
                    num11 = num13;
                    num12 = num14;
                    array[num14, num13] = true;
                }
            }
        }
        for (int m = 0; m < list.Count; m++)
        {
            list[m].Name = "River " + (TerrainMeta.Path.Rivers.Count + m);
        }
        foreach (PathList item in list)
        {
            item.Path.Smoothen(4);
            item.Path.RecalculateTangents();
        }
        TerrainMeta.Path.Rivers.AddRange(list);
    }
Exemple #7
0
    public override void Process(uint seed)
    {
        List <PathList>     pathLists   = new List <PathList>();
        TerrainHeightMap    heightMap   = TerrainMeta.HeightMap;
        TerrainTopologyMap  topologyMap = TerrainMeta.TopologyMap;
        List <MonumentInfo> monuments   = TerrainMeta.Path.Monuments;

        if (monuments.Count == 0)
        {
            return;
        }
        int num = Mathf.NextPowerOfTwo((int)((float)((float)World.Size) / 10f));

        int[,] numArray = new int[num, num];
        float single = 5f;

        for (int i = 0; i < num; i++)
        {
            float single1 = ((float)i + 0.5f) / (float)num;
            for (int j = 0; j < num; j++)
            {
                float single2  = ((float)j + 0.5f) / (float)num;
                float slope    = heightMap.GetSlope(single2, single1);
                int   topology = topologyMap.GetTopology(single2, single1, single);
                int   num1     = 2295174;
                int   num2     = 55296;
                int   num3     = 512;
                if ((topology & num1) != 0)
                {
                    numArray[i, j] = 2147483647;
                }
                else if ((topology & num2) != 0)
                {
                    numArray[i, j] = 2500;
                }
                else if ((topology & num3) == 0)
                {
                    numArray[i, j] = 1 + (int)(slope * slope * 10f);
                }
                else
                {
                    numArray[i, j] = 1000;
                }
            }
        }
        PathFinder pathFinder = new PathFinder(numArray, true);
        List <GeneratePowerlineLayout.PathSegment> pathSegments = new List <GeneratePowerlineLayout.PathSegment>();
        List <GeneratePowerlineLayout.PathNode>    pathNodes    = new List <GeneratePowerlineLayout.PathNode>();
        List <GeneratePowerlineLayout.PathNode>    pathNodes1   = new List <GeneratePowerlineLayout.PathNode>();
        List <PathFinder.Point> points  = new List <PathFinder.Point>();
        List <PathFinder.Point> points1 = new List <PathFinder.Point>();
        List <PathFinder.Point> points2 = new List <PathFinder.Point>();

        foreach (MonumentInfo monument in monuments)
        {
            bool count = pathNodes.Count == 0;
            foreach (TerrainPathConnect target in monument.GetTargets(InfrastructureType.Power))
            {
                PathFinder.Point point = target.GetPoint(num);
                PathFinder.Node  node  = pathFinder.FindClosestWalkable(point, 100000);
                if (node == null)
                {
                    continue;
                }
                GeneratePowerlineLayout.PathNode pathNode = new GeneratePowerlineLayout.PathNode()
                {
                    monument = monument,
                    node     = node
                };
                if (!count)
                {
                    pathNodes1.Add(pathNode);
                }
                else
                {
                    pathNodes.Add(pathNode);
                }
            }
        }
        while (pathNodes1.Count != 0)
        {
            points1.Clear();
            points2.Clear();
            points1.AddRange(
                from x in pathNodes
                select x.node.point);
            points1.AddRange(points);
            points2.AddRange(
                from x in pathNodes1
                select x.node.point);
            PathFinder.Node node1 = pathFinder.FindPathUndirected(points1, points2, 100000);
            if (node1 != null)
            {
                GeneratePowerlineLayout.PathSegment pathSegment = new GeneratePowerlineLayout.PathSegment();
                for (PathFinder.Node k = node1; k != null; k = k.next)
                {
                    if (k == node1)
                    {
                        pathSegment.start = k;
                    }
                    if (k.next == null)
                    {
                        pathSegment.end = k;
                    }
                }
                pathSegments.Add(pathSegment);
                GeneratePowerlineLayout.PathNode pathNode1 = pathNodes1.Find((GeneratePowerlineLayout.PathNode x) => {
                    if (x.node.point == pathSegment.start.point)
                    {
                        return(true);
                    }
                    return(x.node.point == pathSegment.end.point);
                });
                pathNodes.AddRange(
                    from x in pathNodes1
                    where x.monument == pathNode1.monument
                    select x);
                pathNodes1.RemoveAll((GeneratePowerlineLayout.PathNode x) => x.monument == pathNode1.monument);
                int num4 = 1;
                for (PathFinder.Node l = node1; l != null; l = l.next)
                {
                    if (num4 % 8 == 0)
                    {
                        points.Add(l.point);
                    }
                    num4++;
                }
            }
            else
            {
                GeneratePowerlineLayout.PathNode item = pathNodes1[0];
                pathNodes.AddRange(
                    from x in pathNodes1
                    where x.monument == item.monument
                    select x);
                pathNodes1.RemoveAll((GeneratePowerlineLayout.PathNode x) => x.monument == item.monument);
            }
        }
        List <Vector3> vector3s = new List <Vector3>();

        foreach (GeneratePowerlineLayout.PathSegment pathSegment1 in pathSegments)
        {
            for (PathFinder.Node m = pathSegment1.start; m != null; m = m.next)
            {
                float single3  = ((float)m.point.x + 0.5f) / (float)num;
                float single4  = ((float)m.point.y + 0.5f) / (float)num;
                float height01 = heightMap.GetHeight01(single3, single4);
                vector3s.Add(TerrainMeta.Denormalize(new Vector3(single3, height01, single4)));
            }
            if (vector3s.Count == 0)
            {
                continue;
            }
            if (vector3s.Count >= 8)
            {
                PathList pathList = new PathList(string.Concat("Powerline ", pathLists.Count), vector3s.ToArray())
                {
                    Start = true,
                    End   = true
                };
                pathLists.Add(pathList);
            }
            vector3s.Clear();
        }
        TerrainMeta.Path.Powerlines.AddRange(pathLists);
    }
Exemple #8
0
    public override void Process(uint seed)
    {
        List <PathList>    pathLists   = new List <PathList>();
        TerrainHeightMap   heightMap   = TerrainMeta.HeightMap;
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        List <Vector3>     vector3s    = new List <Vector3>();

        for (float i = TerrainMeta.Position.z; i < TerrainMeta.Position.z + TerrainMeta.Size.z; i += 50f)
        {
            for (float j = TerrainMeta.Position.x; j < TerrainMeta.Position.x + TerrainMeta.Size.x; j += 50f)
            {
                Vector3 vector3 = new Vector3(j, 0f, i);
                float   height  = heightMap.GetHeight(vector3);
                float   single  = height;
                vector3.y = height;
                float single1 = single;
                if (vector3.y > 5f)
                {
                    Vector3 normal = heightMap.GetNormal(vector3);
                    if (normal.y > 0.01f)
                    {
                        Vector2 vector2  = new Vector2(normal.x, normal.z);
                        Vector2 vector21 = vector2.normalized;
                        vector3s.Add(vector3);
                        float single2 = 12f;
                        int   num     = 12;
                        for (int k = 0; k < 10000; k++)
                        {
                            vector3.x += vector21.x;
                            vector3.z += vector21.y;
                            if (heightMap.GetSlope(vector3) > 30f)
                            {
                                break;
                            }
                            float height1 = heightMap.GetHeight(vector3);
                            if (height1 > single1 + 10f)
                            {
                                break;
                            }
                            vector3.y = Mathf.Min(height1, single1);
                            vector3s.Add(vector3);
                            int topology  = topologyMap.GetTopology(vector3, single2);
                            int topology1 = topologyMap.GetTopology(vector3);
                            int num1      = 2694148;
                            int num2      = 128;
                            if ((topology & num1) != 0)
                            {
                                break;
                            }
                            if ((topology1 & num2) != 0)
                            {
                                int num3 = num - 1;
                                num = num3;
                                if (num3 <= 0)
                                {
                                    if (vector3s.Count < 300)
                                    {
                                        break;
                                    }
                                    PathList pathList = new PathList(string.Concat("River ", pathLists.Count), vector3s.ToArray())
                                    {
                                        Width         = 24f,
                                        InnerPadding  = 0.5f,
                                        OuterPadding  = 0.5f,
                                        InnerFade     = 8f,
                                        OuterFade     = 16f,
                                        RandomScale   = 0.75f,
                                        MeshOffset    = -0.4f,
                                        TerrainOffset = -2f,
                                        Topology      = 16384,
                                        Splat         = 64,
                                        Start         = true,
                                        End           = true
                                    };
                                    pathLists.Add(pathList);
                                    break;
                                }
                            }
                            normal   = heightMap.GetNormal(vector3);
                            vector2  = new Vector2(vector21.x + 0.15f * normal.x, vector21.y + 0.15f * normal.z);
                            vector21 = vector2.normalized;
                            single1  = vector3.y;
                        }
                        vector3s.Clear();
                    }
                }
            }
        }
        pathLists.Sort((PathList a, PathList b) => ((int)b.Path.Points.Length).CompareTo((int)a.Path.Points.Length));
        int num4 = Mathf.RoundToInt(10f * TerrainMeta.Size.x * TerrainMeta.Size.z * 1E-06f);
        int num5 = Mathf.NextPowerOfTwo((int)((float)((float)World.Size) / 24f));

        bool[,] flagArray = new bool[num5, num5];
        for (int l = 0; l < pathLists.Count; l++)
        {
            if (l < num4)
            {
                PathList item = pathLists[l];
                for (int m = 0; m < l; m++)
                {
                    if (Vector3.Distance(pathLists[m].Path.GetStartPoint(), item.Path.GetStartPoint()) < 100f)
                    {
                        int num6 = l;
                        l = num6 - 1;
                        pathLists.RemoveUnordered <PathList>(num6);
                    }
                }
                int num7 = -1;
                int num8 = -1;
                for (int n = 0; n < (int)item.Path.Points.Length; n++)
                {
                    Vector3 points = item.Path.Points[n];
                    int     num9   = Mathf.Clamp((int)(TerrainMeta.NormalizeX(points.x) * (float)num5), 0, num5 - 1);
                    int     num10  = Mathf.Clamp((int)(TerrainMeta.NormalizeZ(points.z) * (float)num5), 0, num5 - 1);
                    if (num7 != num9 || num8 != num10)
                    {
                        if (!flagArray[num10, num9])
                        {
                            num7 = num9;
                            num8 = num10;
                            flagArray[num10, num9] = true;
                        }
                        else
                        {
                            int num11 = l;
                            l = num11 - 1;
                            pathLists.RemoveUnordered <PathList>(num11);
                            break;
                        }
                    }
                }
            }
            else
            {
                int num12 = l;
                l = num12 - 1;
                pathLists.RemoveUnordered <PathList>(num12);
            }
        }
        TerrainMeta.Path.Rivers.AddRange(pathLists);
    }
            public static float[,] GeneratePerlinMap(int worldX, int worldY, TerrainHeightMap heightMap, float[] scales, float[] additions, float[] strengths, decimal[] limits)
            {
                int size = heightMap.size;
                float[,] noise = new float[size, size];

                float top = 0;
                float bottom = Mathf.Infinity;
                float seed = 1500;
                float totalStrength = 0f;

                for (int i = 0; i < scales.Length; i++)
                {

                    float y = 0.0F;
                    while (y < size)
                    {
                        float x = 0.0F;
                        while (x < size)
                        {
                            float xCoord = (seed + x / size * scales[i]) * worldX;
                            float yCoord = (seed + y / size * scales[i]) * worldY;
                            float sample = Mathf.PerlinNoise(xCoord, yCoord);
                            noise[(int)x, (int)y] += (sample * strengths[i]) + additions[i];

                            //top and bottom check
                            if(noise[(int)x, (int)y] > top)
                                top = noise[(int)x, (int)y];
                            else if(noise[(int)x, (int)y] < bottom)
                                bottom = noise[(int)x, (int)y];
                            x++;
                        }
                        y++;
                    }
                    totalStrength += strengths[i];
                }
                heightMap.SetHeightMap(noise, top, bottom, totalStrength);
                return noise;
            }
Exemple #10
0
    public void SpawnAlong(ref uint seed, PathList.PathObject obj)
    {
        if (string.IsNullOrEmpty(obj.Folder))
        {
            return;
        }
        Prefab[] prefabArray = Prefab.Load(string.Concat("assets/bundled/prefabs/autospawn/", obj.Folder), null, null, true);
        if (prefabArray == null || prefabArray.Length == 0)
        {
            Debug.LogError(string.Concat("Empty decor folder: ", obj.Folder));
            return;
        }
        SpawnFilter      filter     = obj.Filter;
        float            density    = obj.Density;
        float            distance   = obj.Distance;
        float            dithering  = obj.Dithering;
        TerrainHeightMap heightMap  = TerrainMeta.HeightMap;
        Vector3          startPoint = this.Path.GetStartPoint();
        List <Vector3>   vector3s   = new List <Vector3>();
        float            single     = distance * 0.25f;
        float            single1    = distance * 0.5f;
        float            length     = this.Path.Length - this.Path.EndOffset - single1;

        for (float i = this.Path.StartOffset + single1; i <= length; i += single)
        {
            Vector3 vector3 = (this.Spline ? this.Path.GetPointCubicHermite(i) : this.Path.GetPoint(i));
            if ((vector3 - startPoint).magnitude >= distance)
            {
                Vector3 tangent  = this.Path.GetTangent(i);
                Vector3 vector31 = PathList.rot90 * tangent;
                Vector3 height   = vector3;
                height.x += SeedRandom.Range(ref seed, -dithering, dithering);
                height.z += SeedRandom.Range(ref seed, -dithering, dithering);
                float single2 = TerrainMeta.NormalizeX(height.x);
                float single3 = TerrainMeta.NormalizeZ(height.z);
                if (filter.GetFactor(single2, single3) >= SeedRandom.Value(ref seed))
                {
                    if (density >= SeedRandom.Value(ref seed))
                    {
                        height.y = heightMap.GetHeight(single2, single3);
                        if (obj.Alignment == PathList.Alignment.None)
                        {
                            if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.identity, filter))
                            {
                                goto Label1;
                            }
                            goto Label0;
                        }
                        else if (obj.Alignment == PathList.Alignment.Forward)
                        {
                            if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.LookRotation(tangent), filter))
                            {
                                goto Label1;
                            }
                            goto Label0;
                        }
                        else if (obj.Alignment != PathList.Alignment.Inward)
                        {
                            vector3s.Add(height);
                        }
                        else
                        {
                            if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.LookRotation(vector31), filter))
                            {
                                goto Label1;
                            }
                            goto Label0;
                        }
                    }
Label1:
                    startPoint = vector3;
                }
            }
Label0:
        }
        if (vector3s.Count > 0)
        {
            this.SpawnObjectsNeighborAligned(ref seed, prefabArray, vector3s, filter);
        }
    }
    public override void Process(uint seed)
    {
        if ((long)World.Size < (long)this.MinSize)
        {
            return;
        }
        TerrainHeightMap heightMap = TerrainMeta.HeightMap;

        Prefab <MonumentInfo>[] array = Prefab.Load <MonumentInfo>("assets/bundled/prefabs/autospawn/" + this.ResourceFolder, (GameManager)null, (PrefabAttribute.Library)null, true);
        if (array == null || array.Length == 0)
        {
            return;
        }
        array.Shuffle <Prefab <MonumentInfo> >(seed);
        array.BubbleSort <Prefab <MonumentInfo> >();
        Vector3 position1 = TerrainMeta.Position;
        Vector3 size      = TerrainMeta.Size;
        float   x1        = (float)position1.x;
        float   z1        = (float)position1.z;
        float   num1      = (float)(position1.x + size.x);
        float   num2      = (float)(position1.z + size.z);
        List <PlaceMonuments.SpawnInfo> a = new List <PlaceMonuments.SpawnInfo>();
        int num3 = 0;
        List <PlaceMonuments.SpawnInfo> b = new List <PlaceMonuments.SpawnInfo>();

        for (int index1 = 0; index1 < 10; ++index1)
        {
            int num4 = 0;
            a.Clear();
            foreach (Prefab <MonumentInfo> prefab in array)
            {
                int num5 = Object.op_Implicit((Object)prefab.Parameters) ? (int)(prefab.Parameters.Priority + 1) : 1;
                int num6 = num5 * num5 * num5 * num5;
                for (int index2 = 0; index2 < 10000; ++index2)
                {
                    float  x2     = SeedRandom.Range(ref seed, x1, num1);
                    float  z2     = SeedRandom.Range(ref seed, z1, num2);
                    float  normX  = TerrainMeta.NormalizeX(x2);
                    float  normZ  = TerrainMeta.NormalizeZ(z2);
                    float  num7   = SeedRandom.Value(ref seed);
                    double factor = (double)this.Filter.GetFactor(normX, normZ);
                    if (factor * factor >= (double)num7)
                    {
                        float   height = heightMap.GetHeight(normX, normZ);
                        Vector3 pos;
                        ((Vector3) ref pos).\u002Ector(x2, height, z2);
                        Quaternion localRotation = prefab.Object.get_transform().get_localRotation();
                        Vector3    localScale    = prefab.Object.get_transform().get_localScale();
                        if (!this.CheckRadius(a, pos, (float)this.Distance))
                        {
                            prefab.ApplyDecorComponents(ref pos, ref localRotation, ref localScale);
                            if ((!Object.op_Implicit((Object)prefab.Component) || prefab.Component.CheckPlacement(pos, localRotation, localScale)) && (prefab.ApplyTerrainAnchors(ref pos, localRotation, localScale, this.Filter) && prefab.ApplyTerrainChecks(pos, localRotation, localScale, this.Filter)) && (prefab.ApplyTerrainFilters(pos, localRotation, localScale, (SpawnFilter)null) && prefab.ApplyWaterChecks(pos, localRotation, localScale) && !prefab.CheckEnvironmentVolumes(pos, localRotation, localScale, EnvironmentType.Underground)))
                            {
                                a.Add(new PlaceMonuments.SpawnInfo()
                                {
                                    prefab   = (Prefab)prefab,
                                    position = pos,
                                    rotation = localRotation,
                                    scale    = localScale
                                });
                                num4 += num6;
                                break;
                            }
                        }
                    }
                }
            }
            if (num4 > num3)
            {
                num3 = num4;
                GenericsUtil.Swap <List <PlaceMonuments.SpawnInfo> >(ref a, ref b);
            }
        }
        foreach (PlaceMonuments.SpawnInfo spawnInfo in b)
        {
            Prefab     prefab    = spawnInfo.prefab;
            Vector3    position2 = spawnInfo.position;
            Quaternion rotation  = spawnInfo.rotation;
            Vector3    scale     = spawnInfo.scale;
            prefab.ApplyTerrainPlacements(position2, rotation, scale);
            prefab.ApplyTerrainModifiers(position2, rotation, scale);
            World.AddPrefab("Monument", prefab.ID, position2, rotation, scale);
        }
    }
    public override void Process(uint seed)
    {
        List <PathList>     pathListList = new List <PathList>();
        TerrainHeightMap    heightMap    = TerrainMeta.HeightMap;
        TerrainTopologyMap  topologyMap  = TerrainMeta.TopologyMap;
        List <MonumentInfo> monuments    = TerrainMeta.Path.Monuments;

        if (monuments.Count == 0)
        {
            return;
        }
        int res = Mathf.NextPowerOfTwo((int)((double)World.Size / 10.0));

        int[,] costmap = new int[res, res];
        float radius = 5f;

        for (int index1 = 0; index1 < res; ++index1)
        {
            float normZ = ((float)index1 + 0.5f) / (float)res;
            for (int index2 = 0; index2 < res; ++index2)
            {
                float normX    = ((float)index2 + 0.5f) / (float)res;
                float slope    = heightMap.GetSlope(normX, normZ);
                int   topology = topologyMap.GetTopology(normX, normZ, radius);
                int   num1     = 2295174;
                int   num2     = 55296;
                int   num3     = 512;
                costmap[index1, index2] = (topology & num1) == 0 ? ((topology & num2) == 0 ? ((topology & num3) == 0 ? 1 + (int)((double)slope * (double)slope * 10.0) : 1000) : 2500) : int.MaxValue;
            }
        }
        PathFinder pathFinder = new PathFinder(costmap, true);
        List <GeneratePowerlineLayout.PathSegment> pathSegmentList = new List <GeneratePowerlineLayout.PathSegment>();
        List <GeneratePowerlineLayout.PathNode>    source1         = new List <GeneratePowerlineLayout.PathNode>();
        List <GeneratePowerlineLayout.PathNode>    source2         = new List <GeneratePowerlineLayout.PathNode>();
        List <PathFinder.Point> pointList = new List <PathFinder.Point>();
        List <PathFinder.Point> startList = new List <PathFinder.Point>();
        List <PathFinder.Point> endList   = new List <PathFinder.Point>();

        foreach (MonumentInfo monumentInfo in monuments)
        {
            bool flag = source1.Count == 0;
            foreach (TerrainPathConnect target in monumentInfo.GetTargets(InfrastructureType.Power))
            {
                PathFinder.Point point           = target.GetPoint(res);
                PathFinder.Node  closestWalkable = pathFinder.FindClosestWalkable(point, 100000);
                if (closestWalkable != null)
                {
                    GeneratePowerlineLayout.PathNode pathNode = new GeneratePowerlineLayout.PathNode();
                    pathNode.monument = monumentInfo;
                    pathNode.node     = closestWalkable;
                    if (flag)
                    {
                        source1.Add(pathNode);
                    }
                    else
                    {
                        source2.Add(pathNode);
                    }
                }
            }
        }
        while (source2.Count != 0)
        {
            startList.Clear();
            endList.Clear();
            startList.AddRange(source1.Select <GeneratePowerlineLayout.PathNode, PathFinder.Point>((Func <GeneratePowerlineLayout.PathNode, PathFinder.Point>)(x => x.node.point)));
            startList.AddRange((IEnumerable <PathFinder.Point>)pointList);
            endList.AddRange(source2.Select <GeneratePowerlineLayout.PathNode, PathFinder.Point>((Func <GeneratePowerlineLayout.PathNode, PathFinder.Point>)(x => x.node.point)));
            PathFinder.Node pathUndirected = pathFinder.FindPathUndirected(startList, endList, 100000);
            if (pathUndirected == null)
            {
                GeneratePowerlineLayout.PathNode copy = source2[0];
                source1.AddRange(source2.Where <GeneratePowerlineLayout.PathNode>((Func <GeneratePowerlineLayout.PathNode, bool>)(x => Object.op_Equality((Object)x.monument, (Object)copy.monument))));
                source2.RemoveAll((Predicate <GeneratePowerlineLayout.PathNode>)(x => Object.op_Equality((Object)x.monument, (Object)copy.monument)));
            }
            else
            {
                GeneratePowerlineLayout.PathSegment segment = new GeneratePowerlineLayout.PathSegment();
                for (PathFinder.Node node = pathUndirected; node != null; node = node.next)
                {
                    if (node == pathUndirected)
                    {
                        segment.start = node;
                    }
                    if (node.next == null)
                    {
                        segment.end = node;
                    }
                }
                pathSegmentList.Add(segment);
                GeneratePowerlineLayout.PathNode copy = source2.Find((Predicate <GeneratePowerlineLayout.PathNode>)(x =>
                {
                    if (!(x.node.point == segment.start.point))
                    {
                        return(x.node.point == segment.end.point);
                    }
                    return(true);
                }));
                source1.AddRange(source2.Where <GeneratePowerlineLayout.PathNode>((Func <GeneratePowerlineLayout.PathNode, bool>)(x => Object.op_Equality((Object)x.monument, (Object)copy.monument))));
                source2.RemoveAll((Predicate <GeneratePowerlineLayout.PathNode>)(x => Object.op_Equality((Object)x.monument, (Object)copy.monument)));
                int num = 1;
                for (PathFinder.Node node = pathUndirected; node != null; node = node.next)
                {
                    if (num % 8 == 0)
                    {
                        pointList.Add(node.point);
                    }
                    ++num;
                }
            }
        }
        List <Vector3> vector3List = new List <Vector3>();

        foreach (GeneratePowerlineLayout.PathSegment pathSegment in pathSegmentList)
        {
            for (PathFinder.Node node = pathSegment.start; node != null; node = node.next)
            {
                float normX    = ((float)node.point.x + 0.5f) / (float)res;
                float normZ    = ((float)node.point.y + 0.5f) / (float)res;
                float height01 = heightMap.GetHeight01(normX, normZ);
                vector3List.Add(TerrainMeta.Denormalize(new Vector3(normX, height01, normZ)));
            }
            if (vector3List.Count != 0)
            {
                if (vector3List.Count >= 8)
                {
                    pathListList.Add(new PathList("Powerline " + (object)pathListList.Count, vector3List.ToArray())
                    {
                        Start = true,
                        End   = true
                    });
                }
                vector3List.Clear();
            }
        }
        TerrainMeta.Path.Powerlines.AddRange((IEnumerable <PathList>)pathListList);
    }
Exemple #13
0
    public override void Process(uint seed)
    {
        if ((long)World.Size < (long)this.MinSize)
        {
            return;
        }
        TerrainHeightMap heightMap = TerrainMeta.HeightMap;

        Prefab <MonumentInfo>[] array = Prefab.Load <MonumentInfo>("assets/bundled/prefabs/autospawn/" + this.ResourceFolder, (GameManager)null, (PrefabAttribute.Library)null, true);
        if (array == null || array.Length == 0)
        {
            return;
        }
        array.Shuffle <Prefab <MonumentInfo> >(seed);
        array.BubbleSort <Prefab <MonumentInfo> >();
        Vector3 position1           = TerrainMeta.Position;
        Vector3 size                = TerrainMeta.Size;
        float   num1                = (float)position1.x - (float)this.MaxDistanceFromTerrain;
        float   num2                = (float)position1.x - (float)this.MinDistanceFromTerrain;
        float   num3                = (float)(position1.x + size.x) + (float)this.MinDistanceFromTerrain;
        float   num4                = (float)(position1.x + size.x) + (float)this.MaxDistanceFromTerrain;
        float   num5                = (float)position1.z - (float)this.MaxDistanceFromTerrain;
        int     distanceFromTerrain = this.MinDistanceFromTerrain;
        float   num6                = (float)(position1.z + size.z) + (float)this.MinDistanceFromTerrain;
        float   num7                = (float)(position1.z + size.z) + (float)this.MaxDistanceFromTerrain;
        List <PlaceMonumentsOffshore.SpawnInfo> a = new List <PlaceMonumentsOffshore.SpawnInfo>();
        int num8 = 0;
        List <PlaceMonumentsOffshore.SpawnInfo> b = new List <PlaceMonumentsOffshore.SpawnInfo>();

        for (int index1 = 0; index1 < 10; ++index1)
        {
            int num9 = 0;
            a.Clear();
            foreach (Prefab <MonumentInfo> prefab in array)
            {
                int num10 = Object.op_Implicit((Object)prefab.Parameters) ? (int)(prefab.Parameters.Priority + 1) : 1;
                int num11 = num10 * num10 * num10 * num10;
                for (int index2 = 0; index2 < 10000; ++index2)
                {
                    float x = 0.0f;
                    float z = 0.0f;
                    switch (seed % 4U)
                    {
                    case 0:
                        x = SeedRandom.Range(ref seed, num1, num2);
                        z = SeedRandom.Range(ref seed, num5, num7);
                        break;

                    case 1:
                        x = SeedRandom.Range(ref seed, num3, num4);
                        z = SeedRandom.Range(ref seed, num5, num7);
                        break;

                    case 2:
                        x = SeedRandom.Range(ref seed, num1, num4);
                        z = SeedRandom.Range(ref seed, num5, num5);
                        break;

                    case 3:
                        x = SeedRandom.Range(ref seed, num1, num4);
                        z = SeedRandom.Range(ref seed, num6, num7);
                        break;
                    }
                    float   normX  = TerrainMeta.NormalizeX(x);
                    float   normZ  = TerrainMeta.NormalizeZ(z);
                    float   height = heightMap.GetHeight(normX, normZ);
                    Vector3 pos;
                    ((Vector3) ref pos).\u002Ector(x, height, z);
                    Quaternion localRotation = prefab.Object.get_transform().get_localRotation();
                    Vector3    localScale    = prefab.Object.get_transform().get_localScale();
                    if (!this.CheckRadius(a, pos, (float)this.DistanceBetweenMonuments))
                    {
                        prefab.ApplyDecorComponents(ref pos, ref localRotation, ref localScale);
                        if ((!Object.op_Implicit((Object)prefab.Component) || prefab.Component.CheckPlacement(pos, localRotation, localScale)) && !prefab.CheckEnvironmentVolumes(pos, localRotation, localScale, EnvironmentType.Underground))
                        {
                            a.Add(new PlaceMonumentsOffshore.SpawnInfo()
                            {
                                prefab   = (Prefab)prefab,
                                position = pos,
                                rotation = localRotation,
                                scale    = localScale
                            });
                            num9 += num11;
                            break;
                        }
                    }
                }
            }
            if (num9 > num8)
            {
                num8 = num9;
                GenericsUtil.Swap <List <PlaceMonumentsOffshore.SpawnInfo> >(ref a, ref b);
            }
        }
        foreach (PlaceMonumentsOffshore.SpawnInfo spawnInfo in b)
        {
            Prefab     prefab    = spawnInfo.prefab;
            Vector3    position2 = spawnInfo.position;
            Quaternion rotation  = spawnInfo.rotation;
            Vector3    scale     = spawnInfo.scale;
            prefab.ApplyTerrainPlacements(position2, rotation, scale);
            prefab.ApplyTerrainModifiers(position2, rotation, scale);
            World.AddPrefab("Monument", prefab.ID, position2, rotation, scale);
        }
    }
Exemple #14
0
    public override void Process(uint seed)
    {
        List <PathList>     pathListList = new List <PathList>();
        TerrainHeightMap    heightMap    = TerrainMeta.HeightMap;
        TerrainTopologyMap  topologyMap  = TerrainMeta.TopologyMap;
        List <MonumentInfo> monuments    = TerrainMeta.Path.Monuments;

        if (monuments.Count == 0)
        {
            return;
        }
        int res = Mathf.NextPowerOfTwo((int)((double)World.Size / 10.0));

        int[,] costmap = new int[res, res];
        float radius = 5f;

        for (int index1 = 0; index1 < res; ++index1)
        {
            float normZ = ((float)index1 + 0.5f) / (float)res;
            for (int index2 = 0; index2 < res; ++index2)
            {
                float normX    = ((float)index2 + 0.5f) / (float)res;
                int   num1     = SeedRandom.Range(ref seed, 100, 500);
                float slope    = heightMap.GetSlope(normX, normZ);
                int   topology = topologyMap.GetTopology(normX, normZ, radius);
                int   num2     = 2295686;
                int   num3     = 49152;
                costmap[index1, index2] = (double)slope > 20.0 || (topology & num2) != 0 ? int.MaxValue : ((topology & num3) == 0 ? 1 + (int)((double)slope * (double)slope * 10.0) + num1 : 2500);
            }
        }
        PathFinder pathFinder = new PathFinder(costmap, true);
        List <GenerateRoadLayout.PathSegment> pathSegmentList = new List <GenerateRoadLayout.PathSegment>();
        List <GenerateRoadLayout.PathNode>    source1         = new List <GenerateRoadLayout.PathNode>();
        List <GenerateRoadLayout.PathNode>    source2         = new List <GenerateRoadLayout.PathNode>();
        List <PathFinder.Point> pointList = new List <PathFinder.Point>();
        List <PathFinder.Point> startList = new List <PathFinder.Point>();
        List <PathFinder.Point> endList   = new List <PathFinder.Point>();

        foreach (MonumentInfo monumentInfo in monuments)
        {
            bool flag = source1.Count == 0;
            foreach (TerrainPathConnect target in monumentInfo.GetTargets(InfrastructureType.Road))
            {
                PathFinder.Point point           = target.GetPoint(res);
                PathFinder.Node  closestWalkable = pathFinder.FindClosestWalkable(point, 100000);
                if (closestWalkable != null)
                {
                    GenerateRoadLayout.PathNode pathNode = new GenerateRoadLayout.PathNode();
                    pathNode.monument = monumentInfo;
                    pathNode.target   = target;
                    pathNode.node     = closestWalkable;
                    if (flag)
                    {
                        source1.Add(pathNode);
                    }
                    else
                    {
                        source2.Add(pathNode);
                    }
                }
            }
        }
        while (source2.Count != 0)
        {
            startList.Clear();
            endList.Clear();
            startList.AddRange(source1.Select <GenerateRoadLayout.PathNode, PathFinder.Point>((Func <GenerateRoadLayout.PathNode, PathFinder.Point>)(x => x.node.point)));
            startList.AddRange((IEnumerable <PathFinder.Point>)pointList);
            endList.AddRange(source2.Select <GenerateRoadLayout.PathNode, PathFinder.Point>((Func <GenerateRoadLayout.PathNode, PathFinder.Point>)(x => x.node.point)));
            PathFinder.Node pathUndirected = pathFinder.FindPathUndirected(startList, endList, 100000);
            if (pathUndirected == null)
            {
                GenerateRoadLayout.PathNode copy = source2[0];
                source1.AddRange(source2.Where <GenerateRoadLayout.PathNode>((Func <GenerateRoadLayout.PathNode, bool>)(x => Object.op_Equality((Object)x.monument, (Object)copy.monument))));
                source2.RemoveAll((Predicate <GenerateRoadLayout.PathNode>)(x => Object.op_Equality((Object)x.monument, (Object)copy.monument)));
            }
            else
            {
                GenerateRoadLayout.PathSegment segment = new GenerateRoadLayout.PathSegment();
                for (PathFinder.Node node = pathUndirected; node != null; node = node.next)
                {
                    if (node == pathUndirected)
                    {
                        segment.start = node;
                    }
                    if (node.next == null)
                    {
                        segment.end = node;
                    }
                }
                pathSegmentList.Add(segment);
                GenerateRoadLayout.PathNode copy = source2.Find((Predicate <GenerateRoadLayout.PathNode>)(x =>
                {
                    if (!(x.node.point == segment.start.point))
                    {
                        return(x.node.point == segment.end.point);
                    }
                    return(true);
                }));
                source1.AddRange(source2.Where <GenerateRoadLayout.PathNode>((Func <GenerateRoadLayout.PathNode, bool>)(x => Object.op_Equality((Object)x.monument, (Object)copy.monument))));
                source2.RemoveAll((Predicate <GenerateRoadLayout.PathNode>)(x => Object.op_Equality((Object)x.monument, (Object)copy.monument)));
                int num = 1;
                for (PathFinder.Node node = pathUndirected; node != null; node = node.next)
                {
                    if (num % 8 == 0)
                    {
                        pointList.Add(node.point);
                    }
                    ++num;
                }
            }
        }
        foreach (GenerateRoadLayout.PathNode pathNode in source1)
        {
            GenerateRoadLayout.PathNode    target      = pathNode;
            GenerateRoadLayout.PathSegment pathSegment = pathSegmentList.Find((Predicate <GenerateRoadLayout.PathSegment>)(x =>
            {
                if (!(x.start.point == target.node.point))
                {
                    return(x.end.point == target.node.point);
                }
                return(true);
            }));
            if (pathSegment != null)
            {
                if (pathSegment.start.point == target.node.point)
                {
                    PathFinder.Node node1 = target.node;
                    PathFinder.Node node2 = pathFinder.Reverse(target.node);
                    PathFinder.Node start = pathSegment.start;
                    node1.next         = start;
                    pathSegment.start  = node2;
                    pathSegment.origin = target.target;
                }
                else if (pathSegment.end.point == target.node.point)
                {
                    pathSegment.end.next = target.node;
                    pathSegment.end      = pathFinder.FindEnd(target.node);
                    pathSegment.target   = target.target;
                }
            }
        }
        List <Vector3> vector3List = new List <Vector3>();

        foreach (GenerateRoadLayout.PathSegment pathSegment in pathSegmentList)
        {
            bool flag1 = false;
            bool flag2 = false;
            for (PathFinder.Node node = pathSegment.start; node != null; node = node.next)
            {
                float normX = ((float)node.point.x + 0.5f) / (float)res;
                float normZ = ((float)node.point.y + 0.5f) / (float)res;
                if (pathSegment.start == node && Object.op_Inequality((Object)pathSegment.origin, (Object)null))
                {
                    flag1 = true;
                    normX = TerrainMeta.NormalizeX((float)((Component)pathSegment.origin).get_transform().get_position().x);
                    normZ = TerrainMeta.NormalizeZ((float)((Component)pathSegment.origin).get_transform().get_position().z);
                }
                else if (pathSegment.end == node && Object.op_Inequality((Object)pathSegment.target, (Object)null))
                {
                    flag2 = true;
                    normX = TerrainMeta.NormalizeX((float)((Component)pathSegment.target).get_transform().get_position().x);
                    normZ = TerrainMeta.NormalizeZ((float)((Component)pathSegment.target).get_transform().get_position().z);
                }
                float num1 = TerrainMeta.DenormalizeX(normX);
                float num2 = TerrainMeta.DenormalizeZ(normZ);
                float num3 = Mathf.Max(heightMap.GetHeight(normX, normZ), 1f);
                vector3List.Add(new Vector3(num1, num3, num2));
            }
            if (vector3List.Count != 0)
            {
                if (vector3List.Count >= 2)
                {
                    pathListList.Add(new PathList("Road " + (object)pathListList.Count, vector3List.ToArray())
                    {
                        Width         = 10f,
                        InnerPadding  = 1f,
                        OuterPadding  = 1f,
                        InnerFade     = 1f,
                        OuterFade     = 8f,
                        RandomScale   = 0.75f,
                        MeshOffset    = -0.0f,
                        TerrainOffset = -0.5f,
                        Topology      = 2048,
                        Splat         = 128,
                        Start         = flag1,
                        End           = flag2
                    });
                }
                vector3List.Clear();
            }
        }
        foreach (PathList pathList in pathListList)
        {
            pathList.Path.Smoothen(2);
        }
        TerrainMeta.Path.Roads.AddRange((IEnumerable <PathList>)pathListList);
    }
Exemple #15
0
    public void SpawnSide(ref uint seed, PathList.SideObject obj)
    {
        if (string.IsNullOrEmpty(obj.Folder))
        {
            return;
        }
        Prefab[] prefabArray = Prefab.Load(string.Concat("assets/bundled/prefabs/autospawn/", obj.Folder), null, null, true);
        if (prefabArray == null || prefabArray.Length == 0)
        {
            Debug.LogError(string.Concat("Empty decor folder: ", obj.Folder));
            return;
        }
        PathList.Side    side      = obj.Side;
        SpawnFilter      filter    = obj.Filter;
        float            density   = obj.Density;
        float            distance  = obj.Distance;
        float            width     = this.Width * 0.5f + obj.Offset;
        TerrainHeightMap heightMap = TerrainMeta.HeightMap;

        float[]        singleArray = new float[] { -width, width };
        int            num         = 0;
        Vector3        startPoint  = this.Path.GetStartPoint();
        List <Vector3> vector3s    = new List <Vector3>();
        float          single      = distance * 0.25f;
        float          single1     = distance * 0.5f;
        float          length      = this.Path.Length - this.Path.EndOffset - single1;

        for (float i = this.Path.StartOffset + single1; i <= length; i += single)
        {
            Vector3 vector3 = (this.Spline ? this.Path.GetPointCubicHermite(i) : this.Path.GetPoint(i));
            if ((vector3 - startPoint).magnitude >= distance)
            {
                Vector3 tangent  = this.Path.GetTangent(i);
                Vector3 vector31 = PathList.rot90 * tangent;
                for (int j = 0; j < (int)singleArray.Length; j++)
                {
                    int length1 = (num + j) % (int)singleArray.Length;
                    if ((side != PathList.Side.Left || length1 == 0) && (side != PathList.Side.Right || length1 == 1))
                    {
                        float     single2       = singleArray[length1];
                        Vector3   height        = vector3;
                        ref float singlePointer = ref height.x;
                        singlePointer = singlePointer + vector31.x * single2;
                        ref float singlePointer1 = ref height.z;
                        singlePointer1 = singlePointer1 + vector31.z * single2;
                        float single3 = TerrainMeta.NormalizeX(height.x);
                        float single4 = TerrainMeta.NormalizeZ(height.z);
                        if (filter.GetFactor(single3, single4) >= SeedRandom.Value(ref seed))
                        {
                            if (density >= SeedRandom.Value(ref seed))
                            {
                                height.y = heightMap.GetHeight(single3, single4);
                                if (obj.Alignment == PathList.Alignment.None)
                                {
                                    if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.identity, filter))
                                    {
                                        goto Label1;
                                    }
                                    goto Label0;
                                }
                                else if (obj.Alignment == PathList.Alignment.Forward)
                                {
                                    if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.LookRotation(tangent * single2), filter))
                                    {
                                        goto Label1;
                                    }
                                    goto Label0;
                                }
                                else if (obj.Alignment != PathList.Alignment.Inward)
                                {
                                    vector3s.Add(height);
                                }
                                else
                                {
                                    if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.LookRotation(-vector31 * single2), filter))
                                    {
                                        goto Label1;
                                    }
                                    goto Label0;
                                }
                            }
Label1:
                            num        = length1;
                            startPoint = vector3;
                            if (side == PathList.Side.Any)
                            {
                                break;
                            }
                        }
                    }
Label0:
                }
            }
            public static Vector3[] BuildVerticesFromHeightMap(TerrainHeightMap heightMap)
            {
                int size = TerrainChunkObject.TERRAIN_CHUNK_TILE_SIZE;
                Vector3[] vertices = new Vector3[((int)Mathf.Pow(size + 1, 2))];

                for (int i = 0, z = 0; z <= size; z++)
                {
                    for (int x = 0; x <= size; x++, i++)
                    {
                        float y = heightMap.GetFloat(x, z);
                        vertices[i] = new Vector3(x, y, z);
                    }
                }
                return vertices;
            }
Exemple #17
0
    public override void Process(uint seed)
    {
        int priority;

        if ((ulong)World.Size < (long)this.MinSize)
        {
            return;
        }
        TerrainHeightMap heightMap = TerrainMeta.HeightMap;

        Prefab <MonumentInfo>[] prefabArray = Prefab.Load <MonumentInfo>(string.Concat("assets/bundled/prefabs/autospawn/", this.ResourceFolder), null, null, true);
        if (prefabArray == null || prefabArray.Length == 0)
        {
            return;
        }
        prefabArray.Shuffle <Prefab <MonumentInfo> >(seed);
        prefabArray.BubbleSort <Prefab <MonumentInfo> >();
        Vector3 position = TerrainMeta.Position;
        Vector3 size     = TerrainMeta.Size;
        float   single   = position.x;
        float   single1  = position.z;
        float   single2  = position.x + size.x;
        float   single3  = position.z + size.z;
        int     num      = 0;
        List <PlaceMonuments.SpawnInfo> spawnInfos = new List <PlaceMonuments.SpawnInfo>();
        int num1 = 0;
        List <PlaceMonuments.SpawnInfo> spawnInfos1 = new List <PlaceMonuments.SpawnInfo>();

        for (int i = 0; i < 10; i++)
        {
            num = 0;
            spawnInfos.Clear();
            Prefab <MonumentInfo>[] prefabArray1 = prefabArray;
            for (int j = 0; j < (int)prefabArray1.Length; j++)
            {
                Prefab <MonumentInfo> prefab = prefabArray1[j];
                if (prefab.Parameters)
                {
                    priority = (int)prefab.Parameters.Priority + (int)PrefabPriority.Low;
                }
                else
                {
                    priority = 1;
                }
                int num2 = priority;
                int num3 = num2 * num2 * num2 * num2;
                for (int k = 0; k < 10000; k++)
                {
                    float single4 = SeedRandom.Range(ref seed, single, single2);
                    float single5 = SeedRandom.Range(ref seed, single1, single3);
                    float single6 = TerrainMeta.NormalizeX(single4);
                    float single7 = TerrainMeta.NormalizeZ(single5);
                    float single8 = SeedRandom.Value(ref seed);
                    float factor  = this.Filter.GetFactor(single6, single7);
                    if (factor * factor >= single8)
                    {
                        float      height  = heightMap.GetHeight(single6, single7);
                        Vector3    vector3 = new Vector3(single4, height, single5);
                        Quaternion obj     = prefab.Object.transform.localRotation;
                        Vector3    obj1    = prefab.Object.transform.localScale;
                        if (!this.CheckRadius(spawnInfos, vector3, (float)this.Distance))
                        {
                            prefab.ApplyDecorComponents(ref vector3, ref obj, ref obj1);
                            if ((!prefab.Component || prefab.Component.CheckPlacement(vector3, obj, obj1)) && prefab.ApplyTerrainAnchors(ref vector3, obj, obj1, this.Filter) && prefab.ApplyTerrainChecks(vector3, obj, obj1, this.Filter) && prefab.ApplyTerrainFilters(vector3, obj, obj1, null) && prefab.ApplyWaterChecks(vector3, obj, obj1) && !prefab.CheckEnvironmentVolumes(vector3, obj, obj1, EnvironmentType.Underground))
                            {
                                PlaceMonuments.SpawnInfo spawnInfo = new PlaceMonuments.SpawnInfo()
                                {
                                    prefab   = prefab,
                                    position = vector3,
                                    rotation = obj,
                                    scale    = obj1
                                };
                                spawnInfos.Add(spawnInfo);
                                num += num3;
                                break;
                            }
                        }
                    }
                }
            }
            if (num > num1)
            {
                num1 = num;
                GenericsUtil.Swap <List <PlaceMonuments.SpawnInfo> >(ref spawnInfos, ref spawnInfos1);
            }
        }
        foreach (PlaceMonuments.SpawnInfo spawnInfo1 in spawnInfos1)
        {
            Prefab     prefab1    = spawnInfo1.prefab;
            Vector3    vector31   = spawnInfo1.position;
            Quaternion quaternion = spawnInfo1.rotation;
            Vector3    vector32   = spawnInfo1.scale;
            prefab1.ApplyTerrainPlacements(vector31, quaternion, vector32);
            prefab1.ApplyTerrainModifiers(vector31, quaternion, vector32);
            World.AddPrefab("Monument", prefab1.ID, vector31, quaternion, vector32);
        }
    }
 public static Texture2D GenerateTextureFromHeightMap(TerrainHeightMap heightMap)
 {
     Texture2D tex = new Texture2D(TerrainChunkObject.TERRAIN_CHUNK_TEXTURE_RESOLUTION_SIZE, TerrainChunkObject.TERRAIN_CHUNK_TEXTURE_RESOLUTION_SIZE);
     tex.filterMode = FilterMode.Point;
     for (int x = 0; x < tex.width; x++)
     {
         for (int y = 0; y < tex.height; y++)
         {
             Color c = new Color();
             if (heightMap.GetFloat(x, y) > heightMap.highestFloat * 0.8f)
             {
                 c = Color.white;
             }
             else if (heightMap.GetFloat(x, y) > heightMap.highestFloat * 0.65f)
             {
                 c = new Color(0.65f, 0.65f, 0.65f);
             }
             else if (heightMap.GetFloat(x, y) < heightMap.highestFloat * 0.45f)
             {
                 c = Color.blue;
             }
             else
             {
                 c = Color.green;
             }
             c *= heightMap.GetFloat(x, y) / heightMap.totalStrength;
             tex.SetPixel(x, y, c);
         }
     }
     tex.Apply();
     return tex;
 }
Exemple #19
0
    public List <Mesh> CreateMesh()
    {
        List <Mesh>      meshes      = new List <Mesh>();
        float            single      = 8f;
        float            single1     = 64f;
        float            randomScale = this.RandomScale;
        float            meshOffset  = this.MeshOffset;
        float            width       = this.Width * 0.5f;
        int              length      = (int)(this.Path.Length / single) * 2;
        int              num         = (int)(this.Path.Length / single) * 3;
        List <Vector3>   vector3s    = new List <Vector3>(length);
        List <Color>     colors      = new List <Color>(length);
        List <Vector2>   vector2s    = new List <Vector2>(length);
        List <Vector3>   vector3s1   = new List <Vector3>(length);
        List <Vector4>   vector4s    = new List <Vector4>(length);
        List <int>       nums        = new List <int>(num);
        TerrainHeightMap heightMap   = TerrainMeta.HeightMap;
        Vector2          vector2     = new Vector2(0f, 0f);
        Vector2          vector21    = new Vector2(1f, 0f);
        Vector3          vector3     = Vector3.zero;
        Vector3          vector31    = Vector3.zero;
        Vector3          vector32    = Vector3.zero;
        Vector3          vector33    = Vector3.zero;
        int              num1        = -1;
        int              num2        = -1;
        float            length1     = this.Path.Length + single;

        for (float i = 0f; i < length1; i += single)
        {
            Vector3 vector34 = (this.Spline ? this.Path.GetPointCubicHermite(i) : this.Path.GetPoint(i));
            float   single2  = Mathf.Lerp(width, width * randomScale, Noise.Billow(vector34.x, vector34.z, 2, 0.005f, 1f, 2f, 0.5f));
            Vector3 tangent  = this.Path.GetTangent(i);
            Vector3 vector35 = tangent.XZ3D().normalized;
            Vector3 vector36 = PathList.rot90 * vector35;
            Vector4 vector4  = new Vector4(vector36.x, vector36.y, vector36.z, 1f);
            Vector3 vector37 = Vector3.Slerp(Vector3.Cross(tangent, vector36), Vector3.up, 0.1f);
            Vector3 vector38 = new Vector3(vector34.x - vector36.x * single2, 0f, vector34.z - vector36.z * single2)
            {
                y = Mathf.Min(vector34.y, heightMap.GetHeight(vector38)) + meshOffset
            };
            Vector3 vector39 = new Vector3(vector34.x + vector36.x * single2, 0f, vector34.z + vector36.z * single2)
            {
                y = Mathf.Min(vector34.y, heightMap.GetHeight(vector39)) + meshOffset
            };
            if (i != 0f)
            {
                float single3 = (vector34 - vector32).Magnitude2D() / (2f * single2);
                vector2.y  += single3;
                vector21.y += single3;
                if (Vector3.Dot((vector38 - vector3).XZ3D(), vector33) <= 0f)
                {
                    vector38 = vector3;
                }
                if (Vector3.Dot((vector39 - vector31).XZ3D(), vector33) <= 0f)
                {
                    vector39 = vector31;
                }
            }
            Color color = (i <= 0f || i + single >= length1 ? new Color(1f, 1f, 1f, 0f) : new Color(1f, 1f, 1f, 1f));
            vector2s.Add(vector2);
            colors.Add(color);
            vector3s.Add(vector38);
            vector3s1.Add(vector37);
            vector4s.Add(vector4);
            int count = vector3s.Count - 1;
            if (num1 != -1 && num2 != -1)
            {
                nums.Add(count);
                nums.Add(num2);
                nums.Add(num1);
            }
            num1    = count;
            vector3 = vector38;
            vector2s.Add(vector21);
            colors.Add(color);
            vector3s.Add(vector39);
            vector3s1.Add(vector37);
            vector4s.Add(vector4);
            int count1 = vector3s.Count - 1;
            if (num1 != -1 && num2 != -1)
            {
                nums.Add(count1);
                nums.Add(num2);
                nums.Add(num1);
            }
            num2     = count1;
            vector31 = vector39;
            vector32 = vector34;
            vector33 = vector35;
            if (vector3s.Count >= 100 && this.Path.Length - i > single1)
            {
                Mesh mesh = new Mesh();
                mesh.SetVertices(vector3s);
                mesh.SetColors(colors);
                mesh.SetUVs(0, vector2s);
                mesh.SetTriangles(nums, 0);
                mesh.SetNormals(vector3s1);
                mesh.SetTangents(vector4s);
                meshes.Add(mesh);
                vector3s.Clear();
                colors.Clear();
                vector2s.Clear();
                vector3s1.Clear();
                vector4s.Clear();
                nums.Clear();
                num1 = -1;
                num2 = -1;
                i   -= single;
            }
        }
        if (nums.Count > 0)
        {
            Mesh mesh1 = new Mesh();
            mesh1.SetVertices(vector3s);
            mesh1.SetColors(colors);
            mesh1.SetUVs(0, vector2s);
            mesh1.SetTriangles(nums, 0);
            mesh1.SetNormals(vector3s1);
            mesh1.SetTangents(vector4s);
            meshes.Add(mesh1);
        }
        return(meshes);
    }
    private void DoWork()
    {
        Vector3 vector3_1;

        ((Vector3) ref vector3_1).\u002Ector((float)(this.width / 2), 0.0f, (float)(this.height / 2));
        Vector3 vector3_2;

        ((Vector3) ref vector3_2).\u002Ector((float)(this.pivot.x - vector3_1.x), 0.0f, (float)(this.pivot.z - vector3_1.z));
        TerrainHeightMap heightMap = TerrainMeta.HeightMap;
        TerrainAlphaMap  alphaMap  = TerrainMeta.AlphaMap;
        int num1 = 0;

        for (int index = 0; index <= this.height; ++index)
        {
            int num2 = 0;
            while (num2 <= this.width)
            {
                Vector3 worldPos  = Vector3.op_Addition(new Vector3((float)num2, 0.0f, (float)index), vector3_2);
                Vector3 vector3_3 = Vector3.op_Subtraction(new Vector3((float)num2, 0.0f, (float)index), vector3_1);
                float   height    = heightMap.GetHeight(worldPos);
                if ((double)height < -1.0)
                {
                    this.indices.Add(-1);
                }
                else if (this.alpha && (double)alphaMap.GetAlpha(worldPos) < 0.100000001490116)
                {
                    this.indices.Add(-1);
                }
                else
                {
                    if (this.normal)
                    {
                        this.normals.Add(heightMap.GetNormal(worldPos));
                    }
                    worldPos.y = (__Null)(double)(vector3_3.y = (__Null)(height - (float)this.pivot.y));
                    this.indices.Add(this.vertices.Count);
                    this.vertices.Add(vector3_3);
                }
                ++num2;
                ++num1;
            }
        }
        int index1 = 0;
        int num3   = 0;

        while (num3 < this.height)
        {
            int num2 = 0;
            while (num2 < this.width)
            {
                int index2 = this.indices[index1];
                int index3 = this.indices[index1 + this.width + 1];
                int index4 = this.indices[index1 + 1];
                int index5 = this.indices[index1 + 1];
                int index6 = this.indices[index1 + this.width + 1];
                int index7 = this.indices[index1 + this.width + 2];
                if (index2 != -1 && index3 != -1 && index4 != -1)
                {
                    this.triangles.Add(index2);
                    this.triangles.Add(index3);
                    this.triangles.Add(index4);
                }
                if (index5 != -1 && index6 != -1 && index7 != -1)
                {
                    this.triangles.Add(index5);
                    this.triangles.Add(index6);
                    this.triangles.Add(index7);
                }
                ++num2;
                ++index1;
            }
            ++num3;
            ++index1;
        }
    }
Exemple #21
0
    public override void Process(uint seed)
    {
        int priority;

        if ((ulong)World.Size < (long)this.MinSize)
        {
            return;
        }
        TerrainHeightMap heightMap = TerrainMeta.HeightMap;

        Prefab <MonumentInfo>[] prefabArray = Prefab.Load <MonumentInfo>(string.Concat("assets/bundled/prefabs/autospawn/", this.ResourceFolder), null, null, true);
        if (prefabArray == null || prefabArray.Length == 0)
        {
            return;
        }
        prefabArray.Shuffle <Prefab <MonumentInfo> >(seed);
        prefabArray.BubbleSort <Prefab <MonumentInfo> >();
        Vector3 position = TerrainMeta.Position;
        Vector3 size     = TerrainMeta.Size;
        float   maxDistanceFromTerrain = position.x - (float)this.MaxDistanceFromTerrain;
        float   minDistanceFromTerrain = position.x - (float)this.MinDistanceFromTerrain;
        float   single = position.x + size.x + (float)this.MinDistanceFromTerrain;
        float   maxDistanceFromTerrain1 = position.x + size.x + (float)this.MaxDistanceFromTerrain;
        float   single1 = position.z - (float)this.MaxDistanceFromTerrain;
        int     num     = this.MinDistanceFromTerrain;
        float   minDistanceFromTerrain1 = position.z + size.z + (float)this.MinDistanceFromTerrain;
        float   maxDistanceFromTerrain2 = position.z + size.z + (float)this.MaxDistanceFromTerrain;
        int     num1 = 0;
        List <PlaceMonumentsOffshore.SpawnInfo> spawnInfos = new List <PlaceMonumentsOffshore.SpawnInfo>();
        int num2 = 0;
        List <PlaceMonumentsOffshore.SpawnInfo> spawnInfos1 = new List <PlaceMonumentsOffshore.SpawnInfo>();

        for (int i = 0; i < 10; i++)
        {
            num1 = 0;
            spawnInfos.Clear();
            Prefab <MonumentInfo>[] prefabArray1 = prefabArray;
            for (int j = 0; j < (int)prefabArray1.Length; j++)
            {
                Prefab <MonumentInfo> prefab = prefabArray1[j];
                if (prefab.Parameters)
                {
                    priority = (int)prefab.Parameters.Priority + (int)PrefabPriority.Low;
                }
                else
                {
                    priority = 1;
                }
                int num3 = priority;
                int num4 = num3 * num3 * num3 * num3;
                for (int k = 0; k < 10000; k++)
                {
                    float single2 = 0f;
                    float single3 = 0f;
                    switch (seed % 4)
                    {
                    case 0:
                    {
                        single2 = SeedRandom.Range(ref seed, maxDistanceFromTerrain, minDistanceFromTerrain);
                        single3 = SeedRandom.Range(ref seed, single1, maxDistanceFromTerrain2);
                        break;
                    }

                    case 1:
                    {
                        single2 = SeedRandom.Range(ref seed, single, maxDistanceFromTerrain1);
                        single3 = SeedRandom.Range(ref seed, single1, maxDistanceFromTerrain2);
                        break;
                    }

                    case 2:
                    {
                        single2 = SeedRandom.Range(ref seed, maxDistanceFromTerrain, maxDistanceFromTerrain1);
                        single3 = SeedRandom.Range(ref seed, single1, single1);
                        break;
                    }

                    case 3:
                    {
                        single2 = SeedRandom.Range(ref seed, maxDistanceFromTerrain, maxDistanceFromTerrain1);
                        single3 = SeedRandom.Range(ref seed, minDistanceFromTerrain1, maxDistanceFromTerrain2);
                        break;
                    }
                    }
                    float      single4 = TerrainMeta.NormalizeX(single2);
                    float      height  = heightMap.GetHeight(single4, TerrainMeta.NormalizeZ(single3));
                    Vector3    vector3 = new Vector3(single2, height, single3);
                    Quaternion obj     = prefab.Object.transform.localRotation;
                    Vector3    obj1    = prefab.Object.transform.localScale;
                    if (!this.CheckRadius(spawnInfos, vector3, (float)this.DistanceBetweenMonuments))
                    {
                        prefab.ApplyDecorComponents(ref vector3, ref obj, ref obj1);
                        if ((!prefab.Component || prefab.Component.CheckPlacement(vector3, obj, obj1)) && !prefab.CheckEnvironmentVolumes(vector3, obj, obj1, EnvironmentType.Underground))
                        {
                            PlaceMonumentsOffshore.SpawnInfo spawnInfo = new PlaceMonumentsOffshore.SpawnInfo()
                            {
                                prefab   = prefab,
                                position = vector3,
                                rotation = obj,
                                scale    = obj1
                            };
                            spawnInfos.Add(spawnInfo);
                            num1 += num4;
                            break;
                        }
                    }
                }
            }
            if (num1 > num2)
            {
                num2 = num1;
                GenericsUtil.Swap <List <PlaceMonumentsOffshore.SpawnInfo> >(ref spawnInfos, ref spawnInfos1);
            }
        }
        foreach (PlaceMonumentsOffshore.SpawnInfo spawnInfo1 in spawnInfos1)
        {
            Prefab     prefab1    = spawnInfo1.prefab;
            Vector3    vector31   = spawnInfo1.position;
            Quaternion quaternion = spawnInfo1.rotation;
            Vector3    vector32   = spawnInfo1.scale;
            prefab1.ApplyTerrainPlacements(vector31, quaternion, vector32);
            prefab1.ApplyTerrainModifiers(vector31, quaternion, vector32);
            World.AddPrefab("Monument", prefab1.ID, vector31, quaternion, vector32);
        }
    }
Exemple #22
0
    private void DoWork()
    {
        Vector3          vector3   = new Vector3((float)(this.width / 2), 0f, (float)(this.height / 2));
        Vector3          vector31  = new Vector3(this.pivot.x - vector3.x, 0f, this.pivot.z - vector3.z);
        TerrainHeightMap heightMap = TerrainMeta.HeightMap;
        TerrainAlphaMap  alphaMap  = TerrainMeta.AlphaMap;
        int num = 0;

        for (int i = 0; i <= this.height; i++)
        {
            int num1 = 0;
            while (num1 <= this.width)
            {
                Vector3 vector32 = new Vector3((float)num1, 0f, (float)i) + vector31;
                Vector3 vector33 = new Vector3((float)num1, 0f, (float)i) - vector3;
                float   height   = heightMap.GetHeight(vector32);
                if (height < -1f)
                {
                    this.indices.Add(-1);
                }
                else if (!this.alpha || alphaMap.GetAlpha(vector32) >= 0.1f)
                {
                    if (this.normal)
                    {
                        Vector3 normal = heightMap.GetNormal(vector32);
                        this.normals.Add(normal);
                    }
                    float single  = height - this.pivot.y;
                    float single1 = single;
                    vector33.y = single;
                    vector32.y = single1;
                    this.indices.Add(this.vertices.Count);
                    this.vertices.Add(vector33);
                }
                else
                {
                    this.indices.Add(-1);
                }
                num1++;
                num++;
            }
        }
        int num2 = 0;
        int num3 = 0;

        while (num3 < this.height)
        {
            int num4 = 0;
            while (num4 < this.width)
            {
                int item  = this.indices[num2];
                int item1 = this.indices[num2 + this.width + 1];
                int item2 = this.indices[num2 + 1];
                int item3 = this.indices[num2 + 1];
                int item4 = this.indices[num2 + this.width + 1];
                int item5 = this.indices[num2 + this.width + 2];
                if (item != -1 && item1 != -1 && item2 != -1)
                {
                    this.triangles.Add(item);
                    this.triangles.Add(item1);
                    this.triangles.Add(item2);
                }
                if (item3 != -1 && item4 != -1 && item5 != -1)
                {
                    this.triangles.Add(item3);
                    this.triangles.Add(item4);
                    this.triangles.Add(item5);
                }
                num4++;
                num2++;
            }
            num3++;
            num2++;
        }
    }
    private void DoWork()
    {
        Vector3          vector    = new Vector3(width / 2, 0f, height / 2);
        Vector3          vector2   = new Vector3(pivot.x - vector.x, 0f, pivot.z - vector.z);
        TerrainHeightMap heightMap = TerrainMeta.HeightMap;
        TerrainAlphaMap  alphaMap  = TerrainMeta.AlphaMap;
        int num = 0;

        for (int i = 0; i <= height; i++)
        {
            int num2 = 0;
            while (num2 <= width)
            {
                Vector3 worldPos = new Vector3(num2, 0f, i) + vector2;
                Vector3 item     = new Vector3(num2, 0f, i) - vector;
                float   num3     = heightMap.GetHeight(worldPos);
                if (num3 < -1f)
                {
                    indices.Add(-1);
                }
                else if (alpha && alphaMap.GetAlpha(worldPos) < 0.1f)
                {
                    indices.Add(-1);
                }
                else
                {
                    if (normal)
                    {
                        Vector3 item2 = heightMap.GetNormal(worldPos);
                        normals.Add(item2);
                    }
                    worldPos.y = (item.y = num3 - pivot.y);
                    indices.Add(vertices.Count);
                    vertices.Add(item);
                }
                num2++;
                num++;
            }
        }
        int num4 = 0;
        int num5 = 0;

        while (num5 < height)
        {
            int num6 = 0;
            while (num6 < width)
            {
                int num7  = indices[num4];
                int num8  = indices[num4 + width + 1];
                int num9  = indices[num4 + 1];
                int num10 = indices[num4 + 1];
                int num11 = indices[num4 + width + 1];
                int num12 = indices[num4 + width + 2];
                if (num7 != -1 && num8 != -1 && num9 != -1)
                {
                    triangles.Add(num7);
                    triangles.Add(num8);
                    triangles.Add(num9);
                }
                if (num10 != -1 && num11 != -1 && num12 != -1)
                {
                    triangles.Add(num10);
                    triangles.Add(num11);
                    triangles.Add(num12);
                }
                num6++;
                num4++;
            }
            num5++;
            num4++;
        }
    }