public static void CalculateMiddlePoints(Vector3 startPos, Vector3 startDir, Vector3 endPos, Vector3 endDir, bool smoothStart, bool smoothEnd, out Vector3 middlePos1, out Vector3 middlePos2, out float distance) { if (NetSegment.IsStraight(startPos, startDir, endPos, endDir, out distance)) { middlePos1 = startPos + startDir * (distance * ((!smoothStart) ? 0.15f : 0.3f)); middlePos2 = endPos + endDir * (distance * ((!smoothEnd) ? 0.15f : 0.3f)); } else { float dotxz = VectorUtils.DotXZ(startDir, endDir); if (dotxz >= -0.999f && Line2.Intersect( VectorUtils.XZ(startPos), VectorUtils.XZ(startPos + startDir), VectorUtils.XZ(endPos), VectorUtils.XZ(endPos + endDir), out float u, out float v)) { u = Mathf.Clamp(u, distance * 0.1f, distance); v = Mathf.Clamp(v, distance * 0.1f, distance); float uv = u + v; middlePos1 = startPos + startDir * Mathf.Min(u, uv * 0.3f); middlePos2 = endPos + endDir * Mathf.Min(v, uv * 0.3f); }
private void GetIntersectionPoints() { IntersectionResultArray iresArray1; SetComparisonResult result1 = Line1.Intersect(Line3, out iresArray1); IntersectionResult ires1 = iresArray1.get_Item(0); Point1 = ires1.XYZPoint; IntersectionResultArray iresArray2; SetComparisonResult result2 = Line1.Intersect(Line4, out iresArray2); IntersectionResult ires2 = iresArray2.get_Item(0); Point2 = ires2.XYZPoint; IntersectionResultArray iresArray3; SetComparisonResult result3 = Line2.Intersect(Line3, out iresArray3); IntersectionResult ires3 = iresArray3.get_Item(0); Point3 = ires3.XYZPoint; IntersectionResultArray iresArray4; SetComparisonResult result4 = Line2.Intersect(Line4, out iresArray4); IntersectionResult ires4 = iresArray4.get_Item(0); Point4 = ires4.XYZPoint; }
private void OnPointDrag(MarkupPoint point) { var normal = point.Enter.CornerDir.Turn90(true); Line2.Intersect(point.Position.XZ(), (point.Position + point.Enter.CornerDir).XZ(), MouseWorldPosition.XZ(), (MouseWorldPosition + normal).XZ(), out float offsetChange, out _); point.Offset = (point.Offset + offsetChange * Mathf.Sin(point.Enter.CornerAndNormalAngle)).RoundToNearest(0.01f); }
public override void OnMouseDrag(Event e) { var normal = DragPoint.Enter.CornerDir.Turn90(true); Line2.Intersect(DragPoint.Position.XZ(), (DragPoint.Position + DragPoint.Enter.CornerDir).XZ(), NodeMarkupTool.MouseWorldPosition.XZ(), (NodeMarkupTool.MouseWorldPosition + normal).XZ(), out float offsetChange, out _); DragPoint.Offset = (DragPoint.Offset + offsetChange * Mathf.Sin(DragPoint.Enter.CornerAndNormalAngle)).RoundToNearest(0.01f); Panel.EditPoint(DragPoint); }
public override void OnMouseDrag(Event e) { var normal = DragPoint.Enter.CornerDir.Turn90(true); var position = SingletonTool <NodeMarkupTool> .Instance.Ray.GetRayPosition(Markup.Position.y, out _); Line2.Intersect(XZ(DragPoint.Position), XZ(DragPoint.Position + DragPoint.Enter.CornerDir), XZ(position), XZ(position + normal), out float offsetChange, out _); DragPoint.Offset.Value = (DragPoint.Offset + offsetChange * Mathf.Sin(DragPoint.Enter.CornerAndNormalAngle)).RoundToNearest(0.01f); Panel.SelectPoint(DragPoint); }
private void OnPointDrag(MarkupPoint point) { RaycastInput input = new RaycastInput(MouseRay, MouseRayLength); RayCast(input, out RaycastOutput output); var normal = point.Enter.CornerDir.Turn90(true); Line2.Intersect(VectorUtils.XZ(point.Position), VectorUtils.XZ(point.Position + point.Enter.CornerDir), VectorUtils.XZ(output.m_hitPos), VectorUtils.XZ(output.m_hitPos + normal), out float offsetChange, out _); point.Offset = (point.Offset + offsetChange).RoundToNearest(0.01f); }
private void RenderNotConnectLine(RenderManager.CameraInfo cameraInfo) { var bezier = new Bezier3() { a = SelectPoint.Position, b = SelectPoint.Direction, c = SelectPoint.Direction.Turn90(true), d = MouseWorldPosition, }; Line2.Intersect(VectorUtils.XZ(bezier.a), VectorUtils.XZ(bezier.a + bezier.b), VectorUtils.XZ(bezier.d), VectorUtils.XZ(bezier.d + bezier.c), out _, out float v); bezier.c = v >= 0 ? bezier.c : -bezier.c; NetSegment.CalculateMiddlePoints(bezier.a, bezier.b, bezier.d, bezier.c, true, true, out bezier.b, out bezier.c); RenderBezier(cameraInfo, MarkupColors.White, bezier); }
public static void CalculateMiddlePoints(Vector3 startPos, Vector3 startDir, Vector3 endPos, Vector3 endDir, bool smoothStart, bool smoothEnd, out Vector3 middlePos1, out Vector3 middlePos2) { if (IsStraight(startPos, startDir, endPos, endDir, out float distance)) { middlePos1 = startPos + startDir * (distance * ((!smoothStart) ? 0.15f : 0.276f)); middlePos2 = endPos + endDir * (distance * ((!smoothEnd) ? 0.15f : 0.276f)); } else { float num = startDir.x * endDir.x + startDir.z * endDir.z; if (num >= -0.999f && Line2.Intersect(VectorUtils.XZ(startPos), VectorUtils.XZ(startPos + startDir), VectorUtils.XZ(endPos), VectorUtils.XZ(endPos + endDir), out float u, out float v)) { u = Mathf.Clamp(u, distance * 0.1f, distance); v = Mathf.Clamp(v, distance * 0.1f, distance); float num2 = u + v; middlePos1 = startPos + startDir * Mathf.Min(u, num2 * 0.276f); middlePos2 = endPos + endDir * Mathf.Min(v, num2 * 0.276f); }
private Vector3 GetControlPoint(ushort segment) { Vector3 position = NodeBuffer[SegmentBuffer[segment].m_startNode].m_position; Vector3 startDirection = SegmentBuffer[segment].m_startDirection; Vector3 position2 = NodeBuffer[SegmentBuffer[segment].m_endNode].m_position; Vector3 endDirection = SegmentBuffer[segment].m_endDirection; if (!NetSegment.IsStraight(position, startDirection, position2, endDirection, out _)) { var num2 = (startDirection.x * endDirection.x) + (startDirection.z * endDirection.z); if (num2 >= -0.999f && Line2.Intersect(VectorUtils.XZ(position), VectorUtils.XZ(position + startDirection), VectorUtils.XZ(position2), VectorUtils.XZ(position2 + endDirection), out var d, out _)) { return(position + (startDirection * d)); } LogUtils.DoErrorLog("Warning! Invalid segment directions!"); } return((position + position2) / 2f); }
private Vector3 GetControlPoint(ushort segment) { Vector3 position = nodeBuffer[(int)segmentBuffer[(int)segment].m_startNode].m_position; Vector3 startDirection = segmentBuffer[(int)segment].m_startDirection; Vector3 position2 = nodeBuffer[(int)segmentBuffer[(int)segment].m_endNode].m_position; Vector3 endDirection = segmentBuffer[(int)segment].m_endDirection; if (!NetSegment.IsStraight(position, startDirection, position2, endDirection, out float num)) { float num2 = startDirection.x * endDirection.x + startDirection.z * endDirection.z; if (num2 >= -0.999f && Line2.Intersect(VectorUtils.XZ(position), VectorUtils.XZ(position + startDirection), VectorUtils.XZ(position2), VectorUtils.XZ(position2 + endDirection), out float d, out float num3)) { return(position + startDirection * d); } KlyteUtils.doErrorLog("Warning! Invalid segment directions!"); } return((position + position2) / 2f); }
private Vector3 GetControlPoint(ushort segment) { Vector3 startPos = nodeBuffer[segmentBuffer[segment].m_startNode].m_position; Vector3 startDir = segmentBuffer[segment].m_startDirection; Vector3 endPos = nodeBuffer[segmentBuffer[segment].m_endNode].m_position; Vector3 endDir = segmentBuffer[segment].m_endDirection; if (!NetSegment.IsStraight(startPos, startDir, endPos, endDir, out float num)) { float dot = startDir.x * endDir.x + startDir.z * endDir.z; if (dot >= -0.999f && Line2.Intersect(VectorUtils.XZ(startPos), VectorUtils.XZ(startPos + startDir), VectorUtils.XZ(endPos), VectorUtils.XZ(endPos + endDir), out float u, out float v)) { return(startPos + startDir * u); } else { DebugUtils.Warning("Invalid segment directions!"); } }
private void RenderNotConnectLine(RenderManager.CameraInfo cameraInfo) { var bezier = new Bezier3() { a = SelectPoint.Position, b = SelectPoint.Direction, c = SelectPoint.Direction.Turn90(true), d = NodeMarkupTool.Ray.GetRayPosition(Markup.Position.y, out _), }; Line2.Intersect(VectorUtils.XZ(bezier.a), VectorUtils.XZ(bezier.a + bezier.b), VectorUtils.XZ(bezier.d), VectorUtils.XZ(bezier.d + bezier.c), out _, out float v); bezier.c = v >= 0 ? bezier.c : -bezier.c; NetSegment.CalculateMiddlePoints(bezier.a, bezier.b, bezier.d, bezier.c, true, true, out bezier.b, out bezier.c); bezier.RenderBezier(new OverlayData(cameraInfo) { Color = Colors.Hover }); }
internal override bool Cross(Bounding selectBound, Entity entity) { Polyline polyline = entity as Polyline; if (polyline == null) { return(false); } Bounding polylineBound = polyline.Bounding; if (selectBound.Contains(polylineBound)) { return(true); } Rectangle2 selRect = new Rectangle2( new CADPoint(selectBound.left, selectBound.bottom), new CADPoint(selectBound.right, selectBound.top)); Line2 rectLine1 = new Line2(selRect.leftBottom, selRect.leftTop); Line2 rectLine2 = new Line2(selRect.leftTop, selRect.rightTop); Line2 rectLine3 = new Line2(selRect.rightTop, selRect.rightBottom); Line2 rectLine4 = new Line2(selRect.rightBottom, selRect.leftBottom); for (int i = 1; i < polyline.NumberOfVertices; ++i) { CADPoint spnt = polyline.GetPointAt(i - 1); CADPoint epnt = polyline.GetPointAt(i); Line2 line2 = new Line2(spnt, epnt); CADPoint intersection = new CADPoint(); if (Line2.Intersect(rectLine1, line2, ref intersection) || Line2.Intersect(rectLine2, line2, ref intersection) || Line2.Intersect(rectLine3, line2, ref intersection) || Line2.Intersect(rectLine4, line2, ref intersection)) { return(true); } } return(false); }
internal override bool Cross(Bounding selectBound, Entity entity) { Line line = entity as Line; if (line == null) { return(false); } Bounding lineBound = line.Bounding; if (selectBound.Contains(lineBound)) { return(true); } Rectangle2 selRect = new Rectangle2( new CADPoint(selectBound.left, selectBound.bottom), new CADPoint(selectBound.right, selectBound.top)); Line2 rectLine1 = new Line2(selRect.leftBottom, selRect.leftTop); Line2 rectLine2 = new Line2(selRect.leftTop, selRect.rightTop); Line2 rectLine3 = new Line2(selRect.rightTop, selRect.rightBottom); Line2 rectLine4 = new Line2(selRect.rightBottom, selRect.leftBottom); Line2 line2 = new Line2(line.startPoint, line.endPoint); CADPoint intersection = new CADPoint(); if (Line2.Intersect(rectLine1, line2, ref intersection) || Line2.Intersect(rectLine2, line2, ref intersection) || Line2.Intersect(rectLine3, line2, ref intersection) || Line2.Intersect(rectLine4, line2, ref intersection)) { return(true); } else { return(false); } }
private void RenderConnectLineOverlay(RenderManager.CameraInfo cameraInfo) { if (!IsSelectPoint) { return; } var bezier = new Bezier3(); Color color; if (IsHoverPoint) { var pointPair = new MarkupPointPair(SelectPoint, HoverPoint); color = EditMarkup.ExistConnection(pointPair) ? Color.red : Color.green; bezier.a = SelectPoint.Position; bezier.b = HoverPoint.Enter == SelectPoint.Enter ? HoverPoint.Position - SelectPoint.Position : SelectPoint.Direction; bezier.c = HoverPoint.Enter == SelectPoint.Enter ? SelectPoint.Position - HoverPoint.Position : HoverPoint.Direction; bezier.d = HoverPoint.Position; } else { color = Color.white; RaycastInput input = new RaycastInput(MouseRay, MouseRayLength); RayCast(input, out RaycastOutput output); bezier.a = SelectPoint.Position; bezier.b = SelectPoint.Direction; bezier.c = SelectPoint.Direction.Turn90(true); bezier.d = output.m_hitPos; Line2.Intersect(VectorUtils.XZ(bezier.a), VectorUtils.XZ(bezier.a + bezier.b), VectorUtils.XZ(bezier.d), VectorUtils.XZ(bezier.d + bezier.c), out _, out float v); bezier.c = v >= 0 ? bezier.c : -bezier.c; } NetSegment.CalculateMiddlePoints(bezier.a, bezier.b, bezier.d, bezier.c, true, true, out bezier.b, out bezier.c); RenderManager.OverlayEffect.DrawBezier(cameraInfo, color, bezier, 0.5f, 0f, 0f, -1f, 1280f, false, true); }
private void GetCircle3Points(Vector3[] points, int i, int j, int k, ref Vector3 centre, ref float radius) { var pos1 = (points[i] + points[j]) / 2; var pos2 = (points[j] + points[k]) / 2; var dir1 = (points[i] - points[j]).Turn90(true).normalized; var dir2 = (points[j] - points[k]).Turn90(true).normalized; Line2.Intersect(pos1.XZ(), (pos1 + dir1).XZ(), pos2.XZ(), (pos2 + dir2).XZ(), out float p, out _); var newCentre = pos1 + dir1 * p; var newRadius = (newCentre - points[i]).magnitude; if (newRadius >= radius) { return; } if (AllPointsInCircle(points, newCentre, newRadius, i, j, k)) { centre = newCentre; radius = newRadius; } }
private static void CreateZoneBlocksVanilla_Curve(NetInfo info, Randomizer randomizer, ref NetSegment segment) { var minHalfWidth = MIN_HALFWIDTH_DEFAULT; NetManager instance = Singleton <NetManager> .instance; Vector3 startPosition = instance.m_nodes.m_buffer[(int)segment.m_startNode].m_position; Vector3 endPosition = instance.m_nodes.m_buffer[(int)segment.m_endNode].m_position; Vector3 startDirection = segment.m_startDirection; Vector3 endDirection = segment.m_endDirection; float num = startDirection.x * endDirection.x + startDirection.z * endDirection.z; float num2 = Mathf.Max(minHalfWidth, info.m_halfWidth); float num3 = 32f; float num4 = VectorUtils.LengthXZ(endPosition - startPosition); bool flag2 = startDirection.x * endDirection.z - startDirection.z * endDirection.x > 0f; bool flag3 = num <-0.8f || num4> 50f; if (flag2) { num2 = -num2; num3 = -num3; } Vector3 vector = startPosition - new Vector3(startDirection.z, 0f, -startDirection.x) * num2; Vector3 vector2 = endPosition + new Vector3(endDirection.z, 0f, -endDirection.x) * num2; Vector3 vector3; Vector3 vector4; NetSegment.CalculateMiddlePoints(vector, startDirection, vector2, endDirection, true, true, out vector3, out vector4); if (flag3) { float num5 = num * 0.025f + 0.04f; float num6 = num * 0.025f + 0.06f; if (num < -0.9f) { num6 = num5; } Bezier3 bezier = new Bezier3(vector, vector3, vector4, vector2); vector = bezier.Position(num5); vector3 = bezier.Position(0.5f - num6); vector4 = bezier.Position(0.5f + num6); vector2 = bezier.Position(1f - num5); } else { Bezier3 bezier2 = new Bezier3(vector, vector3, vector4, vector2); vector3 = bezier2.Position(0.86f); vector = bezier2.Position(0.14f); } float num7; Vector3 vector5 = VectorUtils.NormalizeXZ(vector3 - vector, out num7); int num8 = Mathf.FloorToInt(num7 / 8f + 0.01f); float num9 = num7 * 0.5f + (float)(num8 - 8) * ((!flag2) ? -4f : 4f); if (num8 != 0) { float angle = (!flag2) ? Mathf.Atan2(vector5.x, -vector5.z) : Mathf.Atan2(-vector5.x, vector5.z); Vector3 position3 = vector + new Vector3(vector5.x * num9 - vector5.z * num3, 0f, vector5.z * num9 + vector5.x * num3); if (flag2) { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockStartRight, ref randomizer, position3, angle, num8, segment.m_buildIndex); } else { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockStartLeft, ref randomizer, position3, angle, num8, segment.m_buildIndex); } } if (flag3) { vector5 = VectorUtils.NormalizeXZ(vector2 - vector4, out num7); num8 = Mathf.FloorToInt(num7 / 8f + 0.01f); num9 = num7 * 0.5f + (float)(num8 - 8) * ((!flag2) ? -4f : 4f); if (num8 != 0) { float angle2 = (!flag2) ? Mathf.Atan2(vector5.x, -vector5.z) : Mathf.Atan2(-vector5.x, vector5.z); Vector3 position4 = vector4 + new Vector3(vector5.x * num9 - vector5.z * num3, 0f, vector5.z * num9 + vector5.x * num3); if (flag2) { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockEndRight, ref randomizer, position4, angle2, num8, segment.m_buildIndex + 1u); } else { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockEndLeft, ref randomizer, position4, angle2, num8, segment.m_buildIndex + 1u); } } } Vector3 vector6 = startPosition + new Vector3(startDirection.z, 0f, -startDirection.x) * num2; Vector3 vector7 = endPosition - new Vector3(endDirection.z, 0f, -endDirection.x) * num2; Vector3 b; Vector3 c; NetSegment.CalculateMiddlePoints(vector6, startDirection, vector7, endDirection, true, true, out b, out c); Bezier3 bezier3 = new Bezier3(vector6, b, c, vector7); Vector3 vector8 = bezier3.Position(0.5f); Vector3 vector9 = bezier3.Position(0.25f); vector9 = Line2.Offset(VectorUtils.XZ(vector6), VectorUtils.XZ(vector8), VectorUtils.XZ(vector9)); Vector3 vector10 = bezier3.Position(0.75f); vector10 = Line2.Offset(VectorUtils.XZ(vector7), VectorUtils.XZ(vector8), VectorUtils.XZ(vector10)); Vector3 vector11 = vector6; Vector3 a = vector7; float d; float num10; if (Line2.Intersect(VectorUtils.XZ(startPosition), VectorUtils.XZ(vector6), VectorUtils.XZ(vector11 - vector9), VectorUtils.XZ(vector8 - vector9), out d, out num10)) { vector6 = startPosition + (vector6 - startPosition) * d; } if (Line2.Intersect(VectorUtils.XZ(endPosition), VectorUtils.XZ(vector7), VectorUtils.XZ(a - vector10), VectorUtils.XZ(vector8 - vector10), out d, out num10)) { vector7 = endPosition + (vector7 - endPosition) * d; } if (Line2.Intersect(VectorUtils.XZ(vector11 - vector9), VectorUtils.XZ(vector8 - vector9), VectorUtils.XZ(a - vector10), VectorUtils.XZ(vector8 - vector10), out d, out num10)) { vector8 = vector11 - vector9 + (vector8 - vector11) * d; } float num11; Vector3 vector12 = VectorUtils.NormalizeXZ(vector8 - vector6, out num11); int num12 = Mathf.FloorToInt(num11 / 8f + 0.01f); float num13 = num11 * 0.5f + (float)(num12 - 8) * ((!flag2) ? 4f : -4f); if (num12 != 0) { float angle3 = (!flag2) ? Mathf.Atan2(-vector12.x, vector12.z) : Mathf.Atan2(vector12.x, -vector12.z); Vector3 position5 = vector6 + new Vector3(vector12.x * num13 + vector12.z * num3, 0f, vector12.z * num13 - vector12.x * num3); if (flag2) { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockStartLeft, ref randomizer, position5, angle3, num12, segment.m_buildIndex); } else { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockStartRight, ref randomizer, position5, angle3, num12, segment.m_buildIndex); } } vector12 = VectorUtils.NormalizeXZ(vector7 - vector8, out num11); num12 = Mathf.FloorToInt(num11 / 8f + 0.01f); num13 = num11 * 0.5f + (float)(num12 - 8) * ((!flag2) ? 4f : -4f); if (num12 != 0) { float angle4 = (!flag2) ? Mathf.Atan2(-vector12.x, vector12.z) : Mathf.Atan2(vector12.x, -vector12.z); Vector3 position6 = vector8 + new Vector3(vector12.x * num13 + vector12.z * num3, 0f, vector12.z * num13 - vector12.x * num3); if (flag2) { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockEndLeft, ref randomizer, position6, angle4, num12, segment.m_buildIndex + 1u); } else { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockEndRight, ref randomizer, position6, angle4, num12, segment.m_buildIndex + 1u); } } }
/// <summary> /// Generic n-gon slicer. If the nodes in V do not represent a valid, convex NGon /// then the result will not be reliable. /// </summary> /// <param name="V">Corners of NGon</param> /// <param name="line">The line to slice with</param> /// <param name="side">Side of NGon to keep (with respect to line)</param> /// <returns>Result. List may share Node instances with V</returns> public static List <Node2> SliceConvexNGon( List <Node2> V, Line2 line, Side2 side, ref bool changed) { changed = false; List <Node2> node2List1; if (V.Count < 2) { node2List1 = V; } else { List <Node2> node2List2 = new List <Node2>(V.Count + 2); int num1 = 0; Side2 side2 = Side2.Coincident; int num2 = V.Count - 1; for (int index1 = 0; index1 <= num2; ++index1) { if (side2 == Side2.Coincident) { side2 = Line2.Side(line, V[index1]); if (side2 != side) { changed = true; } } int index2 = index1 + 1; if (index2 == V.Count) { index2 = 0; } Line2 A = new Line2(V[index1], V[index2]); double t = 0.0; switch (Line2.Intersect(A, line, ref t)) { case LineX.None: if (side2 == side) { node2List2.Add(V[index1]); break; } break; case LineX.Parallel: if (side2 == side) { node2List2.Add(V[index1]); break; } break; case LineX.Coincident: changed = false; node2List1 = V; goto label_28; case LineX.Point: Node2 node2 = A.PointAt(t); if (node2.IsCoincident(V[index1])) { node2List2.Add(V[index1]); side2 = Side2.Coincident; ++num1; changed = true; break; } if (node2.IsCoincident(V[index2])) { if (side2 == side) { node2List2.Add(V[index1]); break; } break; } if (t < 0.0 || t > 1.0) { if (side2 == side) { node2List2.Add(V[index1]); break; } break; } if (side2 == side) { node2List2.Add(V[index1]); } node2List2.Add(node2); side2 = Side2.Coincident; ++num1; changed = true; break; } } node2List1 = node2List2; } label_28: return(node2List1); }
private Vector3 SnapSegmentDirections(ushort segment, Vector3 newPosition, Vector3 moveDelta) { NetManager netManager = NetManager.instance; NetSegment[] segmentBuffer = netManager.m_segments.m_buffer; NetNode[] nodeBuffer = netManager.m_nodes.m_buffer; float minSqDistance = segmentBuffer[segment].Info.GetMinNodeDistance() / 2f; minSqDistance *= minSqDistance; ushort startNode = segmentBuffer[segment].m_startNode; ushort endNode = segmentBuffer[segment].m_endNode; Vector3 startPos = nodeBuffer[segmentBuffer[segment].m_startNode].m_position; Vector3 endPos = nodeBuffer[segmentBuffer[segment].m_endNode].m_position; Vector3 newMoveDelta = moveDelta; float distanceSq = minSqDistance; bool snap = false; // Snap to tangent intersection for (int i = 0; i < 8; i++) { ushort segmentA = nodeBuffer[startNode].GetSegment(i); if (segmentA != 0 && segmentA != segment) { for (int j = 0; j < 8; j++) { ushort segmentB = nodeBuffer[endNode].GetSegment(j); if (segmentB != 0 && segmentB != segment) { Vector3 startDir = segmentBuffer[segmentA].m_startNode == startNode ? segmentBuffer[segmentA].m_startDirection : segmentBuffer[segmentA].m_endDirection; Vector3 endDir = segmentBuffer[segmentB].m_startNode == endNode ? segmentBuffer[segmentB].m_startDirection : segmentBuffer[segmentB].m_endDirection; if (!NetSegment.IsStraight(startPos, startDir, endPos, endDir, out float num)) { float dot = startDir.x * endDir.x + startDir.z * endDir.z; if (dot >= -0.999f && Line2.Intersect(VectorUtils.XZ(startPos), VectorUtils.XZ(startPos + startDir), VectorUtils.XZ(endPos), VectorUtils.XZ(endPos + endDir), out float u, out float v)) { snap = TrySnapping(startPos + startDir * u, newPosition, minSqDistance, ref distanceSq, moveDelta, ref newMoveDelta) || snap; } } } } } } if (!snap) { // Snap to start tangent for (int i = 0; i < 8; i++) { ushort segmentA = nodeBuffer[startNode].GetSegment(i); if (segmentA != 0 && segmentA != segment) { Vector3 startDir = segmentBuffer[segmentA].m_startNode == startNode ? segmentBuffer[segmentA].m_startDirection : segmentBuffer[segmentA].m_endDirection; Vector3 offset = Line2.Offset(startDir, startPos - newPosition); offset = newPosition + offset - startPos; float num = offset.x * startDir.x + offset.z * startDir.z; TrySnapping(startPos + startDir * num, newPosition, minSqDistance, ref distanceSq, moveDelta, ref newMoveDelta); } } // Snap to end tangent for (int i = 0; i < 8; i++) { ushort segmentB = nodeBuffer[endNode].GetSegment(i); if (segmentB != 0 && segmentB != segment) { Vector3 endDir = segmentBuffer[segmentB].m_startNode == endNode ? segmentBuffer[segmentB].m_startDirection : segmentBuffer[segmentB].m_endDirection; Vector3 offset = Line2.Offset(endDir, endPos - newPosition); offset = newPosition + offset - endPos; float num = offset.x * endDir.x + offset.z * endDir.z; TrySnapping(endPos + endDir * num, newPosition, minSqDistance, ref distanceSq, moveDelta, ref newMoveDelta); } } } // Snap straight TrySnapping((startPos + endPos) / 2f, newPosition, minSqDistance, ref distanceSq, moveDelta, ref newMoveDelta); return(newMoveDelta); }
/// <summary> /// Create curved zone blocks. /// </summary> /// <param name="info">Network prefab</param> /// <param name="randomizer">Randomizer</param> /// <param name="segment">Network segment</param> private static void CurvedZoneBlocks(NetInfo info, Randomizer randomizer, ref NetSegment segment) { #pragma warning disable IDE0018 // Inline variable declaration // TODO: Basically game code with some NExT2 modifications. Could do with a good refactor, and possible replacement with Transpiler. var minHalfWidth = MIN_HALFWIDTH_TINY_CURVE; NetManager instance = Singleton <NetManager> .instance; Vector3 startPosition = instance.m_nodes.m_buffer[(int)segment.m_startNode].m_position; Vector3 endPosition = instance.m_nodes.m_buffer[(int)segment.m_endNode].m_position; Vector3 startDirection = segment.m_startDirection; Vector3 endDirection = segment.m_endDirection; float num = startDirection.x * endDirection.x + startDirection.z * endDirection.z; float num2 = Mathf.Max(minHalfWidth, info.m_halfWidth); // minHalfWidth here. float num3 = 32f; int distance = Mathf.RoundToInt(num2); float num4 = VectorUtils.LengthXZ(endPosition - startPosition); bool flag2 = startDirection.x * endDirection.z - startDirection.z * endDirection.x > 0f; bool flag3 = num <-0.8f || num4> 50f; if (flag2) { num2 = -num2; num3 = -num3; } Vector3 vector = startPosition - new Vector3(startDirection.z, 0f, -startDirection.x) * num2; Vector3 vector2 = endPosition + new Vector3(endDirection.z, 0f, -endDirection.x) * num2; Vector3 vector3; Vector3 vector4; NetSegment.CalculateMiddlePoints(vector, startDirection, vector2, endDirection, true, true, out vector3, out vector4); if (flag3) { float num5 = num * 0.025f + 0.04f; float num6 = num * 0.025f + 0.06f; if (num < -0.9f) { num6 = num5; } Bezier3 bezier = new Bezier3(vector, vector3, vector4, vector2); vector = bezier.Position(num5); vector3 = bezier.Position(0.5f - num6); vector4 = bezier.Position(0.5f + num6); vector2 = bezier.Position(1f - num5); } else { Bezier3 bezier2 = new Bezier3(vector, vector3, vector4, vector2); vector3 = bezier2.Position(0.86f); vector = bezier2.Position(0.14f); } float num7; Vector3 vector5 = VectorUtils.NormalizeXZ(vector3 - vector, out num7); int num8 = Mathf.FloorToInt(num7 / 8f + 0.01f); float num9 = num7 * 0.5f + (float)(num8 - 8) * ((!flag2) ? -4f : 4f); if (num8 != 0) { float angle = (!flag2) ? Mathf.Atan2(vector5.x, -vector5.z) : Mathf.Atan2(-vector5.x, vector5.z); Vector3 position3 = vector + new Vector3(vector5.x * num9 - vector5.z * num3, 0f, vector5.z * num9 + vector5.x * num3); if (flag2) { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockStartRight, ref randomizer, position3, angle, num8, distance, segment.m_buildIndex); } else { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockStartLeft, ref randomizer, position3, angle, num8, distance, segment.m_buildIndex); } } if (flag3) { vector5 = VectorUtils.NormalizeXZ(vector2 - vector4, out num7); num8 = Mathf.FloorToInt(num7 / 8f + 0.01f); num9 = num7 * 0.5f + (float)(num8 - 8) * ((!flag2) ? -4f : 4f); if (num8 != 0) { float angle2 = (!flag2) ? Mathf.Atan2(vector5.x, -vector5.z) : Mathf.Atan2(-vector5.x, vector5.z); Vector3 position4 = vector4 + new Vector3(vector5.x * num9 - vector5.z * num3, 0f, vector5.z * num9 + vector5.x * num3); if (flag2) { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockEndRight, ref randomizer, position4, angle2, num8, distance, segment.m_buildIndex + 1u); } else { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockEndLeft, ref randomizer, position4, angle2, num8, distance, segment.m_buildIndex + 1u); } } } Vector3 vector6 = startPosition + new Vector3(startDirection.z, 0f, -startDirection.x) * num2; Vector3 vector7 = endPosition - new Vector3(endDirection.z, 0f, -endDirection.x) * num2; Vector3 b; Vector3 c; NetSegment.CalculateMiddlePoints(vector6, startDirection, vector7, endDirection, true, true, out b, out c); Bezier3 bezier3 = new Bezier3(vector6, b, c, vector7); Vector3 vector8 = bezier3.Position(0.5f); Vector3 vector9 = bezier3.Position(0.25f); vector9 = Line2.Offset(VectorUtils.XZ(vector6), VectorUtils.XZ(vector8), VectorUtils.XZ(vector9)); Vector3 vector10 = bezier3.Position(0.75f); vector10 = Line2.Offset(VectorUtils.XZ(vector7), VectorUtils.XZ(vector8), VectorUtils.XZ(vector10)); Vector3 vector11 = vector6; Vector3 a = vector7; float d; #pragma warning disable IDE0059 // Unnecessary assignment of a value float num10; if (Line2.Intersect(VectorUtils.XZ(startPosition), VectorUtils.XZ(vector6), VectorUtils.XZ(vector11 - vector9), VectorUtils.XZ(vector8 - vector9), out d, out num10)) { vector6 = startPosition + (vector6 - startPosition) * d; } if (Line2.Intersect(VectorUtils.XZ(endPosition), VectorUtils.XZ(vector7), VectorUtils.XZ(a - vector10), VectorUtils.XZ(vector8 - vector10), out d, out num10)) { vector7 = endPosition + (vector7 - endPosition) * d; } if (Line2.Intersect(VectorUtils.XZ(vector11 - vector9), VectorUtils.XZ(vector8 - vector9), VectorUtils.XZ(a - vector10), VectorUtils.XZ(vector8 - vector10), out d, out num10)) #pragma warning restore IDE0059 // Unnecessary assignment of a value { vector8 = vector11 - vector9 + (vector8 - vector11) * d; } float num11; Vector3 vector12 = VectorUtils.NormalizeXZ(vector8 - vector6, out num11); int num12 = Mathf.FloorToInt(num11 / 8f + 0.01f); float num13 = num11 * 0.5f + (float)(num12 - 8) * ((!flag2) ? 4f : -4f); if (num12 != 0) { float angle3 = (!flag2) ? Mathf.Atan2(-vector12.x, vector12.z) : Mathf.Atan2(vector12.x, -vector12.z); Vector3 position5 = vector6 + new Vector3(vector12.x * num13 + vector12.z * num3, 0f, vector12.z * num13 - vector12.x * num3); if (flag2) { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockStartLeft, ref randomizer, position5, angle3, num12, distance, segment.m_buildIndex); } else { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockStartRight, ref randomizer, position5, angle3, num12, distance, segment.m_buildIndex); } } vector12 = VectorUtils.NormalizeXZ(vector7 - vector8, out num11); num12 = Mathf.FloorToInt(num11 / 8f + 0.01f); num13 = num11 * 0.5f + (float)(num12 - 8) * ((!flag2) ? 4f : -4f); if (num12 != 0) { float angle4 = (!flag2) ? Mathf.Atan2(-vector12.x, vector12.z) : Mathf.Atan2(vector12.x, -vector12.z); Vector3 position6 = vector8 + new Vector3(vector12.x * num13 + vector12.z * num3, 0f, vector12.z * num13 - vector12.x * num3); if (flag2) { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockEndLeft, ref randomizer, position6, angle4, num12, distance, segment.m_buildIndex + 1u); } else { Singleton <ZoneManager> .instance.CreateBlock( out segment.m_blockEndRight, ref randomizer, position6, angle4, num12, distance, segment.m_buildIndex + 1u); } } #pragma warning restore IDE0018 // Inline variable declaration }
private void CreateZoneBlocks(ushort segment, ref NetSegment data) { NetManager instance = Singleton <NetManager> .instance; Randomizer randomizer = new Randomizer((int)segment); Vector3 position = instance.m_nodes.m_buffer[(int)data.m_startNode].m_position; Vector3 position2 = instance.m_nodes.m_buffer[(int)data.m_endNode].m_position; Vector3 startDirection = data.m_startDirection; Vector3 endDirection = data.m_endDirection; float num = startDirection.x * endDirection.x + startDirection.z * endDirection.z; bool flag = !NetSegment.IsStraight(position, startDirection, position2, endDirection); float num2 = Mathf.Max(8f, this.m_info.m_halfWidth); float num3 = 32f; if (flag) { float num4 = VectorUtils.LengthXZ(position2 - position); bool flag2 = startDirection.x * endDirection.z - startDirection.z * endDirection.x > 0f; bool flag3 = num <-0.8f || num4> 50f; if (flag2) { num2 = -num2; num3 = -num3; } Vector3 vector = position - new Vector3(startDirection.z, 0f, -startDirection.x) * num2; Vector3 vector2 = position2 + new Vector3(endDirection.z, 0f, -endDirection.x) * num2; Vector3 vector3; Vector3 vector4; NetSegment.CalculateMiddlePoints(vector, startDirection, vector2, endDirection, true, true, out vector3, out vector4); if (flag3) { float num5 = num * 0.025f + 0.04f; float num6 = num * 0.025f + 0.06f; if (num < -0.9f) { num6 = num5; } Bezier3 bezier = new Bezier3(vector, vector3, vector4, vector2); vector = bezier.Position(num5); vector3 = bezier.Position(0.5f - num6); vector4 = bezier.Position(0.5f + num6); vector2 = bezier.Position(1f - num5); } else { Bezier3 bezier2 = new Bezier3(vector, vector3, vector4, vector2); vector3 = bezier2.Position(0.86f); vector = bezier2.Position(0.14f); } float num7; Vector3 vector5 = VectorUtils.NormalizeXZ(vector3 - vector, out num7); int num8 = Mathf.FloorToInt(num7 / 8f + 0.01f); float num9 = num7 * 0.5f + (float)(num8 - 8) * ((!flag2) ? -4f : 4f); if (num8 != 0) { float angle = (!flag2) ? Mathf.Atan2(vector5.x, -vector5.z) : Mathf.Atan2(-vector5.x, vector5.z); Vector3 position3 = vector + new Vector3(vector5.x * num9 - vector5.z * num3, 0f, vector5.z * num9 + vector5.x * num3); if (flag2) { Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockStartRight, ref randomizer, position3, angle, num8, data.m_buildIndex); } else { Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockStartLeft, ref randomizer, position3, angle, num8, data.m_buildIndex); } } if (flag3) { vector5 = VectorUtils.NormalizeXZ(vector2 - vector4, out num7); num8 = Mathf.FloorToInt(num7 / 8f + 0.01f); num9 = num7 * 0.5f + (float)(num8 - 8) * ((!flag2) ? -4f : 4f); if (num8 != 0) { float angle2 = (!flag2) ? Mathf.Atan2(vector5.x, -vector5.z) : Mathf.Atan2(-vector5.x, vector5.z); Vector3 position4 = vector4 + new Vector3(vector5.x * num9 - vector5.z * num3, 0f, vector5.z * num9 + vector5.x * num3); if (flag2) { Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockEndRight, ref randomizer, position4, angle2, num8, data.m_buildIndex + 1u); } else { Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockEndLeft, ref randomizer, position4, angle2, num8, data.m_buildIndex + 1u); } } } Vector3 vector6 = position + new Vector3(startDirection.z, 0f, -startDirection.x) * num2; Vector3 vector7 = position2 - new Vector3(endDirection.z, 0f, -endDirection.x) * num2; Vector3 b; Vector3 c; NetSegment.CalculateMiddlePoints(vector6, startDirection, vector7, endDirection, true, true, out b, out c); Bezier3 bezier3 = new Bezier3(vector6, b, c, vector7); Vector3 vector8 = bezier3.Position(0.5f); Vector3 vector9 = bezier3.Position(0.25f); vector9 = Line2.Offset(VectorUtils.XZ(vector6), VectorUtils.XZ(vector8), VectorUtils.XZ(vector9)); Vector3 vector10 = bezier3.Position(0.75f); vector10 = Line2.Offset(VectorUtils.XZ(vector7), VectorUtils.XZ(vector8), VectorUtils.XZ(vector10)); Vector3 vector11 = vector6; Vector3 a = vector7; float d; float num10; if (Line2.Intersect(VectorUtils.XZ(position), VectorUtils.XZ(vector6), VectorUtils.XZ(vector11 - vector9), VectorUtils.XZ(vector8 - vector9), out d, out num10)) { vector6 = position + (vector6 - position) * d; } if (Line2.Intersect(VectorUtils.XZ(position2), VectorUtils.XZ(vector7), VectorUtils.XZ(a - vector10), VectorUtils.XZ(vector8 - vector10), out d, out num10)) { vector7 = position2 + (vector7 - position2) * d; } if (Line2.Intersect(VectorUtils.XZ(vector11 - vector9), VectorUtils.XZ(vector8 - vector9), VectorUtils.XZ(a - vector10), VectorUtils.XZ(vector8 - vector10), out d, out num10)) { vector8 = vector11 - vector9 + (vector8 - vector11) * d; } float num11; Vector3 vector12 = VectorUtils.NormalizeXZ(vector8 - vector6, out num11); int num12 = Mathf.FloorToInt(num11 / 8f + 0.01f); float num13 = num11 * 0.5f + (float)(num12 - 8) * ((!flag2) ? 4f : -4f); if (num12 != 0) { float angle3 = (!flag2) ? Mathf.Atan2(-vector12.x, vector12.z) : Mathf.Atan2(vector12.x, -vector12.z); Vector3 position5 = vector6 + new Vector3(vector12.x * num13 + vector12.z * num3, 0f, vector12.z * num13 - vector12.x * num3); if (flag2) { Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockStartLeft, ref randomizer, position5, angle3, num12, data.m_buildIndex); } else { Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockStartRight, ref randomizer, position5, angle3, num12, data.m_buildIndex); } } vector12 = VectorUtils.NormalizeXZ(vector7 - vector8, out num11); num12 = Mathf.FloorToInt(num11 / 8f + 0.01f); num13 = num11 * 0.5f + (float)(num12 - 8) * ((!flag2) ? 4f : -4f); if (num12 != 0) { float angle4 = (!flag2) ? Mathf.Atan2(-vector12.x, vector12.z) : Mathf.Atan2(vector12.x, -vector12.z); Vector3 position6 = vector8 + new Vector3(vector12.x * num13 + vector12.z * num3, 0f, vector12.z * num13 - vector12.x * num3); if (flag2) { Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockEndLeft, ref randomizer, position6, angle4, num12, data.m_buildIndex + 1u); } else { Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockEndRight, ref randomizer, position6, angle4, num12, data.m_buildIndex + 1u); } } } else { num2 += num3; Vector2 vector13 = new Vector2(position2.x - position.x, position2.z - position.z); float magnitude = vector13.magnitude; int num14 = Mathf.FloorToInt(magnitude / 8f + 0.1f); int num15 = (num14 <= 8) ? num14 : (num14 + 1 >> 1); int num16 = (num14 <= 8) ? 0 : (num14 >> 1); if (num15 > 0) { float num17 = Mathf.Atan2(startDirection.x, -startDirection.z); Vector3 position7 = position + new Vector3(startDirection.x * 32f - startDirection.z * num2, 0f, startDirection.z * 32f + startDirection.x * num2); Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockStartLeft, ref randomizer, position7, num17, num15, data.m_buildIndex); position7 = position + new Vector3(startDirection.x * (float)(num15 - 4) * 8f + startDirection.z * num2, 0f, startDirection.z * (float)(num15 - 4) * 8f - startDirection.x * num2); Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockStartRight, ref randomizer, position7, num17 + 3.14159274f, num15, data.m_buildIndex); } if (num16 > 0) { float num18 = magnitude - (float)num14 * 8f; float num19 = Mathf.Atan2(endDirection.x, -endDirection.z); Vector3 position8 = position2 + new Vector3(endDirection.x * (32f + num18) - endDirection.z * num2, 0f, endDirection.z * (32f + num18) + endDirection.x * num2); Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockEndLeft, ref randomizer, position8, num19, num16, data.m_buildIndex + 1u); position8 = position2 + new Vector3(endDirection.x * ((float)(num16 - 4) * 8f + num18) + endDirection.z * num2, 0f, endDirection.z * ((float)(num16 - 4) * 8f + num18) - endDirection.x * num2); Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockEndRight, ref randomizer, position8, num19 + 3.14159274f, num16, data.m_buildIndex + 1u); } } }
/* Detoured method. We save a list of all the segment ids (and ids of their lanes and nodes as well) to m_pendingSegments * We will use it a few moments later when the OnAssetSaved method is called * See line 408 */ public static void SavePaths(BuildingInfo info, ushort buildingID, ref Building data) { Debug.Log("SavePaths TMPE detour"); // List <IdentificationTool.AssetSegment> SavedSegments = new List <IdentificationTool.AssetSegment>(); // ns end FastList <BuildingInfo.PathInfo> fastList = new FastList <BuildingInfo.PathInfo>(); List <ushort> list = new List <ushort>(); List <ushort> list2 = new List <ushort>(); for (ushort num = 1; num < 49152; num += 1) { if (Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)num].m_flags != Building.Flags.None) { list.AddRange(BuildingDecoration.GetBuildingSegments(ref Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)num])); list2.Add(num); } } NetManager instance = Singleton <NetManager> .instance; for (int i = 0; i < 36864; i++) { if ((instance.m_segments.m_buffer[i].m_flags & (NetSegment.Flags.Created | NetSegment.Flags.Deleted)) == NetSegment.Flags.Created) { if (!list.Contains((ushort)i)) { NetInfo info2 = instance.m_segments.m_buffer[i].Info; ushort startNode = instance.m_segments.m_buffer[i].m_startNode; ushort endNode = instance.m_segments.m_buffer[i].m_endNode; Vector3 position = instance.m_nodes.m_buffer[(int)startNode].m_position; Vector3 position2 = instance.m_nodes.m_buffer[(int)endNode].m_position; Vector3 startDirection = instance.m_segments.m_buffer[i].m_startDirection; Vector3 endDirection = instance.m_segments.m_buffer[i].m_endDirection; Vector3 a; float num2; float num3; if (NetSegment.IsStraight(position, startDirection, position2, endDirection)) { a = (position + position2) * 0.5f; } else if (Line2.Intersect(VectorUtils.XZ(position), VectorUtils.XZ(position + startDirection), VectorUtils.XZ(position2), VectorUtils.XZ(position2 + endDirection), out num2, out num3)) { float minNodeDistance = info2.GetMinNodeDistance(); num2 = Mathf.Max(minNodeDistance, num2); num3 = Mathf.Max(minNodeDistance, num3); a = (position + startDirection * num2 + position2 + endDirection * num3) * 0.5f; } else { a = (position + position2) * 0.5f; } BuildingInfo.PathInfo pathInfo = new BuildingInfo.PathInfo(); pathInfo.m_netInfo = info2; pathInfo.m_finalNetInfo = info2; pathInfo.m_nodes = new Vector3[2]; pathInfo.m_nodes[0] = position - data.m_position; pathInfo.m_nodes[0].z = -pathInfo.m_nodes[0].z; pathInfo.m_nodes[1] = position2 - data.m_position; pathInfo.m_nodes[1].z = -pathInfo.m_nodes[1].z; pathInfo.m_curveTargets = new Vector3[1]; pathInfo.m_curveTargets[0] = a - data.m_position; pathInfo.m_curveTargets[0].z = -pathInfo.m_curveTargets[0].z; pathInfo.m_forbidLaneConnection = new bool[2]; pathInfo.m_forbidLaneConnection[0] = ((instance.m_nodes.m_buffer[(int)startNode].m_flags & NetNode.Flags.ForbidLaneConnection) != NetNode.Flags.None); pathInfo.m_forbidLaneConnection[1] = ((instance.m_nodes.m_buffer[(int)endNode].m_flags & NetNode.Flags.ForbidLaneConnection) != NetNode.Flags.None); pathInfo.m_trafficLights = new BuildingInfo.TrafficLights[2]; pathInfo.m_trafficLights[0] = /*BuildingDecoration.*/ FlagsToTrafficLights(instance.m_nodes.m_buffer[(int)startNode].m_flags); pathInfo.m_trafficLights[1] = /*BuildingDecoration.*/ FlagsToTrafficLights(instance.m_nodes.m_buffer[(int)endNode].m_flags); pathInfo.m_yieldSigns = new bool[2]; pathInfo.m_yieldSigns[0] = ((instance.m_segments.m_buffer[i].m_flags & NetSegment.Flags.YieldStart) != NetSegment.Flags.None); pathInfo.m_yieldSigns[1] = ((instance.m_segments.m_buffer[i].m_flags & NetSegment.Flags.YieldEnd) != NetSegment.Flags.None); if (info.m_placementMode == BuildingInfo.PlacementMode.Roadside && (position.z > (float)info.m_cellLength * 4f + 8f || position2.z > (float)info.m_cellLength * 4f + 8f)) { pathInfo.m_maxSnapDistance = 7.5f; } else { pathInfo.m_maxSnapDistance = 0.1f; } pathInfo.m_invertSegments = ((instance.m_segments.m_buffer[i].m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None); fastList.Add(pathInfo); SavedSegments.Add(new IdentificationTool.AssetSegment((ushort)i)); // ns } } } for (int j = 0; j < 32768; j++) { if ((instance.m_nodes.m_buffer[j].m_flags & (NetNode.Flags.Created | NetNode.Flags.Deleted)) == NetNode.Flags.Created && instance.m_nodes.m_buffer[j].CountSegments() == 0) { bool flag = false; foreach (ushort num4 in list2) { if (Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)num4].ContainsNode((ushort)j)) { flag = true; break; } } if (!flag) { NetInfo info3 = instance.m_nodes.m_buffer[j].Info; Vector3 position3 = instance.m_nodes.m_buffer[j].m_position; BuildingInfo.PathInfo pathInfo2 = new BuildingInfo.PathInfo(); pathInfo2.m_netInfo = info3; pathInfo2.m_finalNetInfo = info3; pathInfo2.m_nodes = new Vector3[1]; pathInfo2.m_nodes[0] = position3 - data.m_position; pathInfo2.m_nodes[0].z = -pathInfo2.m_nodes[0].z; pathInfo2.m_curveTargets = new Vector3[0]; pathInfo2.m_forbidLaneConnection = new bool[1]; pathInfo2.m_forbidLaneConnection[0] = ((instance.m_nodes.m_buffer[j].m_flags & NetNode.Flags.ForbidLaneConnection) != NetNode.Flags.None); pathInfo2.m_trafficLights = new BuildingInfo.TrafficLights[1]; pathInfo2.m_trafficLights[0] = /*BuildingDecoration.*/ FlagsToTrafficLights(instance.m_nodes.m_buffer[j].m_flags); pathInfo2.m_yieldSigns = new bool[0]; pathInfo2.m_maxSnapDistance = 0.1f; pathInfo2.m_invertSegments = false; fastList.Add(pathInfo2); } } } info.m_paths = fastList.ToArray(); // ns: if (SavedSegments.Count > 0) { m_pendingSegments = SavedSegments; } }
#pragma warning disable 108,114 public virtual ToolBase.ToolErrors CheckBuildPosition(bool test, bool visualize, bool overlay, bool autofix, #pragma warning restore 108,114 ref NetTool.ControlPoint startPoint, ref NetTool.ControlPoint middlePoint, ref NetTool.ControlPoint endPoint, out BuildingInfo ownerBuilding, out Vector3 ownerPosition, out Vector3 ownerDirection, out int productionRate) { ownerBuilding = null; ownerPosition = Vector3.zero; ownerDirection = Vector3.forward; productionRate = 0; ToolBase.ToolErrors toolErrors = ToolBase.ToolErrors.None; if (test) { ushort num = middlePoint.m_segment; if (startPoint.m_segment == num || endPoint.m_segment == num) { num = 0; } if (num != 0 && Singleton <NetManager> .instance.m_segments.m_buffer[(int)num].Info == this.m_info) { if (ZoneBlocksOffset.Mode == ZoneBlocksOffsetMode.Default) { toolErrors |= ToolBase.ToolErrors.CannotUpgrade; } else { // Do nothing } } } if (autofix && this.m_info.m_enableBendingSegments) { Vector3 vector = middlePoint.m_direction; Vector3 vector2 = -endPoint.m_direction; Vector3 vector3 = middlePoint.m_position; float minNodeDistance = this.m_info.GetMinNodeDistance(); for (int i = 0; i < 3; i++) { bool flag = false; bool flag2 = false; if (startPoint.m_node != 0) { if (ForceValidDirection(this.m_info, ref vector, startPoint.m_node, ref Singleton <NetManager> .instance.m_nodes.m_buffer[(int)startPoint.m_node])) { flag = true; } } else if (startPoint.m_segment != 0 && ForceValidDirection(this.m_info, startPoint.m_position, ref vector, startPoint.m_segment, ref Singleton <NetManager> .instance.m_segments.m_buffer[(int)startPoint.m_segment])) { flag = true; } if (flag) { Line2 line = Line2.XZ(startPoint.m_position, startPoint.m_position + vector); Line2 line2 = Line2.XZ(endPoint.m_position, endPoint.m_position + vector2); bool flag3 = true; float num2; float num3; if (line.Intersect(line2, out num2, out num3) && num2 >= minNodeDistance && num3 >= minNodeDistance) { vector3 = startPoint.m_position + vector * num2; flag3 = false; } if (flag3) { Vector3 vector4 = endPoint.m_position - startPoint.m_position; Vector3 vector5 = vector; vector4.y = 0f; vector5.y = 0f; float num4 = Vector3.SqrMagnitude(vector4); vector4 = Vector3.Normalize(vector4); float num5 = Mathf.Min(1.17809725f, Mathf.Acos(Vector3.Dot(vector4, vector5))); float d = Mathf.Sqrt(0.5f * num4 / Mathf.Max(0.001f, 1f - Mathf.Cos(3.14159274f - 2f * num5))); vector3 = startPoint.m_position + vector5 * d; vector2 = vector3 - endPoint.m_position; vector2.y = 0f; vector2.Normalize(); } } if (endPoint.m_node != 0) { if (ForceValidDirection(this.m_info, ref vector2, endPoint.m_node, ref Singleton <NetManager> .instance.m_nodes.m_buffer[(int)endPoint.m_node])) { flag2 = true; } } else if (endPoint.m_segment != 0 && ForceValidDirection(this.m_info, endPoint.m_position, ref vector2, endPoint.m_segment, ref Singleton <NetManager> .instance.m_segments.m_buffer[(int)endPoint.m_segment])) { flag2 = true; } if (flag2) { Line2 line3 = Line2.XZ(startPoint.m_position, startPoint.m_position + vector); Line2 line4 = Line2.XZ(endPoint.m_position, endPoint.m_position + vector2); bool flag4 = true; float num6; float num7; if (line3.Intersect(line4, out num6, out num7) && num6 >= minNodeDistance && num7 >= minNodeDistance) { vector3 = endPoint.m_position + vector2 * num7; flag4 = false; } if (flag4) { Vector3 vector6 = startPoint.m_position - endPoint.m_position; Vector3 vector7 = vector2; vector6.y = 0f; vector7.y = 0f; float num8 = Vector3.SqrMagnitude(vector6); vector6 = Vector3.Normalize(vector6); float num9 = Mathf.Min(1.17809725f, Mathf.Acos(Vector3.Dot(vector6, vector7))); float d2 = Mathf.Sqrt(0.5f * num8 / Mathf.Max(0.001f, 1f - Mathf.Cos(3.14159274f - 2f * num9))); vector3 = endPoint.m_position + vector7 * d2; vector = vector3 - startPoint.m_position; vector.y = 0f; vector.Normalize(); } } if (!flag && !flag2) { middlePoint.m_direction = vector; endPoint.m_direction = -vector2; middlePoint.m_position = vector3; break; } } } return(toolErrors); }