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 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) { 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); }
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> 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); }