private static Vector3 ChangePathRotation(BuildingInfo.PathInfo path, double angle) { Vector3 newNode = Vector3.zero; if (path.m_nodes != null && path.m_nodes.Length > 0) { for (var nodeIndex = 0; nodeIndex < path.m_nodes.Count(); nodeIndex++) { var oldNode = path.m_nodes[nodeIndex]; newNode = new Vector3 { x = (float)((oldNode.x * Math.Cos(angle)) - (oldNode.z * Math.Sin(angle))), y = oldNode.y, z = (float)((oldNode.x * Math.Sin(angle)) + (oldNode.z * Math.Cos(angle))) }; path.m_nodes[nodeIndex] = newNode; } } if (path.m_curveTargets != null && path.m_curveTargets.Length > 0) { for (var curveIndex = 0; curveIndex < path.m_curveTargets.Count(); curveIndex++) { var oldCurve = path.m_curveTargets[curveIndex]; var newCurve = new Vector3 { x = (float)((oldCurve.x * Math.Cos(angle)) - (oldCurve.z * Math.Sin(angle))), y = oldCurve.y, z = (float)((oldCurve.x * Math.Sin(angle)) + (oldCurve.z * Math.Cos(angle))), }; path.m_curveTargets[curveIndex] = newCurve; } } return(newNode); }
private static void PrepareBuilding(ref BuildingInfo info) { if (m_NeedsConvert) { m_CpmNetDict = null; RemoveCreatePassMileStone(ref info); } for (int j = 0; j < info.m_paths.Count(); j++) { BuildingInfo.PathInfo path = info.m_paths[j]; NetInfo nInfo = path.m_netInfo; if (nInfo.name == "Metro Station Track" || nInfo.IsUndergroundMetroStationTrack()) { if (nInfo.m_netAI == null) { var ai = nInfo.gameObject.AddComponent <MetroTrackAI>(); ai.m_info = nInfo; nInfo.m_netAI = ai; } if (m_NeedsConvert) { if (OptionsWrapper <Options> .Options.ghostMode) { info.m_paths[j].AssignNetInfo("Metro Station Track"); } else { info.m_paths[j].AssignNetInfo("Metro Station Track Tunnel"); } } } } }
public static void SetMetroStyle(this BuildingInfo.PathInfo info, TrackStyle style) { if (info.m_finalNetInfo.IsAbovegroundMetroStationTrack()) { var trackName = info.m_finalNetInfo.name; if (style == TrackStyle.Modern) { if (trackName.ToLower().StartsWith("steel")) { trackName = trackName.Substring(6); } info.AssignNetInfo(trackName, false); } else if (style == TrackStyle.Classic) { if (trackName.ToLower().StartsWith("steel") == false) { trackName = "Steel " + trackName; } info.AssignNetInfo(trackName, false); } } }
public static void AssignNetInfo(this BuildingInfo.PathInfo path, NetInfo netInfo, bool includeNetInfo = true) { if (includeNetInfo) { path.m_netInfo = netInfo; } path.m_finalNetInfo = netInfo; }
public static void HandleSubBuildings() { Debug.Log("Investigating " + m_Info.name); if (m_Info?.m_subBuildings != null && m_Info.m_subBuildings.Count() > 0) { for (int i = 0; i < m_Info.m_subBuildings.Count(); i++) { var subBuilding = m_Info.m_subBuildings[i]; if (subBuilding?.m_buildingInfo?.m_paths != null && subBuilding.m_buildingInfo.HasUndergroundMetroStationTracks()) { CleanUpPaths(subBuilding.m_buildingInfo); var theAngle = m_Angle; if (m_Info.name == "Large Airport") { if (subBuilding.m_buildingInfo.name == "Integrated Metro Station") { theAngle += 45; subBuilding.m_angle = 0; var offset = new Vector3(14, 0, 20); subBuilding.m_position = offset; var sbInsidePath = subBuilding.m_buildingInfo.m_paths.FirstOrDefault(p => p.m_nodes.Any(n => n == new Vector3(0, -4, 6))); var airportEntranceLeft = new Vector3(-40, 0, -27); var airportEntranceRight = new Vector3(10, 0, 40); var midpoint = Vector3.Lerp(airportEntranceLeft, airportEntranceRight, 0.5f); midpoint = new Vector3(midpoint.x, -4, midpoint.z); var keyNodeIndex = 0; var superKeyNode = AdjForOffset(sbInsidePath.m_nodes[keyNodeIndex], offset); var adjOtherNode = AdjForOffset(Vector3.Lerp(superKeyNode, midpoint, 0.5f), offset, false); var pathList = new List <BuildingInfo.PathInfo>(); BuildingInfo.PathInfo thePath = null; for (int j = 0; j < subBuilding.m_buildingInfo.m_paths.Count(); j++) { var path = subBuilding.m_buildingInfo.m_paths[j]; if (path.m_nodes.Contains(new Vector3(0, -4, 6))) { var nodeList = new List <Vector3>() { new Vector3(0, -4, 6), adjOtherNode }; path.m_nodes = nodeList.ToArray(); thePath = path; } pathList.Add(path); } var airportEntranceLeftToSub = AdjForOffset(airportEntranceLeft, offset, false); var airportEntranceRightToSub = AdjForOffset(airportEntranceRight, offset, false); var pathBranchLeft = ChainPath(thePath, airportEntranceLeftToSub, 1); var pathBranchRight = ChainPath(thePath, airportEntranceRightToSub, 1); pathList.Add(pathBranchLeft); pathList.Add(pathBranchRight); subBuilding.m_buildingInfo.m_paths = pathList.ToArray(); } } ModifyStation(subBuilding.m_buildingInfo, m_TargetDepth, m_TargetStationTrackLength, theAngle, m_BendStrength); } } } }
private static void BendStationTrack(BuildingInfo.PathInfo stationPath, float aBendStrength) { var middle = GetMiddle(stationPath); var newX = (stationPath.m_nodes.First().z - stationPath.m_nodes.Last().z) / 2; var newY = (stationPath.m_nodes.First().y + stationPath.m_nodes.Last().y) / 2; var newZ = -(stationPath.m_nodes.First().x - stationPath.m_nodes.Last().x) / 2; var newCurve = middle + (aBendStrength * new Vector3(newX, newY, newZ)); stationPath.m_curveTargets[0] = newCurve; }
private static void ShiftPath(BuildingInfo.PathInfo path, Vector3 offset) { for (var i = 0; i < path.m_nodes.Length; i++) { path.m_nodes[i] = path.m_nodes[i] + offset; } for (var i = 0; i < path.m_curveTargets.Length; i++) { path.m_curveTargets[i] = path.m_curveTargets[i] + offset; } }
public static void AssignNetInfo(this BuildingInfo.PathInfo path, string netInfoName, bool includeNetInfo = true) { NetInfo netInfo = PrefabCollection <NetInfo> .FindLoaded(netInfoName); if (netInfo == null) { UnityEngine.Debug.Log("Cannot find NetInfo " + netInfoName); } else { path.AssignNetInfo(netInfo, includeNetInfo); } }
private static Vector3 GetMiddle(BuildingInfo.PathInfo path, bool useBendStrength = false) { var aBendStrength = useBendStrength ? m_BendStrength : 0; var midPoint = (path.m_nodes.First() + path.m_nodes.Last()) / 2; var distance = Vector3.Distance(midPoint, path.m_nodes.First()); var xCoeff = -(path.m_nodes.First().x - path.m_nodes.Last().x) / Vector3.Distance(path.m_nodes.First(), path.m_nodes.Last()); var zCoeff = (path.m_nodes.First().z - path.m_nodes.Last().z) / Vector3.Distance(path.m_nodes.First(), path.m_nodes.Last()); var bendCoeff = aBendStrength * (Math.Sqrt(2) - 1); var adjMidPoint = new Vector3() { x = midPoint.x + (float)(-zCoeff * distance * bendCoeff), y = midPoint.y, z = midPoint.z + (float)(xCoeff * distance * bendCoeff) }; return(adjMidPoint); }
private static bool RequireFixedHeight(BuildingInfo buildingInfo, NetInfo info2, Vector3 pos) { if (info2.m_useFixedHeight) { return(true); } ItemClass.Service service = info2.m_class.m_service; ItemClass.SubService subService = info2.m_class.m_subService; ItemClass.Layer layer = info2.m_class.m_layer; ItemClass.Service service2 = ItemClass.Service.None; ItemClass.SubService subService2 = ItemClass.SubService.None; ItemClass.Layer layer2 = ItemClass.Layer.Default; if (info2.m_intersectClass != null) { service2 = info2.m_intersectClass.m_service; subService2 = info2.m_intersectClass.m_subService; layer2 = info2.m_intersectClass.m_layer; } if (info2.m_netAI.SupportUnderground() || info2.m_netAI.IsUnderground()) { layer |= (ItemClass.Layer.Default | ItemClass.Layer.MetroTunnels); layer2 |= (ItemClass.Layer.Default | ItemClass.Layer.MetroTunnels); } for (int i = 0; i < buildingInfo.m_paths.Length; i++) { BuildingInfo.PathInfo pathInfo = buildingInfo.m_paths[i]; if (pathInfo.m_finalNetInfo != null && pathInfo.m_finalNetInfo.m_useFixedHeight && pathInfo.m_nodes != null && pathInfo.m_nodes.Length != 0) { for (int j = 0; j < pathInfo.m_nodes.Length; j++) { if (Vector3.SqrMagnitude(pos - pathInfo.m_nodes[j]) < 0.001f) { NetInfo finalNetInfo = pathInfo.m_finalNetInfo; ItemClass connectionClass = finalNetInfo.GetConnectionClass(); if (((service == ItemClass.Service.None || connectionClass.m_service == service) && (subService == ItemClass.SubService.None || connectionClass.m_subService == subService) && (layer == ItemClass.Layer.None || (connectionClass.m_layer & layer) != ItemClass.Layer.None)) || (finalNetInfo.m_intersectClass != null && (service == ItemClass.Service.None || finalNetInfo.m_intersectClass.m_service == service) && (subService == ItemClass.SubService.None || finalNetInfo.m_intersectClass.m_subService == subService) && (layer == ItemClass.Layer.None || (finalNetInfo.m_intersectClass.m_layer & layer) != ItemClass.Layer.None)) || (finalNetInfo.m_netAI.CanIntersect(info2) && connectionClass.m_service == service2 && (subService2 == ItemClass.SubService.None || connectionClass.m_subService == subService2) && (layer2 == ItemClass.Layer.None || (connectionClass.m_layer & layer2) != ItemClass.Layer.None))) { return(true); } } } } } return(false); }
private static void SetCurveTargets(BuildingInfo.PathInfo path) { if (path.m_nodes.Length < 2) { return; } var newCurveTargets = new List <Vector3>(); if (path.m_curveTargets != null && path.m_curveTargets.Length > 0) { newCurveTargets.AddRange(path.m_curveTargets); } else { newCurveTargets.Add(new Vector3()); } newCurveTargets[0] = GetMiddle(path); path.m_curveTargets = newCurveTargets.ToArray(); }
private static double CalculateAngleDelta() { var stationTracks = m_Info.m_paths.Where(p => p.m_netInfo != null && p.m_netInfo.IsUndergroundMetroStationTrack() && p.m_nodes.Count() > 1).ToList(); BuildingInfo.PathInfo mainTrack = null; if (m_PremierPath > -1 && stationTracks.Count > m_PremierPath) { mainTrack = stationTracks[m_PremierPath]; } else { mainTrack = stationTracks.OrderBy(s => Vector3.Magnitude(GetMiddle(s))).ThenBy(s2 => GetMiddle(s2).y).FirstOrDefault(); m_PremierPath = stationTracks.IndexOf(mainTrack); } float delta = m_Angle - m_PrevAngle; m_PrevAngle = m_Angle; delta *= (float)(Math.PI / 180); return(delta); }
private static BuildingInfo.PathInfo ChainPath(BuildingInfo.PathInfo startPath, Vector3 endNode, int startNodeIndex = -1, NetInfo info = null) { var newNodes = new List <Vector3>(); var newPath = startPath.ShallowClone(); if (startNodeIndex == -1 || startNodeIndex >= startPath.m_nodes.Count()) { startNodeIndex = startPath.m_nodes.Count() - 1; } if (info != null) { newPath.AssignNetInfo(info); } var startNode = startPath.m_nodes[startNodeIndex]; newNodes.Add(startNode); newNodes.Add(endNode); newPath.m_nodes = newNodes.ToArray(); MarkPathGenerated(newPath); return(newPath); }
private static BuildingInfo.PathInfo AddStub(BuildingInfo.PathInfo path) { var pathLastIndex = path?.m_nodes?.Count() - 1 ?? 0; if (pathLastIndex < 1 || path.m_nodes.Any(n => n.y >= 0)) { return(null); } var newPath = path.ShallowClone(); var newPathNodes = new List <Vector3>(); var pathNodeDiff = path.m_nodes.Last() - path.m_nodes.First(); //var pathLengthCoeff = Vector3.Distance(path.m_nodes.First(), path.m_nodes.Last()) / 3; newPathNodes.Add(new Vector3() { x = path.m_nodes.First().x - pathNodeDiff.x, y = 0, z = path.m_nodes.First().z - pathNodeDiff.z }); newPathNodes.Add(path.m_nodes.First()); newPath.m_nodes = newPathNodes.ToArray(); //MarkPathGenerated(newPath); return(newPath); }
public static void AssignNetInfo(this BuildingInfo.PathInfo path, NetInfo netInfo) { path.m_netInfo = netInfo; path.m_finalNetInfo = netInfo; }
/* STOCK CODE START */ /* Called when building (intersection) loads its segments. Detoured method. Added code is marked 'ns' * We obrain a list with all the segments and pass them to the ProcessNewPaths method. We create our own list for that purpose instead of * using instance.m_tempSegmentBuffer because it almost seems that the game can create multiple segments per one saved path in the file which * makes absolutely no sense at all but would lead to our list being shifted compared to the (third) one in which we had saved the ids of the * old segments. Whatever, you don't really have to understand this, I studied it a lot when creating my previous mods and it's the part I * understand the most compared to the rest */ public static void LoadPaths(BuildingInfo info, ushort buildingID, ref Building data, float elevation) { #if DEBUG Debug.Log("LoadPaths TMPE detour"); #endif // ns Dictionary <string, TmpeAssetData> dict = AssetDataManager.Instance.AssetsWithData; bool isAssetWithTmpeSettings = dict.ContainsKey(IdentificationTool.GetNameWithoutPrefix(info.name)); List <ushort> CreatedSegments = null; if (isAssetWithTmpeSettings) { CreatedSegments = new List <ushort>(); } // ns end if (info.m_paths != null) { NetManager instance = Singleton <NetManager> .instance; instance.m_tempNodeBuffer.Clear(); instance.m_tempSegmentBuffer.Clear(); for (int i = 0; i < info.m_paths.Length; i++) { // ns if (isAssetWithTmpeSettings) { CreatedSegments.Add(0); } // ns end BuildingInfo.PathInfo pathInfo = info.m_paths[i]; if (pathInfo.m_finalNetInfo != null && pathInfo.m_nodes != null && pathInfo.m_nodes.Length != 0) { Vector3 vector = data.CalculatePosition(pathInfo.m_nodes[0]); bool flag = /*BuildingDecoration.*/ RequireFixedHeight(info, pathInfo.m_finalNetInfo, pathInfo.m_nodes[0]); if (!flag) { vector.y = NetSegment.SampleTerrainHeight(pathInfo.m_finalNetInfo, vector, false, pathInfo.m_nodes[0].y + elevation); } Ray ray = new Ray(vector + new Vector3(0f, 8f, 0f), Vector3.down); NetTool.ControlPoint controlPoint; if (!/*BuildingDecoration.*/ FindConnectNode(instance.m_tempNodeBuffer, vector, pathInfo.m_finalNetInfo, out controlPoint)) { if (NetTool.MakeControlPoint(ray, 16f, pathInfo.m_finalNetInfo, true, NetNode.Flags.Untouchable, NetSegment.Flags.Untouchable, Building.Flags.All, pathInfo.m_nodes[0].y + elevation - pathInfo.m_finalNetInfo.m_buildHeight, true, out controlPoint)) { Vector3 vector2 = controlPoint.m_position - vector; if (!flag) { vector2.y = 0f; } float sqrMagnitude = vector2.sqrMagnitude; if (sqrMagnitude > pathInfo.m_maxSnapDistance * pathInfo.m_maxSnapDistance) { controlPoint.m_position = vector; controlPoint.m_elevation = 0f; controlPoint.m_node = 0; controlPoint.m_segment = 0; } else { controlPoint.m_position.y = vector.y; } } else { controlPoint.m_position = vector; } } ushort num; ushort num2; int num3; int num4; if (controlPoint.m_node != 0) { instance.m_tempNodeBuffer.Add(controlPoint.m_node); } else if (NetTool.CreateNode(pathInfo.m_finalNetInfo, controlPoint, controlPoint, controlPoint, NetTool.m_nodePositionsSimulation, 0, false, false, false, false, pathInfo.m_invertSegments, false, 0, out num, out num2, out num3, out num4) == ToolBase.ToolErrors.None) { instance.m_tempNodeBuffer.Add(num); controlPoint.m_node = num; if (pathInfo.m_forbidLaneConnection != null && pathInfo.m_forbidLaneConnection.Length > 0 && pathInfo.m_forbidLaneConnection[0]) { NetNode[] buffer = instance.m_nodes.m_buffer; ushort num5 = num; buffer[(int)num5].m_flags = (buffer[(int)num5].m_flags | NetNode.Flags.ForbidLaneConnection); } if (pathInfo.m_trafficLights != null && pathInfo.m_trafficLights.Length > 0) { /*BuildingDecoration.*/ TrafficLightsToFlags(pathInfo.m_trafficLights[0], ref instance.m_nodes.m_buffer[(int)num].m_flags); } } for (int j = 1; j < pathInfo.m_nodes.Length; j++) { vector = data.CalculatePosition(pathInfo.m_nodes[j]); bool flag2 = /*BuildingDecoration.*/ RequireFixedHeight(info, pathInfo.m_finalNetInfo, pathInfo.m_nodes[j]); if (!flag2) { vector.y = NetSegment.SampleTerrainHeight(pathInfo.m_finalNetInfo, vector, false, pathInfo.m_nodes[j].y + elevation); } ray = new Ray(vector + new Vector3(0f, 8f, 0f), Vector3.down); NetTool.ControlPoint controlPoint2; if (!/*BuildingDecoration.*/ FindConnectNode(instance.m_tempNodeBuffer, vector, pathInfo.m_finalNetInfo, out controlPoint2)) { if (NetTool.MakeControlPoint(ray, 16f, pathInfo.m_finalNetInfo, true, NetNode.Flags.Untouchable, NetSegment.Flags.Untouchable, Building.Flags.All, pathInfo.m_nodes[j].y + elevation - pathInfo.m_finalNetInfo.m_buildHeight, true, out controlPoint2)) { Vector3 vector3 = controlPoint2.m_position - vector; if (!flag2) { vector3.y = 0f; } float sqrMagnitude2 = vector3.sqrMagnitude; if (sqrMagnitude2 > pathInfo.m_maxSnapDistance * pathInfo.m_maxSnapDistance) { controlPoint2.m_position = vector; controlPoint2.m_elevation = 0f; controlPoint2.m_node = 0; controlPoint2.m_segment = 0; } else { controlPoint2.m_position.y = vector.y; } } else { controlPoint2.m_position = vector; } } NetTool.ControlPoint middlePoint = controlPoint2; if (pathInfo.m_curveTargets != null && pathInfo.m_curveTargets.Length >= j) { middlePoint.m_position = data.CalculatePosition(pathInfo.m_curveTargets[j - 1]); if (!flag || !flag2) { middlePoint.m_position.y = NetSegment.SampleTerrainHeight(pathInfo.m_finalNetInfo, middlePoint.m_position, false, pathInfo.m_curveTargets[j - 1].y + elevation); } } else { middlePoint.m_position = (controlPoint.m_position + controlPoint2.m_position) * 0.5f; } middlePoint.m_direction = VectorUtils.NormalizeXZ(middlePoint.m_position - controlPoint.m_position); controlPoint2.m_direction = VectorUtils.NormalizeXZ(controlPoint2.m_position - middlePoint.m_position); ushort num6; ushort num7; ushort num8; int num9; int num10; if (NetTool.CreateNode(pathInfo.m_finalNetInfo, controlPoint, middlePoint, controlPoint2, NetTool.m_nodePositionsSimulation, 1, false, false, false, false, false, pathInfo.m_invertSegments, false, 0, out num6, out num7, out num8, out num9, out num10) == ToolBase.ToolErrors.None) { instance.m_tempNodeBuffer.Add(num7); instance.m_tempSegmentBuffer.Add(num8); // ns if (isAssetWithTmpeSettings) { CreatedSegments[CreatedSegments.Count - 1] = num8; } // ns end controlPoint2.m_node = num7; if (pathInfo.m_forbidLaneConnection != null && pathInfo.m_forbidLaneConnection.Length > j && pathInfo.m_forbidLaneConnection[j]) { NetNode[] buffer2 = instance.m_nodes.m_buffer; ushort num11 = num7; buffer2[(int)num11].m_flags = (buffer2[(int)num11].m_flags | NetNode.Flags.ForbidLaneConnection); } if (pathInfo.m_trafficLights != null && pathInfo.m_trafficLights.Length > j) { /*BuildingDecoration.*/ TrafficLightsToFlags(pathInfo.m_trafficLights[j], ref instance.m_nodes.m_buffer[(int)num7].m_flags); } if (pathInfo.m_yieldSigns != null && pathInfo.m_yieldSigns.Length >= j * 2) { if (pathInfo.m_yieldSigns[j * 2 - 2]) { NetSegment[] buffer3 = instance.m_segments.m_buffer; ushort num12 = num8; buffer3[(int)num12].m_flags = (buffer3[(int)num12].m_flags | NetSegment.Flags.YieldStart); } if (pathInfo.m_yieldSigns[j * 2 - 1]) { NetSegment[] buffer4 = instance.m_segments.m_buffer; ushort num13 = num8; buffer4[(int)num13].m_flags = (buffer4[(int)num13].m_flags | NetSegment.Flags.YieldEnd); } } } controlPoint = controlPoint2; flag = flag2; } } } for (int k = 0; k < instance.m_tempNodeBuffer.m_size; k++) { ushort num14 = instance.m_tempNodeBuffer.m_buffer[k]; if ((instance.m_nodes.m_buffer[(int)num14].m_flags & NetNode.Flags.Untouchable) == NetNode.Flags.None) { if (buildingID != 0) { if ((data.m_flags & Building.Flags.Active) == Building.Flags.None && instance.m_nodes.m_buffer[(int)num14].Info.m_canDisable) { NetNode[] buffer5 = instance.m_nodes.m_buffer; ushort num15 = num14; buffer5[(int)num15].m_flags = (buffer5[(int)num15].m_flags | NetNode.Flags.Disabled); } NetNode[] buffer6 = instance.m_nodes.m_buffer; ushort num16 = num14; buffer6[(int)num16].m_flags = (buffer6[(int)num16].m_flags | NetNode.Flags.Untouchable); instance.UpdateNode(num14); instance.m_nodes.m_buffer[(int)num14].m_nextBuildingNode = data.m_netNode; data.m_netNode = num14; } else { instance.UpdateNode(num14); } } } for (int l = 0; l < instance.m_tempSegmentBuffer.m_size; l++) { ushort num17 = instance.m_tempSegmentBuffer.m_buffer[l]; if ((instance.m_segments.m_buffer[(int)num17].m_flags & NetSegment.Flags.Untouchable) == NetSegment.Flags.None) { if (buildingID != 0) { NetSegment[] buffer7 = instance.m_segments.m_buffer; ushort num18 = num17; buffer7[(int)num18].m_flags = (buffer7[(int)num18].m_flags | NetSegment.Flags.Untouchable); instance.UpdateSegment(num17); } else { if ((Singleton <ToolManager> .instance.m_properties.m_mode & ItemClass.Availability.AssetEditor) != ItemClass.Availability.None) { NetInfo info2 = instance.m_segments.m_buffer[(int)num17].Info; if ((info2.m_availableIn & ItemClass.Availability.AssetEditor) == ItemClass.Availability.None) { NetSegment[] buffer8 = instance.m_segments.m_buffer; ushort num19 = num17; buffer8[(int)num19].m_flags = (buffer8[(int)num19].m_flags | NetSegment.Flags.Untouchable); } } instance.UpdateSegment(num17); } } } // ns if (isAssetWithTmpeSettings && CreatedSegments.Count > 0) { if (CreatedSegments.Last() == 0) { CreatedSegments.RemoveAt(CreatedSegments.Count - 1); } ProcessNewPaths(CreatedSegments, info); } // ns end instance.m_tempNodeBuffer.Clear(); instance.m_tempSegmentBuffer.Clear(); } }
private static bool IsPedestrianPath(BuildingInfo.PathInfo path) { return(path.m_netInfo.IsPedestrianNetwork()); }
private static bool IsPathGenerated(BuildingInfo.PathInfo path) { return(Math.Abs(path.m_maxSnapDistance - GENERATED_PATH_MARKER) < TOLERANCE); }
public static void ModifyStation(BuildingInfo info, float targetDepth, float targetStationTrackLength, float angle, float bendStrength, bool inRecurse = false) { m_Info = info; m_TargetDepth = targetDepth; m_TargetStationTrackLength = targetStationTrackLength; m_Angle = angle; m_BendStrength = bendStrength; if (m_TargetDepth <= 0 || targetStationTrackLength <= 0 || (!info.HasUndergroundMetroStationTracks() && (info?.m_subBuildings == null || info?.m_subBuildings.Count() == 0))) { return; } if (!inRecurse) { CleanUpPaths(); } if (info?.m_subBuildings != null && info.m_subBuildings.Count() > 0) { for (int i = 0; i < info.m_subBuildings.Count(); i++) { var subBuilding = info.m_subBuildings[i]; if (subBuilding?.m_buildingInfo?.m_paths != null && subBuilding.m_buildingInfo.HasUndergroundMetroStationTracks()) { CleanUpPaths(subBuilding.m_buildingInfo); if (info.name == "Large Airport") { if (subBuilding.m_buildingInfo.name == "Integrated Metro Station") { m_Angle += 45; subBuilding.m_angle = 0; var offset = new Vector3(14, 0, 20); subBuilding.m_position = offset; var sbInsidePath = subBuilding.m_buildingInfo.m_paths.FirstOrDefault(p => p.m_nodes.Any(n => n == new Vector3(0, -4, 6))); var airportEntranceLeft = new Vector3(-40, 0, -27); var airportEntranceRight = new Vector3(10, 0, 40); var midpoint = Vector3.Lerp(airportEntranceLeft, airportEntranceRight, 0.5f); midpoint = new Vector3(midpoint.x, -4, midpoint.z); var keyNodeIndex = 0; var superKeyNode = AdjForOffset(sbInsidePath.m_nodes[keyNodeIndex], offset); var adjOtherNode = AdjForOffset(Vector3.Lerp(superKeyNode, midpoint, 0.5f), offset, false); var pathList = new List <BuildingInfo.PathInfo>(); BuildingInfo.PathInfo thePath = null; for (int j = 0; j < subBuilding.m_buildingInfo.m_paths.Count(); j++) { var path = subBuilding.m_buildingInfo.m_paths[j]; if (path.m_nodes.Contains(new Vector3(0, -4, 6))) { var nodeList = new List <Vector3>() { new Vector3(0, -4, 6), adjOtherNode }; path.m_nodes = nodeList.ToArray(); thePath = path; } pathList.Add(path); } var airportEntranceLeftToSub = AdjForOffset(airportEntranceLeft, offset, false); var airportEntranceRightToSub = AdjForOffset(airportEntranceRight, offset, false); var pathBranchLeft = ChainPath(thePath, airportEntranceLeftToSub, 1); var pathBranchRight = ChainPath(thePath, airportEntranceRightToSub, 1); pathList.Add(pathBranchLeft); pathList.Add(pathBranchRight); subBuilding.m_buildingInfo.m_paths = pathList.ToArray(); } } ModifyStation(subBuilding.m_buildingInfo, m_TargetDepth, m_TargetStationTrackLength, m_Angle, m_BendStrength, true); } } } ResizeUndergroundStationTracks(); ChangeStationDepthAndRotation(); ReconfigureStationAccess(); BendStationTrack(); RecalculateSpawnPoints(); }
private static void MarkPathGenerated(BuildingInfo.PathInfo newPath) { newPath.m_maxSnapDistance = GENERATED_PATH_MARKER; }
public static bool LoadPaths(BuildingInfo info, ushort buildingID, ref Building data, float elevation) { if (info.m_paths != null) { // ns start HashSet <ConnectionPoint> borderNodes = null; if (info.m_paths.Length > 0) { //Debug.Log("LoadPaths detour"); borderNodes = ReleaseCollidingSegments(); } // ns end NetManager instance = Singleton <NetManager> .instance; instance.m_tempNodeBuffer.Clear(); instance.m_tempSegmentBuffer.Clear(); for (int i = 0; i < info.m_paths.Length; i++) { BuildingInfo.PathInfo pathInfo = info.m_paths[i]; if (pathInfo.m_finalNetInfo != null && pathInfo.m_nodes != null && pathInfo.m_nodes.Length != 0) { Vector3 vector = data.CalculatePosition(pathInfo.m_nodes[0]); bool flag = /*BuildingDecoration.*/ RequireFixedHeight(info, pathInfo.m_finalNetInfo, pathInfo.m_nodes[0]); if (!flag) { vector.y = NetSegment.SampleTerrainHeight(pathInfo.m_finalNetInfo, vector, false, pathInfo.m_nodes[0].y + elevation); } Ray ray = new Ray(vector + new Vector3(0f, 8f, 0f), Vector3.down); NetTool.ControlPoint controlPoint; if (!FindConnectNode(instance.m_tempNodeBuffer, vector, pathInfo.m_finalNetInfo, out controlPoint)) { if (NetTool.MakeControlPoint(ray, 16f, pathInfo.m_finalNetInfo, true, NetNode.Flags.Untouchable, NetSegment.Flags.Untouchable, Building.Flags.All, pathInfo.m_nodes[0].y + elevation - pathInfo.m_finalNetInfo.m_buildHeight, true, out controlPoint)) { Vector3 vector2 = controlPoint.m_position - vector; if (!flag) { vector2.y = 0f; } float sqrMagnitude = vector2.sqrMagnitude; if (sqrMagnitude > pathInfo.m_maxSnapDistance * pathInfo.m_maxSnapDistance) { controlPoint.m_position = vector; controlPoint.m_elevation = 0f; controlPoint.m_node = 0; controlPoint.m_segment = 0; } else { controlPoint.m_position.y = vector.y; } } else { controlPoint.m_position = vector; } } // ns start /*if (!instance.m_tempNodeBuffer.Contains(controlPoint.m_node)) * { * controlPoint.m_position = vector; * controlPoint.m_elevation = 0f; * controlPoint.m_node = 0; * controlPoint.m_segment = 0; * }*/ // ns end //CheckSplitSegmentAngle(ref controlPoint, instance.m_tempSegmentBuffer, borderNodes); // ns ushort node; ushort num2; int num3; int num4; if (controlPoint.m_node != 0) { instance.m_tempNodeBuffer.Add(controlPoint.m_node); } else if (NetTool.CreateNode(pathInfo.m_finalNetInfo, controlPoint, controlPoint, controlPoint, NetTool.m_nodePositionsSimulation, 0, false, false, false, false, pathInfo.m_invertSegments, false, 0, out node, out num2, out num3, out num4) == ToolBase.ToolErrors.None) { instance.m_tempNodeBuffer.Add(node); controlPoint.m_node = node; if (pathInfo.m_forbidLaneConnection != null && pathInfo.m_forbidLaneConnection.Length > 0 && pathInfo.m_forbidLaneConnection[0]) { NetNode[] buffer = instance.m_nodes.m_buffer; ushort num5 = node; buffer[(int)num5].m_flags = (buffer[(int)num5].m_flags | NetNode.Flags.ForbidLaneConnection); } if (pathInfo.m_trafficLights != null && pathInfo.m_trafficLights.Length > 0) { /*BuildingDecoration.*/ TrafficLightsToFlags(pathInfo.m_trafficLights[0], ref instance.m_nodes.m_buffer[(int)node].m_flags); } } for (int j = 1; j < pathInfo.m_nodes.Length; j++) { vector = data.CalculatePosition(pathInfo.m_nodes[j]); bool flag2 = /*BuildingDecoration.*/ RequireFixedHeight(info, pathInfo.m_finalNetInfo, pathInfo.m_nodes[j]); if (!flag2) { vector.y = NetSegment.SampleTerrainHeight(pathInfo.m_finalNetInfo, vector, false, pathInfo.m_nodes[j].y + elevation); } ray = new Ray(vector + new Vector3(0f, 8f, 0f), Vector3.down); NetTool.ControlPoint controlPoint2; if (!/*BuildingDecoration.*/ FindConnectNode(instance.m_tempNodeBuffer, vector, pathInfo.m_finalNetInfo, out controlPoint2)) { if (NetTool.MakeControlPoint(ray, 16f, pathInfo.m_finalNetInfo, true, NetNode.Flags.Untouchable, NetSegment.Flags.Untouchable, Building.Flags.All, pathInfo.m_nodes[j].y + elevation - pathInfo.m_finalNetInfo.m_buildHeight, true, out controlPoint2)) { Vector3 vector3 = controlPoint2.m_position - vector; if (!flag2) { vector3.y = 0f; } float sqrMagnitude2 = vector3.sqrMagnitude; if (sqrMagnitude2 > pathInfo.m_maxSnapDistance * pathInfo.m_maxSnapDistance) { controlPoint2.m_position = vector; controlPoint2.m_elevation = 0f; controlPoint2.m_node = 0; controlPoint2.m_segment = 0; } else { controlPoint2.m_position.y = vector.y; } } else { controlPoint2.m_position = vector; } } NetTool.ControlPoint middlePoint = controlPoint2; if (pathInfo.m_curveTargets != null && pathInfo.m_curveTargets.Length >= j) { middlePoint.m_position = data.CalculatePosition(pathInfo.m_curveTargets[j - 1]); if (!flag || !flag2) { middlePoint.m_position.y = NetSegment.SampleTerrainHeight(pathInfo.m_finalNetInfo, middlePoint.m_position, false, pathInfo.m_curveTargets[j - 1].y + elevation); } } else { middlePoint.m_position = (controlPoint.m_position + controlPoint2.m_position) * 0.5f; } middlePoint.m_direction = VectorUtils.NormalizeXZ(middlePoint.m_position - controlPoint.m_position); controlPoint2.m_direction = VectorUtils.NormalizeXZ(controlPoint2.m_position - middlePoint.m_position); ushort num6; ushort num7; ushort num8; int num9; int num10; if (NetTool.CreateNode(pathInfo.m_finalNetInfo, controlPoint, middlePoint, controlPoint2, NetTool.m_nodePositionsSimulation, 1, false, false, false, false, false, pathInfo.m_invertSegments, false, 0, out num6, out num7, out num8, out num9, out num10) == ToolBase.ToolErrors.None) { instance.m_tempNodeBuffer.Add(num7); instance.m_tempSegmentBuffer.Add(num8); controlPoint2.m_node = num7; if (pathInfo.m_forbidLaneConnection != null && pathInfo.m_forbidLaneConnection.Length > j && pathInfo.m_forbidLaneConnection[j]) { NetNode[] buffer2 = instance.m_nodes.m_buffer; ushort num11 = num7; buffer2[(int)num11].m_flags = (buffer2[(int)num11].m_flags | NetNode.Flags.ForbidLaneConnection); } if (pathInfo.m_trafficLights != null && pathInfo.m_trafficLights.Length > j) { /*BuildingDecoration.*/ TrafficLightsToFlags(pathInfo.m_trafficLights[j], ref instance.m_nodes.m_buffer[(int)num7].m_flags); } if (pathInfo.m_yieldSigns != null && pathInfo.m_yieldSigns.Length >= j * 2) { if (pathInfo.m_yieldSigns[j * 2 - 2]) { NetSegment[] buffer3 = instance.m_segments.m_buffer; ushort num12 = num8; buffer3[(int)num12].m_flags = (buffer3[(int)num12].m_flags | NetSegment.Flags.YieldStart); } if (pathInfo.m_yieldSigns[j * 2 - 1]) { NetSegment[] buffer4 = instance.m_segments.m_buffer; ushort num13 = num8; buffer4[(int)num13].m_flags = (buffer4[(int)num13].m_flags | NetSegment.Flags.YieldEnd); } } } controlPoint = controlPoint2; flag = flag2; } } } for (int k = 0; k < instance.m_tempNodeBuffer.m_size; k++) { ushort num14 = instance.m_tempNodeBuffer.m_buffer[k]; if ((instance.m_nodes.m_buffer[(int)num14].m_flags & NetNode.Flags.Untouchable) == NetNode.Flags.None) { if (buildingID != 0) { if ((data.m_flags & Building.Flags.Active) == Building.Flags.None && instance.m_nodes.m_buffer[(int)num14].Info.m_canDisable) { NetNode[] buffer5 = instance.m_nodes.m_buffer; ushort num15 = num14; buffer5[(int)num15].m_flags = (buffer5[(int)num15].m_flags | NetNode.Flags.Disabled); } NetNode[] buffer6 = instance.m_nodes.m_buffer; ushort num16 = num14; buffer6[(int)num16].m_flags = (buffer6[(int)num16].m_flags | NetNode.Flags.Untouchable); instance.UpdateNode(num14); instance.m_nodes.m_buffer[(int)num14].m_nextBuildingNode = data.m_netNode; data.m_netNode = num14; } else { instance.UpdateNode(num14); } } } for (int l = 0; l < instance.m_tempSegmentBuffer.m_size; l++) { ushort num17 = instance.m_tempSegmentBuffer.m_buffer[l]; if ((instance.m_segments.m_buffer[(int)num17].m_flags & NetSegment.Flags.Untouchable) == NetSegment.Flags.None) { if (buildingID != 0) { NetSegment[] buffer7 = instance.m_segments.m_buffer; ushort num18 = num17; buffer7[(int)num18].m_flags = (buffer7[(int)num18].m_flags | NetSegment.Flags.Untouchable); instance.UpdateSegment(num17); } else { if ((Singleton <ToolManager> .instance.m_properties.m_mode & ItemClass.Availability.AssetEditor) != ItemClass.Availability.None) { NetInfo info2 = instance.m_segments.m_buffer[(int)num17].Info; if ((info2.m_availableIn & ItemClass.Availability.AssetEditor) == ItemClass.Availability.None) { NetSegment[] buffer8 = instance.m_segments.m_buffer; ushort num19 = num17; buffer8[(int)num19].m_flags = (buffer8[(int)num19].m_flags | NetSegment.Flags.Untouchable); } } instance.UpdateSegment(num17); } } } // ns start if (info.m_paths.Length > 0) { ReleaseQuestionableSegments(instance.m_tempNodeBuffer, instance.m_tempSegmentBuffer); new MakeConnections(borderNodes, instance.m_tempNodeBuffer); } // ns end instance.m_tempNodeBuffer.Clear(); instance.m_tempSegmentBuffer.Clear(); } return(false); // ns }
public static void AssignNetInfo(this BuildingInfo.PathInfo path, string netInfoName) { NetInfo netInfo = PrefabCollection <NetInfo> .FindLoaded(netInfoName); path.AssignNetInfo(netInfo); }
private static void ReconfigureStationAccess() { var pathList = new List <BuildingInfo.PathInfo>(); var connectList = new List <Vector3[]>(); var singleGap = 16; var directionList = new List <string>(); //for (int i = 0; i < m_Info.m_paths.Length; i++) //{ // var thePath = m_Info.m_paths[i]; // if (thePath.m_netInfo == null || thePath.m_nodes == null || thePath.m_nodes.Count() < 2) // continue; // if (thePath.m_netInfo.IsUndergroundMetroStationTrack()) // { // var xDirection = (thePath.m_nodes.First().x - thePath.m_nodes.Last().x); // var zDirection = (thePath.m_nodes.First().z - thePath.m_nodes.Last().z); // var direction = $"{xDirection},{zDirection}"; // var antiDirection = $"{-xDirection},{-zDirection}"; // if (directionList.Contains(direction)) // { // continue; // } // if (directionList.Contains(antiDirection)) // { // thePath.m_nodes = thePath.m_nodes.Reverse().ToArray(); // } // else // { // directionList.Add(direction); // } // } //} for (int i = 0; i < m_Info.m_paths.Length; i++) { var thePath = m_Info.m_paths[i]; if (thePath.m_netInfo == null || thePath.m_nodes == null || thePath.m_nodes.Count() < 2) { continue; } if (thePath.m_netInfo.IsUndergroundSmallStationTrack() && !IsPathGenerated(thePath)) { var xCoeff = -(thePath.m_nodes.First().x - thePath.m_nodes.Last().x) / Vector3.Distance(thePath.m_nodes.First(), thePath.m_nodes.Last()); var zCoeff = (thePath.m_nodes.First().z - thePath.m_nodes.Last().z) / Vector3.Distance(thePath.m_nodes.First(), thePath.m_nodes.Last()); var multiplier = 1; var nearestTrackNode = m_Info.m_paths.Where(p => p.m_netInfo.IsUndergroundMetroStationTrack()).SelectMany(p => p.m_nodes).Where(n => n.y == thePath.m_nodes.First().y).OrderBy(n => Vector3.Distance(n, thePath.m_nodes.First())).FirstOrDefault(); if (Vector3.Distance(nearestTrackNode, thePath.m_nodes.First()) <= 2 * singleGap) { multiplier = -1; } var aNewPath = thePath.ShallowClone(); var nodeList = new List <Vector3>(); nodeList.Add(new Vector3() { x = thePath.m_nodes.First().x + multiplier * zCoeff * singleGap, y = thePath.m_nodes.First().y, z = thePath.m_nodes.First().z + multiplier * xCoeff * singleGap }); nodeList.Add(new Vector3() { x = thePath.m_nodes.Last().x + multiplier * zCoeff * singleGap, y = thePath.m_nodes.Last().y, z = thePath.m_nodes.Last().z + multiplier * xCoeff * singleGap }); aNewPath.m_nodes = nodeList.ToArray(); MarkPathGenerated(aNewPath); pathList.Add(aNewPath); } pathList.Add(thePath); } var aPath = pathList.FirstOrDefault(p => IsPedestrianPath(p)); if (aPath == null) { aPath = new BuildingInfo.PathInfo(); } for (int i = 0; i < pathList.Count; i++) { if (pathList[i].m_netInfo != null && pathList[i].m_netInfo.IsUndergroundMetroStationTrack()) { TrackPath = pathList[i]; var middleBend = GetMiddle(TrackPath, true); var middle = GetMiddle(TrackPath, false); BendVector = middleBend - middle; //var trackNodes = new List<Vector3>(); //for (var j = 0; j < trackPath.m_nodes.Count(); j++) //{ // trackNodes.Add(new Vector3() // { // x = trackPath.m_nodes[j].x - bendVector.x, // y = trackPath.m_nodes[j].y, // z = trackPath.m_nodes[j].z - bendVector.z // }); //} //trackPath.m_nodes = trackNodes.ToArray(); NewPath = aPath.ShallowClone(); NewPath.AssignNetInfo(SpecialNetInfo); MarkPathGenerated(NewPath); xCoeff = -(TrackPath.m_nodes[0].x - TrackPath.m_nodes.Last().x) / Vector3.Distance(TrackPath.m_nodes[0], TrackPath.m_nodes.Last()); zCoeff = (TrackPath.m_nodes[0].z - TrackPath.m_nodes.Last().z) / Vector3.Distance(TrackPath.m_nodes[0], TrackPath.m_nodes.Last()); var stationLength = Vector3.Distance(TrackPath.m_nodes[0], TrackPath.m_nodes.Last()); StairsLengthX = (((0.12f * m_BendStrength) + 1) * (stationLength * StairCoeff)) * -xCoeff; StairsLengthZ = (((0.12f * m_BendStrength) + 1) * (stationLength * StairCoeff)) * zCoeff; var interpolant = 0.6f; Crossing = Vector3.Lerp(TrackPath.m_nodes.First(), TrackPath.m_nodes.Last(), interpolant); if (TrackPath.m_netInfo.IsUndergroundIslandPlatformStationTrack()) { pathList.AddRange(SetStationPaths(0)); } //else if (TrackPath.m_netInfo.IsUndergroundSideIslandPlatformMetroStationTrack()) //{ // pathList.AddRange(SetStationPaths(-14, 0, 14)); //} else if (TrackPath.m_netInfo.IsUndergroundSmallStationTrack()) { pathList.AddRange(SetStationPaths(5)); } else if (TrackPath.m_netInfo.IsUndergroundPlatformLargeMetroStationTrack()) { pathList.AddRange(SetStationPaths(-11, 11)); } else if (TrackPath.m_netInfo.IsUndergroundDualIslandPlatformMetroStationTrack()) { pathList.AddRange(SetStationPaths(-8.8f, -5.5f, 5.5f, 8.8f)); } else if (TrackPath.m_netInfo.IsUndergroundSidePlatformMetroStationTrack()) { pathList.AddRange(SetStationPaths(-7, 7)); } if (!connectList.Contains(NewPath.m_nodes)) { connectList.Add(NewPath.m_nodes); } } } if (/*m_SuperInfo == null &&*/ m_Info.m_paths.Count() >= 2) { CheckPedestrianConnections(); } pathList = CleanPaths(pathList); var lowestHighPaths = m_Info.m_paths.Where(p => IsPedestrianPath(p) && p.m_nodes.Any(n => n.y > -4) && p.m_nodes.Any(nd => nd.y <= -4)).ToList(); if (lowestHighPaths.Count == 0) { lowestHighPaths.Add(m_Info.m_paths.Where(p => IsPedestrianPath(p)) .OrderByDescending(p => p.m_nodes[0].y) .FirstOrDefault()); } var connectPoints = new List <Vector3>(); if (lowestHighPaths != null && lowestHighPaths.Count > 0) { foreach (BuildingInfo.PathInfo p in lowestHighPaths) { if (p != null && p.m_nodes != null && p.m_nodes.Count() > 0) { connectPoints.Add(p.m_nodes.OrderByDescending(n => n.y).ThenBy(n => n.z).LastOrDefault()); } } } var currentVector = connectPoints.FirstOrDefault(); if (connectPoints != null && connectPoints.Count > 0) { var pool = new List <Vector3[]>(); var pivotPath = pathList.FirstOrDefault(p => p.m_nodes.Any(n => n == connectPoints.FirstOrDefault())); pool.AddRange(connectList); for (var i = 0; i < connectList.Count; i++) { var closestVector = pool.SelectMany(n => n).OrderBy(n => (currentVector.x - n.x) + (100 * (connectPoints.FirstOrDefault().y - n.y)) + (currentVector.z - n.z)).LastOrDefault(); var closestPath = pathList.FirstOrDefault(p => p.m_nodes.Any(n => n == closestVector)); BuildingInfo.PathInfo branch = null; if (currentVector == connectPoints.FirstOrDefault()) { branch = ChainPath(pivotPath, closestVector, Array.IndexOf(pivotPath.m_nodes, connectPoints.FirstOrDefault())); } else { branch = ChainPath(closestPath, currentVector, Array.IndexOf(closestPath.m_nodes, closestVector)); } branch.AssignNetInfo(SpecialNetInfo); branch.m_forbidLaneConnection = new[] { true, true }; pathList.Add(branch); var nodeArrayToLose = pool.FirstOrDefault(na => na.Any(n => n == closestVector)); if (nodeArrayToLose != null) { currentVector = nodeArrayToLose.OrderBy(n => Vector3.Distance(closestVector, n)).LastOrDefault(); pool.Remove(nodeArrayToLose); } } if (connectPoints.Count > 1) { for (var i = 1; i < connectPoints.Count(); i++) { Vector3 node = connectPoints[i]; Vector3 closestVector = connectList.SelectMany(n => n).OrderBy(n => (node.x - n.x) + (100 * (node.y - n.y)) + (node.z - n.z)).FirstOrDefault(); var closestPath = pathList.FirstOrDefault(p => p.m_nodes.Any(n => n == closestVector)); var branch = ChainPath(closestPath, node, Array.IndexOf(closestPath.m_nodes, closestVector)); branch.AssignNetInfo(SpecialNetInfo); branch.m_forbidLaneConnection = new[] { true, true }; pathList.Add(branch); } } } m_Info.m_paths = CleanPaths(pathList).ToArray(); }
private static bool AllNodesUnderGround(BuildingInfo.PathInfo path) { return(path.m_nodes.All(n => n.y <= -4)); }
private static void GetMiddlePointsFor(BuildingInfo.PathInfo pathInfo, out Vector3 b, out Vector3 c) { b = Vector3.zero; c = Vector3.zero; if (pathInfo.m_finalNetInfo != null && pathInfo.m_nodes != null && pathInfo.m_nodes.Length != 0) { Vector3 vector = Building.CalculatePosition(new Vector3(), 0, pathInfo.m_nodes[0]); if (!pathInfo.m_finalNetInfo.m_useFixedHeight) { vector.y = NetSegment.SampleTerrainHeight(pathInfo.m_finalNetInfo, vector, false, pathInfo.m_nodes[0].y); } var ray = new Ray(vector + new Vector3(0f, 8f, 0f), Vector3.down); if (NetTool.MakeControlPoint(ray, 16f, pathInfo.m_finalNetInfo, true, NetNode.Flags.Untouchable, NetSegment.Flags.Untouchable, Building.Flags.All, pathInfo.m_nodes[0].y - pathInfo.m_finalNetInfo.m_buildHeight, true, out NetTool.ControlPoint controlPoint)) { Vector3 vector2 = controlPoint.m_position - vector; if (!pathInfo.m_finalNetInfo.m_useFixedHeight) { vector2.y = 0f; } float sqrMagnitude = vector2.sqrMagnitude; if (sqrMagnitude > pathInfo.m_maxSnapDistance * pathInfo.m_maxSnapDistance) { controlPoint.m_position = vector; controlPoint.m_elevation = 0f; controlPoint.m_node = 0; controlPoint.m_segment = 0; } else { controlPoint.m_position.y = vector.y; } } else { controlPoint.m_position = vector; } int j = 1; vector = Building.CalculatePosition(Vector3.zero, 0, pathInfo.m_nodes[j]); if (!pathInfo.m_finalNetInfo.m_useFixedHeight) { vector.y = NetSegment.SampleTerrainHeight(pathInfo.m_finalNetInfo, vector, false, pathInfo.m_nodes[j].y); } ray = new Ray(vector + new Vector3(0f, 8f, 0f), Vector3.down); if (NetTool.MakeControlPoint(ray, 16f, pathInfo.m_finalNetInfo, true, NetNode.Flags.Untouchable, NetSegment.Flags.Untouchable, Building.Flags.All, pathInfo.m_nodes[j].y - pathInfo.m_finalNetInfo.m_buildHeight, true, out NetTool.ControlPoint controlPoint2)) { Vector3 vector3 = controlPoint2.m_position - vector; if (!pathInfo.m_finalNetInfo.m_useFixedHeight) { vector3.y = 0f; } float sqrMagnitude2 = vector3.sqrMagnitude; if (sqrMagnitude2 > pathInfo.m_maxSnapDistance * pathInfo.m_maxSnapDistance) { controlPoint2.m_position = vector; controlPoint2.m_elevation = 0f; controlPoint2.m_node = 0; controlPoint2.m_segment = 0; } else { controlPoint2.m_position.y = vector.y; } } else { controlPoint2.m_position = vector; } NetTool.ControlPoint middlePoint = controlPoint2; if (pathInfo.m_curveTargets != null && pathInfo.m_curveTargets.Length >= j) { middlePoint.m_position = Building.CalculatePosition(Vector3.zero, 0, pathInfo.m_curveTargets[j - 1]); if (!pathInfo.m_finalNetInfo.m_useFixedHeight) { middlePoint.m_position.y = NetSegment.SampleTerrainHeight(pathInfo.m_finalNetInfo, middlePoint.m_position, false, pathInfo.m_curveTargets[j - 1].y); } } else { middlePoint.m_position = (controlPoint.m_position + controlPoint2.m_position) * 0.5f; } middlePoint.m_direction = VectorUtils.NormalizeXZ(middlePoint.m_position - controlPoint.m_position); controlPoint2.m_direction = VectorUtils.NormalizeXZ(controlPoint2.m_position - middlePoint.m_position); NetSegment.CalculateMiddlePoints(controlPoint.m_position, middlePoint.m_direction, controlPoint2.m_position, -controlPoint2.m_direction, true, true, out b, out c); //controlPoint = controlPoint2; } }
private static bool IsVehicleStop(BuildingInfo.PathInfo path) { UnityEngine.Debug.LogError("IsVehicleStop"); return(false); }
private static bool IsVehicleStop(BuildingInfo.PathInfo path) { return((path?.m_nodes?.Length ?? 0) > 1 && (path?.m_netInfo?.IsUndergroundMetroStationTrack() ?? false)); }
private static void DipPath(BuildingInfo.PathInfo path, float depthOffsetDist) { ShiftPath(path, new Vector3(0, -depthOffsetDist, 0)); }
internal static object CustomDeserialize(Package p, Type t, PackageReader r) { // Props and trees in buildings and parks. if (t == typeof(BuildingInfo.Prop)) { PropInfo pi = Get <PropInfo>(r.ReadString()); // old name format (without package name) is possible TreeInfo ti = Get <TreeInfo>(r.ReadString()); // old name format (without package name) is possible if (instance.report && UsedAssets.instance.GotAnyContainer()) { if (pi != null) { string n = pi.gameObject.name; if (!string.IsNullOrEmpty(n) && n.IndexOf('.') >= 0) { UsedAssets.instance.IndirectProps.Add(n); } } if (ti != null) { string n = ti.gameObject.name; if (!string.IsNullOrEmpty(n) && n.IndexOf('.') >= 0) { UsedAssets.instance.IndirectTrees.Add(n); } } } return(new BuildingInfo.Prop { m_prop = pi, m_tree = ti, m_position = r.ReadVector3(), m_angle = r.ReadSingle(), m_probability = r.ReadInt32(), m_fixedHeight = r.ReadBoolean() }); } // Paths (nets) in buildings. if (t == typeof(BuildingInfo.PathInfo)) { string fullName = r.ReadString(); NetInfo ni = Get <NetInfo>(fullName); BuildingInfo.PathInfo path = new BuildingInfo.PathInfo(); path.m_netInfo = ni; path.m_nodes = r.ReadVector3Array(); path.m_curveTargets = r.ReadVector3Array(); path.m_invertSegments = r.ReadBoolean(); path.m_maxSnapDistance = r.ReadSingle(); if (p.version >= 5) { path.m_forbidLaneConnection = r.ReadBooleanArray(); path.m_trafficLights = (BuildingInfo.TrafficLights[])(object) r.ReadInt32Array(); path.m_yieldSigns = r.ReadBooleanArray(); } return(path); } if (t == typeof(Package.Asset)) { return(r.ReadAsset(p)); } // It seems that trailers are listed in the save game so this is not necessary. Better to be safe however // because a missing trailer reference is fatal for the simulation thread. if (t == typeof(VehicleInfo.VehicleTrailer)) { string name = r.ReadString(); string fullName = p.packageName + "." + name; VehicleInfo vi = Get <VehicleInfo>(p, fullName, name, false); VehicleInfo.VehicleTrailer trailer; trailer.m_info = vi; trailer.m_probability = r.ReadInt32(); trailer.m_invertProbability = r.ReadInt32(); return(trailer); } if (t == typeof(NetInfo.Lane)) { return(new NetInfo.Lane { m_position = r.ReadSingle(), m_width = r.ReadSingle(), m_verticalOffset = r.ReadSingle(), m_stopOffset = r.ReadSingle(), m_speedLimit = r.ReadSingle(), m_direction = (NetInfo.Direction)r.ReadInt32(), m_laneType = (NetInfo.LaneType)r.ReadInt32(), m_vehicleType = (VehicleInfo.VehicleType)r.ReadInt32(), m_stopType = (VehicleInfo.VehicleType)r.ReadInt32(), m_laneProps = GetNetLaneProps(p, r), m_allowConnect = r.ReadBoolean(), m_useTerrainHeight = r.ReadBoolean(), m_centerPlatform = r.ReadBoolean(), m_elevated = r.ReadBoolean() }); } if (t == typeof(NetInfo.Segment)) { NetInfo.Segment segment = new NetInfo.Segment(); string checksum = r.ReadString(); segment.m_mesh = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMesh(checksum, p, true); checksum = r.ReadString(); segment.m_material = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMaterial(checksum, p, true); checksum = r.ReadString(); segment.m_lodMesh = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMesh(checksum, p, false); checksum = r.ReadString(); segment.m_lodMaterial = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMaterial(checksum, p, false); segment.m_forwardRequired = (NetSegment.Flags)r.ReadInt32(); segment.m_forwardForbidden = (NetSegment.Flags)r.ReadInt32(); segment.m_backwardRequired = (NetSegment.Flags)r.ReadInt32(); segment.m_backwardForbidden = (NetSegment.Flags)r.ReadInt32(); segment.m_emptyTransparent = r.ReadBoolean(); segment.m_disableBendNodes = r.ReadBoolean(); return(segment); } if (t == typeof(NetInfo.Node)) { NetInfo.Node node = new NetInfo.Node(); string checksum = r.ReadString(); node.m_mesh = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMesh(checksum, p, true); checksum = r.ReadString(); node.m_material = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMaterial(checksum, p, true); checksum = r.ReadString(); node.m_lodMesh = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMesh(checksum, p, false); checksum = r.ReadString(); node.m_lodMaterial = string.IsNullOrEmpty(checksum) ? null : Sharing.instance.GetMaterial(checksum, p, false); node.m_flagsRequired = (NetNode.Flags)r.ReadInt32(); node.m_flagsForbidden = (NetNode.Flags)r.ReadInt32(); node.m_connectGroup = (NetInfo.ConnectGroup)r.ReadInt32(); node.m_directConnect = r.ReadBoolean(); node.m_emptyTransparent = r.ReadBoolean(); return(node); } if (t == typeof(NetInfo)) { string name = r.ReadString(); CustomAssetMetaData.Type type = AssetLoader.instance.GetMetaType(AssetLoader.instance.Current); if (type == CustomAssetMetaData.Type.Road || type == CustomAssetMetaData.Type.RoadElevation) { return(Get <NetInfo>(p, name)); } else { return(Get <NetInfo>(name)); } } if (t == typeof(BuildingInfo)) { string name = r.ReadString(); CustomAssetMetaData.Type type = AssetLoader.instance.GetMetaType(AssetLoader.instance.Current); if (type == CustomAssetMetaData.Type.Road || type == CustomAssetMetaData.Type.RoadElevation) { return(Get <BuildingInfo>(p, name)); } else { return(Get <BuildingInfo>(name)); } } // Sub-buildings in buildings. if (t == typeof(BuildingInfo.SubInfo)) { string name = r.ReadString(); string fullName = p.packageName + "." + name; BuildingInfo bi = null; if (fullName == AssetLoader.instance.Current.fullName || name == AssetLoader.instance.Current.fullName) { Util.DebugPrint("Warning:", fullName, "wants to be a sub-building for itself"); } else { bi = Get <BuildingInfo>(p, fullName, name, true); } BuildingInfo.SubInfo subInfo = new BuildingInfo.SubInfo(); subInfo.m_buildingInfo = bi; subInfo.m_position = r.ReadVector3(); subInfo.m_angle = r.ReadSingle(); subInfo.m_fixedHeight = r.ReadBoolean(); return(subInfo); } // Prop variations in props. if (t == typeof(PropInfo.Variation)) { string name = r.ReadString(); string fullName = p.packageName + "." + name; PropInfo pi = null; if (fullName == AssetLoader.instance.Current.fullName) { Util.DebugPrint("Warning:", fullName, "wants to be a prop variation for itself"); } else { pi = Get <PropInfo>(p, fullName, name, false); } return(new PropInfo.Variation { m_prop = pi, m_probability = r.ReadInt32() }); } // Tree variations in trees. if (t == typeof(TreeInfo.Variation)) { string name = r.ReadString(); string fullName = p.packageName + "." + name; TreeInfo ti = null; if (fullName == AssetLoader.instance.Current.fullName) { Util.DebugPrint("Warning:", fullName, "wants to be a tree variation for itself"); } else { ti = Get <TreeInfo>(p, fullName, name, false); } return(new TreeInfo.Variation { m_tree = ti, m_probability = r.ReadInt32() }); } if (t == typeof(VehicleInfo.MeshInfo)) { VehicleInfo.MeshInfo meshinfo = new VehicleInfo.MeshInfo(); string checksum = r.ReadString(); if (!string.IsNullOrEmpty(checksum)) { Package.Asset asset = p.FindByChecksum(checksum); GameObject go = AssetDeserializer.Instantiate(asset) as GameObject; meshinfo.m_subInfo = go.GetComponent <VehicleInfoBase>(); go.SetActive(false); if (meshinfo.m_subInfo.m_lodObject != null) { meshinfo.m_subInfo.m_lodObject.SetActive(false); } } else { meshinfo.m_subInfo = null; } meshinfo.m_vehicleFlagsForbidden = (Vehicle.Flags)r.ReadInt32(); meshinfo.m_vehicleFlagsRequired = (Vehicle.Flags)r.ReadInt32(); meshinfo.m_parkedFlagsForbidden = (VehicleParked.Flags)r.ReadInt32(); meshinfo.m_parkedFlagsRequired = (VehicleParked.Flags)r.ReadInt32(); return(meshinfo); } return(PackageHelper.CustomDeserialize(p, t, r)); }
private static Vector3 GetMiddle(BuildingInfo.PathInfo path) { UnityEngine.Debug.LogError("GetMiddle"); return(Vector3.zero); }