Пример #1
0
    private static void Process(int x, int z, bool keepExisting)
    {
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        float normZ    = topologyMap.Coordinate(z);
        float normX    = topologyMap.Coordinate(x);
        int   topology = topologyMap.GetTopology(x, z);

        if ((topology & 8389632) != 0)
        {
            return;
        }
        float slope = TerrainMeta.HeightMap.GetSlope(normX, normZ);
        float splat = TerrainMeta.SplatMap.GetSplat(normX, normZ, 8);

        if ((double)slope > 40.0 || (double)splat > 0.400000005960464)
        {
            topologyMap.AddTopology(x, z, 2);
        }
        else
        {
            if (keepExisting || (double)slope >= 20.0 || ((double)splat >= 0.200000002980232 || (topology & 55296) == 0))
            {
                return;
            }
            topologyMap.RemoveTopology(x, z, 2);
        }
    }
Пример #2
0
    public override void Process(uint seed)
    {
        List <PathList>    roads     = TerrainMeta.Path.Roads;
        TerrainHeightMap   heightmap = TerrainMeta.HeightMap;
        TerrainTopologyMap topomap   = TerrainMeta.TopologyMap;

        foreach (PathList pathList in roads)
        {
            pathList.Path.RecalculateTangents();
        }
        heightmap.Push();
        foreach (PathList pathList in roads)
        {
            pathList.AdjustTerrainHeight();
            pathList.AdjustTerrainTexture();
            pathList.AdjustTerrainTopology();
        }
        heightmap.Pop();
        int[] map = topomap.dst;
        int   res = topomap.res;

        ImageProcessing.Dilate2D(map, res, res, 6144, 6, (Action <int, int>)((x, y) =>
        {
            if ((map[x * res + y] & 49) != 0)
            {
                map[x * res + y] |= 4096;
            }
            if ((double)heightmap.GetSlope(topomap.Coordinate(x), topomap.Coordinate(y)) <= 40.0)
            {
                return;
            }
            map[x * res + y] |= 2;
        }));
    }
    public override void Process(uint seed)
    {
        List <PathList>    rivers      = TerrainMeta.Path.Rivers;
        TerrainHeightMap   heightMap   = TerrainMeta.HeightMap;
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;

        foreach (PathList river in rivers)
        {
            river.Path.RecalculateTangents();
        }
        heightMap.Push();
        foreach (PathList pathList in rivers)
        {
            pathList.AdjustTerrainHeight();
            pathList.AdjustTerrainTexture();
            pathList.AdjustTerrainTopology();
        }
        heightMap.Pop();
        int[] numArray = topologyMap.dst;
        int   num      = topologyMap.res;

        ImageProcessing.Dilate2D(numArray, num, num, 49152, 6, (int x, int y) => {
            if ((numArray[x * num + y] & 49) != 0)
            {
                numArray[x * num + y] |= 32768;
            }
            float single  = topologyMap.Coordinate(x);
            float single1 = topologyMap.Coordinate(y);
            if (heightMap.GetSlope(single, single1) > 40f)
            {
                numArray[x * num + y] |= 2;
            }
        });
    }
Пример #4
0
    public override void Process(uint seed)
    {
        List <PathList>    pathListList = new List <PathList>();
        TerrainHeightMap   heightMap    = TerrainMeta.HeightMap;
        TerrainTopologyMap topologyMap  = TerrainMeta.TopologyMap;
        List <Vector3>     vector3List  = new List <Vector3>();

        for (float z = (float)TerrainMeta.Position.z; (double)z < TerrainMeta.Position.z + TerrainMeta.Size.z; z += 50f)
        {
            for (float x = (float)TerrainMeta.Position.x; (double)x < TerrainMeta.Position.x + TerrainMeta.Size.x; x += 50f)
            {
                Vector3 worldPos;
                ((Vector3) ref worldPos).\u002Ector(x, 0.0f, z);
                float num1 = (float)(double)(worldPos.y = (__Null)heightMap.GetHeight(worldPos));
                if (worldPos.y > 5.0)
                {
                    Vector3 normal1 = heightMap.GetNormal(worldPos);
                    if (normal1.y > 0.00999999977648258)
                    {
                        Vector2 vector2    = new Vector2((float)normal1.x, (float)normal1.z);
                        Vector2 normalized = ((Vector2) ref vector2).get_normalized();
                        vector3List.Add(worldPos);
                        float radius = 12f;
                        int   num2   = 12;
                        for (int index = 0; index < 10000; ++index)
                        {
                            ref __Null local1 = ref worldPos.x;
Пример #5
0
    public void AdjustTerrainHeight()
    {
        TerrainHeightMap   heightMap   = TerrainMeta.HeightMap;
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        float   single6       = 1f;
        float   randomScale   = this.RandomScale;
        float   outerPadding  = this.OuterPadding;
        float   innerPadding  = this.InnerPadding;
        float   outerFade     = this.OuterFade;
        float   innerFade     = this.InnerFade;
        float   terrainOffset = this.TerrainOffset * TerrainMeta.OneOverSize.y;
        float   width         = this.Width * 0.5f;
        Vector3 startPoint    = this.Path.GetStartPoint();
        Vector3 endPoint      = this.Path.GetEndPoint();
        Vector3 startTangent  = this.Path.GetStartTangent();
        Vector3 vector32      = PathList.rot90 * startTangent;
        Vector3 vector33      = startPoint - (vector32 * (width + outerPadding + outerFade));
        Vector3 vector34      = startPoint + (vector32 * (width + outerPadding + outerFade));
        float   length        = this.Path.Length + single6;

        for (float i = 0f; i < length; i += single6)
        {
            Vector3 vector35 = (this.Spline ? this.Path.GetPointCubicHermite(i) : this.Path.GetPoint(i));
            float   single7  = (startPoint - vector35).Magnitude2D();
            float   single8  = (endPoint - vector35).Magnitude2D();
            float   single9  = Mathf.InverseLerp(0f, width, Mathf.Min(single7, single8));
            float   single10 = Mathf.Lerp(width, width * randomScale, Noise.Billow(vector35.x, vector35.z, 2, 0.005f, 1f, 2f, 0.5f));
            Vector3 vector36 = this.Path.GetTangent(i).XZ3D();
            startTangent = vector36.normalized;
            vector32     = PathList.rot90 * startTangent;
            Ray     ray      = new Ray(vector35, startTangent);
            Vector3 vector37 = vector35 - (vector32 * (single10 + outerPadding + outerFade));
            Vector3 vector38 = vector35 + (vector32 * (single10 + outerPadding + outerFade));
            float   single11 = TerrainMeta.NormalizeY(vector35.y);
            heightMap.ForEach(vector33, vector34, vector37, vector38, (int x, int z) => {
                float single  = heightMap.Coordinate(x);
                float single1 = heightMap.Coordinate(z);
                if ((topologyMap.GetTopology(single, single1) & this.Topology) != 0)
                {
                    return;
                }
                Vector3 vector3  = TerrainMeta.Denormalize(new Vector3(single, single11, single1));
                Vector3 vector31 = ray.ClosestPoint(vector3);
                float single2    = (vector3 - vector31).Magnitude2D();
                float single3    = Mathf.InverseLerp(single10 + outerPadding + outerFade, single10 + outerPadding, single2);
                float single4    = Mathf.InverseLerp(single10 - innerPadding, single10 - innerPadding - innerFade, single2);
                float single5    = TerrainMeta.NormalizeY(vector31.y);
                single3          = Mathf.SmoothStep(0f, 1f, single3);
                single4          = Mathf.SmoothStep(0f, 1f, single4);
                heightMap.SetHeight(x, z, single5 + terrainOffset * single4, single9 * single3);
            });
            vector33 = vector37;
            vector34 = vector38;
        }
    }
    public void RefreshTerrainData()
    {
        TerrainData      terrainData = Terrain.get_activeTerrain().get_terrainData();
        TerrainHeightMap component1  = (TerrainHeightMap)((Component)Terrain.get_activeTerrain()).GetComponent <TerrainHeightMap>();

        if (Object.op_Implicit((Object)component1))
        {
            this.heightmap = component1.HeightTexture;
        }
        TerrainSplatMap component2 = (TerrainSplatMap)((Component)Terrain.get_activeTerrain()).GetComponent <TerrainSplatMap>();

        if (Object.op_Implicit((Object)component2))
        {
            this.splatmap0 = component2.SplatTexture0;
            this.splatmap1 = component2.SplatTexture1;
        }
        TerrainAlphaMap component3 = (TerrainAlphaMap)((Component)Terrain.get_activeTerrain()).GetComponent <TerrainAlphaMap>();

        if (Object.op_Implicit((Object)component3))
        {
            this.alphamap = component3.AlphaTexture;
        }
        TerrainBiomeMap component4 = (TerrainBiomeMap)((Component)Terrain.get_activeTerrain()).GetComponent <TerrainBiomeMap>();

        if (Object.op_Implicit((Object)component4))
        {
            this.biomemap = component4.BiomeTexture;
        }
        TerrainTopologyMap component5 = (TerrainTopologyMap)((Component)Terrain.get_activeTerrain()).GetComponent <TerrainTopologyMap>();

        if (Object.op_Implicit((Object)component5))
        {
            this.topologymap = component5.TopologyTexture;
        }
        TerrainWaterMap component6 = (TerrainWaterMap)((Component)Terrain.get_activeTerrain()).GetComponent <TerrainWaterMap>();

        if (Object.op_Implicit((Object)component6))
        {
            this.watermap = component6.WaterTexture;
        }
        TerrainBlendMap component7 = (TerrainBlendMap)((Component)Terrain.get_activeTerrain()).GetComponent <TerrainBlendMap>();

        if (Object.op_Implicit((Object)component7))
        {
            this.blendmap = component7.BlendTexture;
        }
        this.size    = terrainData.get_size();
        this.extents = Vector3.op_Multiply(terrainData.get_size(), 0.5f);
        this.offset  = Vector3.op_Subtraction(Vector3.op_Addition(Terrain.get_activeTerrain().GetPosition(), Vector3.op_Multiply(Vector3Ex.XZ3D(terrainData.get_size()), 0.5f)), ((Component)this).get_transform().get_position());
    }
    public void RefreshTerrainData()
    {
        TerrainData      terrainDatum = Terrain.activeTerrain.terrainData;
        TerrainHeightMap component    = Terrain.activeTerrain.GetComponent <TerrainHeightMap>();

        if (component)
        {
            this.heightmap = component.HeightTexture;
        }
        TerrainSplatMap terrainSplatMap = Terrain.activeTerrain.GetComponent <TerrainSplatMap>();

        if (terrainSplatMap)
        {
            this.splatmap0 = terrainSplatMap.SplatTexture0;
            this.splatmap1 = terrainSplatMap.SplatTexture1;
        }
        TerrainAlphaMap terrainAlphaMap = Terrain.activeTerrain.GetComponent <TerrainAlphaMap>();

        if (terrainAlphaMap)
        {
            this.alphamap = terrainAlphaMap.AlphaTexture;
        }
        TerrainBiomeMap terrainBiomeMap = Terrain.activeTerrain.GetComponent <TerrainBiomeMap>();

        if (terrainBiomeMap)
        {
            this.biomemap = terrainBiomeMap.BiomeTexture;
        }
        TerrainTopologyMap terrainTopologyMap = Terrain.activeTerrain.GetComponent <TerrainTopologyMap>();

        if (terrainTopologyMap)
        {
            this.topologymap = terrainTopologyMap.TopologyTexture;
        }
        TerrainWaterMap terrainWaterMap = Terrain.activeTerrain.GetComponent <TerrainWaterMap>();

        if (terrainWaterMap)
        {
            this.watermap = terrainWaterMap.WaterTexture;
        }
        TerrainBlendMap terrainBlendMap = Terrain.activeTerrain.GetComponent <TerrainBlendMap>();

        if (terrainBlendMap)
        {
            this.blendmap = terrainBlendMap.BlendTexture;
        }
        this.size    = terrainDatum.size;
        this.extents = terrainDatum.size * 0.5f;
        this.offset  = (Terrain.activeTerrain.GetPosition() + (terrainDatum.size.XZ3D() * 0.5f)) - base.transform.position;
    }
Пример #8
0
    public void AdjustTerrainTopology()
    {
        if (this.Topology == 0)
        {
            return;
        }
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        float   single3      = 1f;
        float   randomScale  = this.RandomScale;
        float   outerPadding = this.OuterPadding;
        float   innerPadding = this.InnerPadding;
        float   width        = this.Width * 0.5f;
        Vector3 startPoint   = this.Path.GetStartPoint();
        Vector3 endPoint     = this.Path.GetEndPoint();
        Vector3 startTangent = this.Path.GetStartTangent();
        Vector3 vector31     = PathList.rot90 * startTangent;
        Vector3 vector32     = startPoint - (vector31 * (width + outerPadding));
        Vector3 vector33     = startPoint + (vector31 * (width + outerPadding));
        float   length       = this.Path.Length + single3;

        for (float i = 0f; i < length; i += single3)
        {
            Vector3 vector34 = (this.Spline ? this.Path.GetPointCubicHermite(i) : this.Path.GetPoint(i));
            float   single4  = (startPoint - vector34).Magnitude2D();
            float   single5  = (endPoint - vector34).Magnitude2D();
            float   single6  = Mathf.InverseLerp(0f, width, Mathf.Min(single4, single5));
            float   single7  = Mathf.Lerp(width, width * randomScale, Noise.Billow(vector34.x, vector34.z, 2, 0.005f, 1f, 2f, 0.5f));
            Vector3 vector35 = this.Path.GetTangent(i).XZ3D();
            startTangent = vector35.normalized;
            vector31     = PathList.rot90 * startTangent;
            Ray     ray      = new Ray(vector34, startTangent);
            Vector3 vector36 = vector34 - (vector31 * (single7 + outerPadding));
            Vector3 vector37 = vector34 + (vector31 * (single7 + outerPadding));
            float   single8  = TerrainMeta.NormalizeY(vector34.y);
            topologyMap.ForEach(vector32, vector33, vector36, vector37, (int x, int z) => {
                float single    = topologyMap.Coordinate(x);
                float single1   = topologyMap.Coordinate(z);
                Vector3 vector3 = TerrainMeta.Denormalize(new Vector3(single, single8, single1));
                float single2   = (vector3 - ray.ClosestPoint(vector3)).Magnitude2D();
                if (Mathf.InverseLerp(single7 + outerPadding, single7 - innerPadding, single2) * single6 > 0.3f)
                {
                    topologyMap.SetTopology(x, z, this.Topology);
                }
            });
            vector32 = vector36;
            vector33 = vector37;
        }
    }
    public override void Process(uint seed)
    {
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        int num = topologyMap.res;

        Parallel.For(0, num, (int z) => {
            for (int i = 0; i < num; i++)
            {
                if (topologyMap.GetTopology(i, z, 4194306))
                {
                    topologyMap.AddTopology(i, z, 512);
                }
                else if (!this.KeepExisting)
                {
                    topologyMap.RemoveTopology(i, z, 512);
                }
            }
        });
    }
Пример #10
0
    public static void Process(int x, int z)
    {
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        float normZ = topologyMap.Coordinate(z);
        float normX = topologyMap.Coordinate(x);

        if ((topologyMap.GetTopology(x, z) & 0x800400) == 0)
        {
            float slope = TerrainMeta.HeightMap.GetSlope(normX, normZ);
            float splat = TerrainMeta.SplatMap.GetSplat(normX, normZ, 8);
            if (slope > 40f || splat > 0.4f)
            {
                topologyMap.AddTopology(x, z, 2);
            }
            else
            {
                topologyMap.RemoveTopology(x, z, 2);
            }
        }
    }
Пример #11
0
    public override void Process(uint seed)
    {
        TerrainTopologyMap topomap = TerrainMeta.TopologyMap;
        int topores = topomap.res;

        Parallel.For(0, topores, delegate(int z)
        {
            for (int i = 0; i < topores; i++)
            {
                if (topomap.GetTopology(i, z, 4194306))
                {
                    topomap.AddTopology(i, z, 512);
                }
                else if (!KeepExisting)
                {
                    topomap.RemoveTopology(i, z, 512);
                }
            }
        });
    }
    public override void Process(uint seed)
    {
        TerrainTopologyMap topomap = TerrainMeta.TopologyMap;
        int topores = topomap.res;

        Parallel.For(0, topores, (Action <int>)(z =>
        {
            for (int x = 0; x < topores; ++x)
            {
                if (topomap.GetTopology(x, z, 4194306))
                {
                    topomap.AddTopology(x, z, 512);
                }
                else if (!this.KeepExisting)
                {
                    topomap.RemoveTopology(x, z, 512);
                }
            }
        }));
    }
    public static void Process(int x, int z)
    {
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        float single  = topologyMap.Coordinate(z);
        float single1 = topologyMap.Coordinate(x);

        if ((topologyMap.GetTopology(x, z) & 8389632) == 0)
        {
            float slope = TerrainMeta.HeightMap.GetSlope(single1, single);
            float splat = TerrainMeta.SplatMap.GetSplat(single1, single, 8);
            if (slope > 40f || splat > 0.4f)
            {
                topologyMap.AddTopology(x, z, 2);
                return;
            }
            if (slope < 20f && splat < 0.2f)
            {
                topologyMap.RemoveTopology(x, z, 2);
            }
        }
    }
Пример #14
0
    private static void Process(int x, int z, bool keepExisting)
    {
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        float normZ    = topologyMap.Coordinate(z);
        float normX    = topologyMap.Coordinate(x);
        int   topology = topologyMap.GetTopology(x, z);

        if (!World.Procedural || (topology & 0x800400) == 0)
        {
            float slope = TerrainMeta.HeightMap.GetSlope(normX, normZ);
            float splat = TerrainMeta.SplatMap.GetSplat(normX, normZ, 8);
            if (slope > 40f || splat > 0.4f)
            {
                topologyMap.AddTopology(x, z, 2);
            }
            else if (!keepExisting)
            {
                topologyMap.RemoveTopology(x, z, 2);
            }
        }
    }
    private static void Process(int x, int z, bool keepExisting)
    {
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        float single   = topologyMap.Coordinate(z);
        float single1  = topologyMap.Coordinate(x);
        int   topology = topologyMap.GetTopology(x, z);

        if ((topology & 8389632) == 0)
        {
            float slope = TerrainMeta.HeightMap.GetSlope(single1, single);
            float splat = TerrainMeta.SplatMap.GetSplat(single1, single, 8);
            if (slope > 40f || splat > 0.4f)
            {
                topologyMap.AddTopology(x, z, 2);
                return;
            }
            if (!keepExisting && slope < 20f && splat < 0.2f && (topology & 55296) != 0)
            {
                topologyMap.RemoveTopology(x, z, 2);
            }
        }
    }
Пример #16
0
    private void MarkRoadside()
    {
        TerrainHeightMap   heightmap = TerrainMeta.HeightMap;
        TerrainTopologyMap topomap   = TerrainMeta.TopologyMap;

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

        ImageProcessing.Dilate2D(map, res, res, 6144, 6, delegate(int x, int y)
        {
            if (((uint)map[x * res + y] & 0x31u) != 0)
            {
                map[x * res + y] |= 4096;
            }
            float normX = topomap.Coordinate(x);
            float normZ = topomap.Coordinate(y);
            if (heightmap.GetSlope(normX, normZ) > 40f)
            {
                map[x * res + y] |= 2;
            }
        });
    }
Пример #17
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);
    }
Пример #18
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);
    }
Пример #19
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);
    }
    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);
    }
Пример #21
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);
    }
Пример #22
0
    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);
    }
Пример #23
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);
    }