Ejemplo n.º 1
0
 public float GetSplat(Vector3 worldPos, int mask)
 {
     return(this.GetSplat(TerrainMeta.NormalizeX((float)worldPos.x), TerrainMeta.NormalizeZ((float)worldPos.z), mask));
 }
Ejemplo n.º 2
0
    public override void Process(uint seed)
    {
        if (World.Networked || World.Size < MinWorldSize)
        {
            return;
        }
        int[,] array = TerrainPath.CreateRoadCostmap(ref seed);
        PathFinder      pathFinder = new PathFinder(array);
        int             length     = array.GetLength(0);
        int             num        = length / 4;
        int             num2       = 4;
        int             stepcount  = num / num2;
        int             num3       = length / 2;
        int             pos_x      = num;
        int             pos_x2     = length - num;
        int             pos_y      = num;
        int             pos_y2     = length - num;
        int             num4       = 0;
        int             dir_x      = -num2;
        int             dir_x2     = num2;
        int             dir_y      = -num2;
        int             dir_y2     = num2;
        List <RingNode> list       = ((World.Size >= 5000) ? new List <RingNode>
        {
            new RingNode(num3, pos_y2, num4, dir_y, stepcount),
            new RingNode(pos_x2, pos_y2, dir_x, dir_y, stepcount),
            new RingNode(pos_x2, num3, dir_x, num4, stepcount),
            new RingNode(pos_x2, pos_y, dir_x, dir_y2, stepcount),
            new RingNode(num3, pos_y, num4, dir_y2, stepcount),
            new RingNode(pos_x, pos_y, dir_x2, dir_y2, stepcount),
            new RingNode(pos_x, num3, dir_x2, num4, stepcount),
            new RingNode(pos_x, pos_y2, dir_x2, dir_y, stepcount)
        } : new List <RingNode>
        {
            new RingNode(pos_x2, pos_y2, dir_x, dir_y, stepcount),
            new RingNode(pos_x2, pos_y, dir_x, dir_y2, stepcount),
            new RingNode(pos_x, pos_y, dir_x2, dir_y2, stepcount),
            new RingNode(pos_x, pos_y2, dir_x2, dir_y, stepcount)
        });

        for (int i = 0; i < list.Count; i++)
        {
            RingNode ringNode = list[i];
            RingNode next     = list[(i + 1) % list.Count];
            RingNode prev     = list[(i - 1 + list.Count) % list.Count];
            ringNode.next = next;
            ringNode.prev = prev;
            while (!pathFinder.IsWalkable(ringNode.position))
            {
                if (ringNode.attempts <= 0)
                {
                    return;
                }
                ringNode.position += ringNode.direction;
                ringNode.attempts--;
            }
        }
        foreach (RingNode item in list)
        {
            item.path = pathFinder.FindPath(item.position, item.next.position, 250000);
        }
        bool flag = false;

        while (!flag)
        {
            flag = true;
            PathFinder.Point point = new PathFinder.Point(0, 0);
            foreach (RingNode item2 in list)
            {
                point += item2.position;
            }
            point /= list.Count;
            float    num5      = float.MinValue;
            RingNode ringNode2 = null;
            foreach (RingNode item3 in list)
            {
                if (item3.path == null)
                {
                    float num6 = new Vector2(item3.position.x - point.x, item3.position.y - point.y).magnitude;
                    if (item3.prev.path == null)
                    {
                        num6 *= 1.5f;
                    }
                    if (num6 > num5)
                    {
                        num5      = num6;
                        ringNode2 = item3;
                    }
                }
            }
            if (ringNode2 == null)
            {
                continue;
            }
            do
            {
                if (ringNode2.attempts <= 0)
                {
                    return;
                }
                ringNode2.position += ringNode2.direction;
                ringNode2.attempts--;
            }while (!pathFinder.IsWalkable(ringNode2.position));
            ringNode2.path      = pathFinder.FindPath(ringNode2.position, ringNode2.next.position, 250000);
            ringNode2.prev.path = pathFinder.FindPath(ringNode2.prev.position, ringNode2.position, 250000);
            flag = false;
        }
        if (!flag)
        {
            return;
        }
        for (int j = 0; j < list.Count; j++)
        {
            RingNode ringNode3 = list[j];
            RingNode ringNode4 = list[(j + 1) % list.Count];
            for (PathFinder.Node node = ringNode3.path; node != null; node = node.next)
            {
                for (PathFinder.Node node2 = ringNode4.path; node2 != null; node2 = node2.next)
                {
                    if (Mathf.Abs(node.point.x - node2.point.x) <= 1 && Mathf.Abs(node.point.y - node2.point.y) <= 1)
                    {
                        node.next      = null;
                        ringNode4.path = node2;
                        break;
                    }
                }
            }
        }
        PathFinder.Node node3 = null;
        PathFinder.Node node4 = null;
        foreach (RingNode item4 in list)
        {
            if (node3 == null)
            {
                node3 = item4.path;
                node4 = item4.path;
            }
            else
            {
                node4.next = item4.path;
            }
            while (node4.next != null)
            {
                node4 = node4.next;
            }
        }
        node4.next = new PathFinder.Node(node3.point, node3.cost, node3.heuristic);
        List <Vector3> list2 = new List <Vector3>();

        for (PathFinder.Node node5 = node3; node5 != null; node5 = node5.next)
        {
            float normX = ((float)node5.point.x + 0.5f) / (float)length;
            float normZ = ((float)node5.point.y + 0.5f) / (float)length;
            float x     = TerrainMeta.DenormalizeX(normX);
            float z     = TerrainMeta.DenormalizeZ(normZ);
            float y     = Mathf.Max(TerrainMeta.HeightMap.GetHeight(normX, normZ), 1f);
            list2.Add(new Vector3(x, y, z));
        }
        if (list2.Count >= 2)
        {
            int      count    = TerrainMeta.Path.Roads.Count;
            PathList pathList = new PathList("Road " + count, list2.ToArray());
            pathList.Width            = 12f;
            pathList.InnerPadding     = 1f;
            pathList.OuterPadding     = 1f;
            pathList.InnerFade        = 1f;
            pathList.OuterFade        = 8f;
            pathList.RandomScale      = 0.75f;
            pathList.MeshOffset       = 0f;
            pathList.TerrainOffset    = -0.125f;
            pathList.Topology         = 2048;
            pathList.Splat            = 128;
            pathList.Start            = false;
            pathList.End              = false;
            pathList.ProcgenStartNode = node3;
            pathList.ProcgenEndNode   = node4;
            pathList.Path.Smoothen(4);
            pathList.Path.RecalculateTangents();
            pathList.AdjustPlacementMap(24f);
            TerrainMeta.Path.Roads.Add(pathList);
        }
    }
Ejemplo n.º 3
0
    protected override void ApplyTopology(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        TextureData topologydata = new TextureData(this.topologymap);

        TerrainMeta.TopologyMap.ForEachParallel(((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)-this.extents.x, 0.0f, (float)-this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)this.extents.x, 0.0f, (float)-this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)-this.extents.x, 0.0f, (float)this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)this.extents.x, 0.0f, (float)this.extents.z))), (Action <int, int>)((x, z) =>
        {
            GenerateCliffTopology.Process(x, z);
            float normZ = TerrainMeta.TopologyMap.Coordinate(z);
            float normX = TerrainMeta.TopologyMap.Coordinate(x);
            Vector3 vector3_1;
            ((Vector3) ref vector3_1).\u002Ector(TerrainMeta.DenormalizeX(normX), 0.0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 vector3_2   = Vector3.op_Subtraction(((Matrix4x4) ref worldToLocal).MultiplyPoint3x4(vector3_1), this.offset);
            int interpolatedInt = topologydata.GetInterpolatedInt((float)((vector3_2.x + this.extents.x) / this.size.x), (float)((vector3_2.z + this.extents.z) / this.size.z));
            if (!this.ShouldTopology(interpolatedInt))
            {
                return;
            }
            TerrainMeta.TopologyMap.AddTopology(x, z, interpolatedInt & this.TopologyMask);
        }));
    }
Ejemplo n.º 4
0
 internal bool IsInside(Vector3 vPos)
 {
     return(!Vector3Ex.IsNaNOrInfinity(vPos) && ((Bounds) ref this.worldBounds).Contains(vPos) && (!Object.op_Inequality((Object)TerrainMeta.Terrain, (Object)null) || vPos.y >= TerrainMeta.Position.y && !TerrainMeta.OutOfMargin(vPos)));
 }
Ejemplo n.º 5
0
    public override void Process()
    {
        RaycastHit raycastHit;
        Collider   component = base.GetComponent <Collider>();
        Bounds     bound     = component.bounds;
        int        num       = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeX(bound.min.x));
        int        num1      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeZ(bound.max.x));
        int        num2      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeX(bound.min.z));
        int        num3      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeZ(bound.max.z));

        if (!(component is BoxCollider) || !(base.transform.rotation == Quaternion.identity))
        {
            for (int i = num2; i <= num3; i++)
            {
                float single = TerrainMeta.WaterMap.Coordinate(i);
                for (int j = num; j <= num1; j++)
                {
                    float   single1 = TerrainMeta.WaterMap.Coordinate(j);
                    Vector3 vector3 = new Vector3(TerrainMeta.DenormalizeX(single1), bound.max.y + 1f, TerrainMeta.DenormalizeZ(single));
                    Ray     ray     = new Ray(vector3, Vector3.down);
                    if (component.Raycast(ray, out raycastHit, bound.size.y + 1f + 1f))
                    {
                        float single2 = TerrainMeta.NormalizeY(raycastHit.point.y);
                        if (single2 > TerrainMeta.WaterMap.GetHeight01(j, i))
                        {
                            TerrainMeta.WaterMap.SetHeight(j, i, single2);
                        }
                    }
                }
            }
        }
        else
        {
            float single3 = TerrainMeta.NormalizeY(bound.max.y);
            for (int k = num2; k <= num3; k++)
            {
                for (int l = num; l <= num1; l++)
                {
                    if (single3 > TerrainMeta.WaterMap.GetHeight01(l, k))
                    {
                        TerrainMeta.WaterMap.SetHeight(l, k, single3);
                    }
                }
            }
        }
        GameManager.Destroy(this, 0f);
    }
    public Vector3 GetNormal(Vector3 worldPos)
    {
        float single = TerrainMeta.NormalizeX(worldPos.x);

        return(this.GetNormal(single, TerrainMeta.NormalizeZ(worldPos.z)));
    }
    public float GetHeight01(Vector3 worldPos)
    {
        float single = TerrainMeta.NormalizeX(worldPos.x);

        return(this.GetHeight01(single, TerrainMeta.NormalizeZ(worldPos.z)));
    }
Ejemplo n.º 8
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);
    }
Ejemplo n.º 9
0
    public void AddTopology(Vector3 worldPos, int mask)
    {
        float single = TerrainMeta.NormalizeX(worldPos.x);

        this.AddTopology(single, TerrainMeta.NormalizeZ(worldPos.z), mask);
    }
Ejemplo n.º 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);
        }
    }
Ejemplo n.º 11
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:
                }
            }
Ejemplo n.º 12
0
 public void AddSplat(Vector3 worldPos, int id, float delta, float radius, float fade = 0.0f)
 {
     this.AddSplat(TerrainMeta.NormalizeX((float)worldPos.x), TerrainMeta.NormalizeZ((float)worldPos.z), id, delta, radius, fade);
 }
Ejemplo n.º 13
0
 public void SetSplat(Vector3 worldPos, int id, float opacity, float radius, float fade = 0.0f)
 {
     this.SetSplat(TerrainMeta.NormalizeX((float)worldPos.x), TerrainMeta.NormalizeZ((float)worldPos.z), id, opacity, radius, fade);
 }
Ejemplo n.º 14
0
 public void SetSplat(Vector3 worldPos, int id)
 {
     this.SetSplat(TerrainMeta.NormalizeX((float)worldPos.x), TerrainMeta.NormalizeZ((float)worldPos.z), id);
 }
Ejemplo n.º 15
0
    public override void Process()
    {
        Collider component = (Collider)((Component)this).GetComponent <Collider>();
        Bounds   bounds    = component.get_bounds();
        int      num1      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeX((float)((Bounds) ref bounds).get_min().x));
        int      num2      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeZ((float)((Bounds) ref bounds).get_max().x));
        int      num3      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeX((float)((Bounds) ref bounds).get_min().z));
        int      num4      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeZ((float)((Bounds) ref bounds).get_max().z));

        if (component is BoxCollider && Quaternion.op_Equality(((Component)this).get_transform().get_rotation(), Quaternion.get_identity()))
        {
            float height = TerrainMeta.NormalizeY((float)((Bounds) ref bounds).get_max().y);
            for (int z = num3; z <= num4; ++z)
            {
                for (int x = num1; x <= num2; ++x)
                {
                    float height01 = TerrainMeta.WaterMap.GetHeight01(x, z);
                    if ((double)height > (double)height01)
                    {
                        TerrainMeta.WaterMap.SetHeight(x, z, height);
                    }
                }
            }
        }
        else
        {
            for (int index1 = num3; index1 <= num4; ++index1)
            {
                float normZ = TerrainMeta.WaterMap.Coordinate(index1);
                for (int index2 = num1; index2 <= num2; ++index2)
                {
                    float   normX = TerrainMeta.WaterMap.Coordinate(index2);
                    Vector3 vector3;
                    ((Vector3) ref vector3).\u002Ector(TerrainMeta.DenormalizeX(normX), (float)(((Bounds) ref bounds).get_max().y + 1.0), TerrainMeta.DenormalizeZ(normZ));
                    Ray ray;
                    ((Ray) ref ray).\u002Ector(vector3, Vector3.get_down());
                    RaycastHit raycastHit;
                    if (component.Raycast(ray, ref raycastHit, (float)(((Bounds) ref bounds).get_size().y + 1.0 + 1.0)))
                    {
                        float height   = TerrainMeta.NormalizeY((float)((RaycastHit) ref raycastHit).get_point().y);
                        float height01 = TerrainMeta.WaterMap.GetHeight01(index2, index1);
                        if ((double)height > (double)height01)
                        {
                            TerrainMeta.WaterMap.SetHeight(index2, index1, height);
                        }
                    }
                }
            }
        }
        GameManager.Destroy((Component)this, 0.0f);
    }
Ejemplo n.º 16
0
    public override void Process(uint seed)
    {
        if (World.Networked)
        {
            TerrainMeta.Path.Powerlines.Clear();
            TerrainMeta.Path.Powerlines.AddRange(World.GetPaths("Powerline"));
            return;
        }
        List <PathList>     list      = new List <PathList>();
        List <MonumentInfo> monuments = TerrainMeta.Path.Monuments;

        int[,] array = TerrainPath.CreatePowerlineCostmap(ref seed);
        PathFinder              pathFinder = new PathFinder(array);
        int                     length     = array.GetLength(0);
        List <PathSegment>      list2      = new List <PathSegment>();
        List <PathNode>         list3      = new List <PathNode>();
        List <PathNode>         list4      = new List <PathNode>();
        List <PathFinder.Point> list5      = new List <PathFinder.Point>();
        List <PathFinder.Point> list6      = new List <PathFinder.Point>();
        List <PathFinder.Point> list7      = new List <PathFinder.Point>();

        foreach (PathList road in TerrainMeta.Path.Roads)
        {
            if (road.ProcgenStartNode == null || road.ProcgenEndNode == null || !road.IsExtraWide)
            {
                continue;
            }
            int num = 1;
            for (PathFinder.Node node = road.ProcgenStartNode; node != null; node = node.next)
            {
                if (num % 8 == 0)
                {
                    list5.Add(node.point);
                }
                num++;
            }
        }
        foreach (MonumentInfo item in monuments)
        {
            TerrainPathConnect[] componentsInChildren = item.GetComponentsInChildren <TerrainPathConnect>(true);
            foreach (TerrainPathConnect terrainPathConnect in componentsInChildren)
            {
                if (terrainPathConnect.Type == InfrastructureType.Power)
                {
                    PathFinder.Point pathFinderPoint = terrainPathConnect.GetPathFinderPoint(length);
                    PathFinder.Node  node2           = pathFinder.FindClosestWalkable(pathFinderPoint, 100000);
                    if (node2 != null)
                    {
                        PathNode pathNode = new PathNode();
                        pathNode.monument = item;
                        pathNode.node     = node2;
                        list4.Add(pathNode);
                    }
                }
            }
        }
        while (list4.Count != 0)
        {
            list7.Clear();
            list7.AddRange(list4.Select((PathNode x) => x.node.point));
            list6.Clear();
            list6.AddRange(list3.Select((PathNode x) => x.node.point));
            list6.AddRange(list5);
            PathFinder.Node node3 = pathFinder.FindPathUndirected(list6, list7, 100000);
            if (node3 == null)
            {
                PathNode copy2 = list4[0];
                list3.AddRange(list4.Where((PathNode x) => x.monument == copy2.monument));
                list4.RemoveAll((PathNode x) => x.monument == copy2.monument);
                continue;
            }
            PathSegment segment = new PathSegment();
            for (PathFinder.Node node4 = node3; node4 != null; node4 = node4.next)
            {
                if (node4 == node3)
                {
                    segment.start = node4;
                }
                if (node4.next == null)
                {
                    segment.end = node4;
                }
            }
            list2.Add(segment);
            PathNode copy = list4.Find((PathNode x) => x.node.point == segment.start.point || x.node.point == segment.end.point);
            list3.AddRange(list4.Where((PathNode x) => x.monument == copy.monument));
            list4.RemoveAll((PathNode x) => x.monument == copy.monument);
            int num2 = 1;
            for (PathFinder.Node node5 = node3; node5 != null; node5 = node5.next)
            {
                if (num2 % 8 == 0)
                {
                    list5.Add(node5.point);
                }
                num2++;
            }
        }
        List <Vector3> list8 = new List <Vector3>();

        foreach (PathSegment item2 in list2)
        {
            for (PathFinder.Node node6 = item2.start; node6 != null; node6 = node6.next)
            {
                float num3   = ((float)node6.point.x + 0.5f) / (float)length;
                float num4   = ((float)node6.point.y + 0.5f) / (float)length;
                float height = TerrainMeta.HeightMap.GetHeight01(num3, num4);
                list8.Add(TerrainMeta.Denormalize(new Vector3(num3, height, num4)));
            }
            if (list8.Count != 0)
            {
                if (list8.Count >= 8)
                {
                    int      num5     = TerrainMeta.Path.Powerlines.Count + list.Count;
                    PathList pathList = new PathList("Powerline " + num5, list8.ToArray());
                    pathList.Start            = true;
                    pathList.End              = true;
                    pathList.ProcgenStartNode = item2.start;
                    pathList.ProcgenEndNode   = item2.end;
                    list.Add(pathList);
                }
                list8.Clear();
            }
        }
        foreach (PathList item3 in list)
        {
            item3.Path.RecalculateTangents();
        }
        TerrainMeta.Path.Powerlines.AddRange(list);
    }
    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);
    }
Ejemplo n.º 18
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);
        }
    }
    public void SetHeight(Vector3 worldPos, float height)
    {
        float single = TerrainMeta.NormalizeX(worldPos.x);

        this.SetHeight(single, TerrainMeta.NormalizeZ(worldPos.z), height);
    }
Ejemplo n.º 20
0
 public void SetBiome(Vector3 worldPos, int id, float v)
 {
     this.SetBiome(TerrainMeta.NormalizeX((float)worldPos.x), TerrainMeta.NormalizeZ((float)worldPos.z), id, v);
 }
Ejemplo n.º 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);
        }
    }
Ejemplo n.º 22
0
 public float GetBiomeMax(Vector3 worldPos, int mask = -1)
 {
     return(this.GetBiomeMax(TerrainMeta.NormalizeX((float)worldPos.x), TerrainMeta.NormalizeZ((float)worldPos.z), mask));
 }
Ejemplo n.º 23
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);
    }
Ejemplo n.º 24
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   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);
        }
    }
Ejemplo n.º 25
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);
    }
Ejemplo n.º 26
0
    public override void Process()
    {
        Collider component = GetComponent <Collider>();
        Bounds   bounds    = component.bounds;
        int      num       = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeX(bounds.min.x));
        int      num2      = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeZ(bounds.max.x));
        int      num3      = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeX(bounds.min.z));
        int      num4      = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeZ(bounds.max.z));

        for (int i = num3; i <= num4; i++)
        {
            float normZ = TerrainMeta.HeightMap.Coordinate(i);
            for (int j = num; j <= num2; j++)
            {
                float      normX  = TerrainMeta.HeightMap.Coordinate(j);
                Vector3    origin = new Vector3(TerrainMeta.DenormalizeX(normX), bounds.max.y, TerrainMeta.DenormalizeZ(normZ));
                Ray        ray    = new Ray(origin, Vector3.down);
                RaycastHit hitInfo;
                if (component.Raycast(ray, out hitInfo, bounds.size.y))
                {
                    float num5   = TerrainMeta.NormalizeY(hitInfo.point.y);
                    float height = TerrainMeta.HeightMap.GetHeight01(j, i);
                    if (num5 > height)
                    {
                        TerrainMeta.HeightMap.SetHeight(j, i, num5);
                    }
                }
            }
        }
        if (DestroyGameObject)
        {
            GameManager.Destroy(base.gameObject);
        }
        else
        {
            GameManager.Destroy(this);
        }
    }
Ejemplo n.º 27
0
    protected override void ApplyBiome(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        bool should0 = this.ShouldBiome(1);
        bool should1 = this.ShouldBiome(2);
        bool should2 = this.ShouldBiome(4);
        bool should3 = this.ShouldBiome(8);

        if (!should0 && !should1 && (!should2 && !should3))
        {
            return;
        }
        Vector3     position   = ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.get_zero());
        TextureData heightdata = new TextureData(this.heightmap);
        TextureData biomedata  = new TextureData(this.biomemap);

        TerrainMeta.BiomeMap.ForEachParallel(((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)-this.extents.x, 0.0f, (float)-this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)this.extents.x, 0.0f, (float)-this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)-this.extents.x, 0.0f, (float)this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)this.extents.x, 0.0f, (float)this.extents.z))), (Action <int, int>)((x, z) =>
        {
            float normZ = TerrainMeta.BiomeMap.Coordinate(z);
            float normX = TerrainMeta.BiomeMap.Coordinate(x);
            Vector3 vector3_1;
            ((Vector3) ref vector3_1).\u002Ector(TerrainMeta.DenormalizeX(normX), 0.0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 vector3_2 = Vector3.op_Subtraction(((Matrix4x4) ref worldToLocal).MultiplyPoint3x4(vector3_1), this.offset);
            float opacity     = Mathf.InverseLerp((float)position.y, (float)position.y + this.Fade, (float)(position.y + this.offset.y + (double)heightdata.GetInterpolatedHalf((float)((vector3_2.x + this.extents.x) / this.size.x), (float)((vector3_2.z + this.extents.z) / this.size.z)) * this.size.y));
            if ((double)opacity == 0.0)
            {
                return;
            }
            Vector4 interpolatedVector = biomedata.GetInterpolatedVector((float)((vector3_2.x + this.extents.x) / this.size.x), (float)((vector3_2.z + this.extents.z) / this.size.z));
            if (!should0)
            {
                interpolatedVector.x = (__Null)0.0;
            }
            if (!should1)
            {
                interpolatedVector.y = (__Null)0.0;
            }
            if (!should2)
            {
                interpolatedVector.z = (__Null)0.0;
            }
            if (!should3)
            {
                interpolatedVector.w = (__Null)0.0;
            }
            TerrainMeta.BiomeMap.SetBiomeRaw(x, z, interpolatedVector, opacity);
        }));
    }
    public void SetAlpha(Vector3 worldPos, float a)
    {
        float single = TerrainMeta.NormalizeX(worldPos.x);

        this.SetAlpha(single, TerrainMeta.NormalizeZ(worldPos.z), a);
    }
Ejemplo n.º 29
0
    protected override void ApplyHeight(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        Vector3     position   = ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.get_zero());
        TextureData heightdata = new TextureData(this.heightmap);

        TerrainMeta.HeightMap.ForEachParallel(((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)-this.extents.x, 0.0f, (float)-this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)this.extents.x, 0.0f, (float)-this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)-this.extents.x, 0.0f, (float)this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)this.extents.x, 0.0f, (float)this.extents.z))), (Action <int, int>)((x, z) =>
        {
            float normZ = TerrainMeta.HeightMap.Coordinate(z);
            float normX = TerrainMeta.HeightMap.Coordinate(x);
            Vector3 vector3_1;
            ((Vector3) ref vector3_1).\u002Ector(TerrainMeta.DenormalizeX(normX), 0.0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 vector3_2 = Vector3.op_Subtraction(((Matrix4x4) ref worldToLocal).MultiplyPoint3x4(vector3_1), this.offset);
            float y           = (float)(position.y + this.offset.y + (double)heightdata.GetInterpolatedHalf((float)((vector3_2.x + this.extents.x) / this.size.x), (float)((vector3_2.z + this.extents.z) / this.size.z)) * this.size.y);
            float opacity     = Mathf.InverseLerp((float)position.y, (float)position.y + this.Fade, y);
            if ((double)opacity == 0.0)
            {
                return;
            }
            float num    = TerrainMeta.NormalizeY(y);
            float height = Mathx.SmoothMax(TerrainMeta.HeightMap.GetHeight01(x, z), num, 0.1f);
            TerrainMeta.HeightMap.SetHeight(x, z, height, opacity);
        }));
    }
Ejemplo n.º 30
0
 public int GetSplatMaxIndex(Vector3 worldPos, int mask = -1)
 {
     return(this.GetSplatMaxIndex(TerrainMeta.NormalizeX((float)worldPos.x), TerrainMeta.NormalizeZ((float)worldPos.z), mask));
 }