private void SetEditLine(ushort line, bool forceRefresh) { if (line != this.m_lastEditLine || forceRefresh) { TransportManager instance = Singleton <TransportManager> .instance; if (this.m_lastEditLine != 0) { TransportLine[] expr_39_cp_0 = instance.m_lines.m_buffer; ushort expr_39_cp_1 = this.m_lastEditLine; expr_39_cp_0[(int)expr_39_cp_1].m_flags = (expr_39_cp_0[(int)expr_39_cp_1].m_flags & ~(TransportLine.Flags.Hidden | TransportLine.Flags.Selected)); } this.m_lastEditLine = line; this.m_lastMoveIndex = -2; this.m_lastAddIndex = -2; this.m_lastMovePos = Vector3.zero; this.m_lastAddPos = Vector3.zero; if (this.m_lastEditLine != 0) { TransportLine[] expr_95_cp_0 = instance.m_lines.m_buffer; ushort expr_95_cp_1 = this.m_lastEditLine; expr_95_cp_0[(int)expr_95_cp_1].m_flags = (expr_95_cp_0[(int)expr_95_cp_1].m_flags | (TransportLine.Flags.Hidden | TransportLine.Flags.Selected)); } if (this.m_tempLine != 0) { instance.m_lines.m_buffer[(int)this.m_tempLine].CloneLine(this.m_tempLine, this.m_lastEditLine); BusTransportLineAI.UpdateMeshData(ref instance.m_lines.m_buffer[(int)this.m_tempLine], this.m_tempLine); } } }
public new static bool UpdatePath(ushort segmentID, ref NetSegment data, ItemClass.Service netService, VehicleInfo.VehicleType vehicleType, bool skipQueue) { if (data.m_path == 0u) { return(BusTransportLineAI.StartPathFind(segmentID, ref data, netService, vehicleType, skipQueue)); } if ((data.m_flags & NetSegment.Flags.WaitingPath) == NetSegment.Flags.None) { return(true); } PathManager instance = Singleton <PathManager> .instance; NetManager instance2 = Singleton <NetManager> .instance; byte pathFindFlags = instance.m_pathUnits.m_buffer[(int)((UIntPtr)data.m_path)].m_pathFindFlags; if ((pathFindFlags & 4) != 0) { bool flag = false; PathUnit.Position pathPos; if (instance.m_pathUnits.m_buffer[(int)((UIntPtr)data.m_path)].GetPosition(0, out pathPos)) { flag = TransportLineAI.CheckNodePosition(data.m_startNode, pathPos); } if (instance.m_pathUnits.m_buffer[(int)((UIntPtr)data.m_path)].GetLastPosition(out pathPos)) { TransportLineAI.CheckNodePosition(data.m_endNode, pathPos); } float length = instance.m_pathUnits.m_buffer[(int)((UIntPtr)data.m_path)].m_length; if (length != data.m_averageLength) { data.m_averageLength = length; ushort transportLine = instance2.m_nodes.m_buffer[(int)data.m_startNode].m_transportLine; if (transportLine != 0) { Singleton <TransportManager> .instance.UpdateLine(transportLine); } } if (data.m_lanes != 0u) { instance2.m_lanes.m_buffer[(int)((UIntPtr)data.m_lanes)].m_length = data.m_averageLength * ((!flag) ? 1f : 0.75f); } data.m_flags &= ~NetSegment.Flags.WaitingPath; data.m_flags &= ~NetSegment.Flags.PathFailed; return(true); } if ((pathFindFlags & 8) != 0) { if (data.m_averageLength == 0f) { Vector3 position = instance2.m_nodes.m_buffer[(int)data.m_startNode].m_position; Vector3 position2 = instance2.m_nodes.m_buffer[(int)data.m_endNode].m_position; data.m_averageLength = Vector3.Distance(position, position2); } data.m_flags &= ~NetSegment.Flags.WaitingPath; data.m_flags |= NetSegment.Flags.PathFailed; return(true); } return(false); }
public override void SimulationStep(ushort segmentID, ref NetSegment data) { NetManager instance = Singleton <NetManager> .instance; if ((instance.m_nodes.m_buffer[(int)data.m_startNode].m_flags & NetNode.Flags.Temporary) == NetNode.Flags.None) { if (data.m_path == 0u || (ulong)(Singleton <SimulationManager> .instance.m_currentFrameIndex >> 8 & 15u) == (ulong)((long)(segmentID & 15))) { BusTransportLineAI.StartPathFind(segmentID, ref data, this.m_netService, this.m_vehicleType, false); } else { BusTransportLineAI.UpdatePath(segmentID, ref data, this.m_netService, this.m_vehicleType, false); } } }
public static bool UpdatePaths(ref TransportLine transportLine, ushort lineID) { bool flag = true; NetManager instance = Singleton <NetManager> .instance; ushort stops = transportLine.m_stops; ushort num = stops; int num2 = 0; while (num != 0) { ushort num3 = 0; for (int i = 0; i < 8; i++) { ushort segment = instance.m_nodes.m_buffer[(int)num].GetSegment(i); if (segment != 0 && instance.m_segments.m_buffer[(int)segment].m_startNode == num) { TransportInfo info = transportLine.Info; if (!BusTransportLineAI.UpdatePath(segment, ref instance.m_segments.m_buffer[(int)segment], info.m_netService, info.m_vehicleType, (transportLine.m_flags & TransportLine.Flags.Temporary) != TransportLine.Flags.None)) { flag = false; } num3 = instance.m_segments.m_buffer[(int)segment].m_endNode; break; } } num = num3; if (num == stops) { break; } if (!flag) { break; } if (++num2 >= 32768) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace); break; } } return(flag); }
public new static bool StartPathFind(ushort segmentID, ref NetSegment data, ItemClass.Service netService, VehicleInfo.VehicleType vehicleType, bool skipQueue) { if (data.m_path != 0u) { Singleton <PathManager> .instance.ReleasePath(data.m_path); data.m_path = 0u; } NetManager instance = Singleton <NetManager> .instance; if ((instance.m_nodes.m_buffer[(int)data.m_startNode].m_flags & NetNode.Flags.Ambiguous) != NetNode.Flags.None) { for (int i = 0; i < 8; i++) { ushort segment = instance.m_nodes.m_buffer[(int)data.m_startNode].GetSegment(i); if (segment != 0 && segment != segmentID && instance.m_segments.m_buffer[(int)segment].m_path != 0u) { return(true); } } } if ((instance.m_nodes.m_buffer[(int)data.m_endNode].m_flags & NetNode.Flags.Ambiguous) != NetNode.Flags.None) { for (int j = 0; j < 8; j++) { ushort segment2 = instance.m_nodes.m_buffer[(int)data.m_endNode].GetSegment(j); if (segment2 != 0 && segment2 != segmentID && instance.m_segments.m_buffer[(int)segment2].m_path != 0u) { return(true); } } } 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; PathUnit.Position startPosA; PathUnit.Position startPosB; float num; float num2; if (!PathManager.FindPathPosition(position, netService, NetInfo.LaneType.Pedestrian, VehicleInfo.VehicleType.None, true, false, 32f, out startPosA, out startPosB, out num, out num2)) { return(true); } PathUnit.Position endPosA; PathUnit.Position endPosB; float num3; float num4; if (!PathManager.FindPathPosition(position2, netService, NetInfo.LaneType.Pedestrian, VehicleInfo.VehicleType.None, true, false, 32f, out endPosA, out endPosB, out num3, out num4)) { return(true); } if ((instance.m_nodes.m_buffer[(int)data.m_startNode].m_flags & NetNode.Flags.Fixed) != NetNode.Flags.None) { startPosB = default(PathUnit.Position); } if ((instance.m_nodes.m_buffer[(int)data.m_endNode].m_flags & NetNode.Flags.Fixed) != NetNode.Flags.None) { endPosB = default(PathUnit.Position); } startPosA.m_offset = 128; startPosB.m_offset = 128; endPosA.m_offset = 128; endPosB.m_offset = 128; bool stopLane = BusTransportLineAI.GetStopLane(ref startPosA, vehicleType); bool stopLane2 = BusTransportLineAI.GetStopLane(ref startPosB, vehicleType); bool stopLane3 = BusTransportLineAI.GetStopLane(ref endPosA, vehicleType); bool stopLane4 = BusTransportLineAI.GetStopLane(ref endPosB, vehicleType); if ((!stopLane && !stopLane2) || (!stopLane3 && !stopLane4)) { return(true); } uint path; bool createPathResult; CustomPathManager customPathManager = Singleton <PathManager> .instance as CustomPathManager; if (customPathManager != null) { createPathResult = customPathManager.CreatePath(out path, ref Singleton <SimulationManager> .instance.m_randomizer, Singleton <SimulationManager> .instance.m_currentBuildIndex, startPosA, startPosB, endPosA, endPosB, NetInfo.LaneType.Vehicle, vehicleType, 20000f, false, true, true, skipQueue, RoadManager.VehicleType.Bus); } else { createPathResult = Singleton <PathManager> .instance.CreatePath(out path, ref Singleton <SimulationManager> .instance.m_randomizer, Singleton <SimulationManager> .instance.m_currentBuildIndex, startPosA, startPosB, endPosA, endPosB, NetInfo.LaneType.Vehicle, vehicleType, 20000f, false, true, true, skipQueue); } if (createPathResult) { if (startPosA.m_segment != 0 && startPosB.m_segment != 0) { NetNode[] expr_2D9_cp_0 = instance.m_nodes.m_buffer; ushort expr_2D9_cp_1 = data.m_startNode; expr_2D9_cp_0[(int)expr_2D9_cp_1].m_flags = (expr_2D9_cp_0[(int)expr_2D9_cp_1].m_flags | NetNode.Flags.Ambiguous); } else { NetNode[] expr_305_cp_0 = instance.m_nodes.m_buffer; ushort expr_305_cp_1 = data.m_startNode; expr_305_cp_0[(int)expr_305_cp_1].m_flags = (expr_305_cp_0[(int)expr_305_cp_1].m_flags & ~NetNode.Flags.Ambiguous); } if (endPosA.m_segment != 0 && endPosB.m_segment != 0) { NetNode[] expr_344_cp_0 = instance.m_nodes.m_buffer; ushort expr_344_cp_1 = data.m_endNode; expr_344_cp_0[(int)expr_344_cp_1].m_flags = (expr_344_cp_0[(int)expr_344_cp_1].m_flags | NetNode.Flags.Ambiguous); } else { NetNode[] expr_370_cp_0 = instance.m_nodes.m_buffer; ushort expr_370_cp_1 = data.m_endNode; expr_370_cp_0[(int)expr_370_cp_1].m_flags = (expr_370_cp_0[(int)expr_370_cp_1].m_flags & ~NetNode.Flags.Ambiguous); } data.m_path = path; data.m_flags |= NetSegment.Flags.WaitingPath; return(false); } return(true); }
// from TransportLine public static bool UpdateMeshData(ref TransportLine transportLine, ushort lineID) { //return transportLine.UpdateMeshData(lineID); bool flag = true; int num = 0; int num2 = 0; int num3 = 0; float num4 = 0f; TransportManager instance = Singleton <TransportManager> .instance; NetManager instance2 = Singleton <NetManager> .instance; PathManager instance3 = Singleton <PathManager> .instance; ushort stops = transportLine.m_stops; ushort num5 = stops; int num6 = 0; while (num5 != 0) { ushort num7 = 0; for (int i = 0; i < 8; i++) { ushort segment = instance2.m_nodes.m_buffer[(int)num5].GetSegment(i); if (segment != 0 && instance2.m_segments.m_buffer[(int)segment].m_startNode == num5) { uint path = instance2.m_segments.m_buffer[(int)segment].m_path; if (path != 0u) { byte pathFindFlags = instance3.m_pathUnits.m_buffer[(int)((UIntPtr)path)].m_pathFindFlags; if ((pathFindFlags & 4) != 0) { if (!TransportLine.CalculatePathSegmentCount(path, ref num2, ref num3, ref num4)) { TransportInfo info = transportLine.Info; BusTransportLineAI.StartPathFind(segment, ref instance2.m_segments.m_buffer[(int)segment], info.m_netService, info.m_vehicleType, (transportLine.m_flags & TransportLine.Flags.Temporary) != TransportLine.Flags.None); flag = false; } } else if ((pathFindFlags & 8) == 0) { flag = false; } } num7 = instance2.m_segments.m_buffer[(int)segment].m_endNode; break; } } num++; num2++; num5 = num7; if (num5 == stops) { break; } if (!flag) { break; } if (++num6 >= 32768) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace); break; } } if (!flag) { return(flag); } RenderGroup.MeshData meshData = new RenderGroup.MeshData(); meshData.m_vertices = new Vector3[num2 * 8]; meshData.m_normals = new Vector3[num2 * 8]; meshData.m_tangents = new Vector4[num2 * 8]; meshData.m_uvs = new Vector2[num2 * 8]; meshData.m_uvs1 = new Vector2[num2 * 8]; meshData.m_colors = new Color32[num2 * 8]; meshData.m_triangles = new int[num2 * 30]; TransportManager.LineSegment[] array = new TransportManager.LineSegment[num]; Bezier3[] array2 = new Bezier3[num3]; int num8 = 0; int num9 = 0; int num10 = 0; float lengthScale = Mathf.Ceil(num4 / 64f) / num4; float num11 = 0f; num5 = stops; Vector3 vector = new Vector3(100000f, 100000f, 100000f); Vector3 vector2 = new Vector3(-100000f, -100000f, -100000f); num6 = 0; while (num5 != 0) { ushort num12 = 0; for (int j = 0; j < 8; j++) { ushort segment2 = instance2.m_nodes.m_buffer[(int)num5].GetSegment(j); if (segment2 != 0 && instance2.m_segments.m_buffer[(int)segment2].m_startNode == num5) { uint path2 = instance2.m_segments.m_buffer[(int)segment2].m_path; if (path2 != 0u && (instance3.m_pathUnits.m_buffer[(int)((UIntPtr)path2)].m_pathFindFlags & 4) != 0) { array[num8].m_curveStart = num10; Vector3 vector3; Vector3 vector4; TransportLine.FillPathSegments(path2, meshData, array2, ref num9, ref num10, ref num11, lengthScale, out vector3, out vector4); vector = Vector3.Min(vector, vector3); vector2 = Vector3.Max(vector2, vector4); array[num8].m_bounds.SetMinMax(vector3, vector4); array[num8].m_curveEnd = num10; } num12 = instance2.m_segments.m_buffer[(int)segment2].m_endNode; break; } } TransportLine.FillPathNode(instance2.m_nodes.m_buffer[(int)num5].m_position, meshData, num9); num8++; num9++; num5 = num12; if (num5 == stops) { break; } if (++num6 >= 32768) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace); break; } } while (!Monitor.TryEnter(instance.m_lineMeshData, SimulationManager.SYNCHRONIZE_TIMEOUT)) { } try { instance.m_lineMeshData[(int)lineID] = meshData; instance.m_lineSegments[(int)lineID] = array; instance.m_lineCurves[(int)lineID] = array2; transportLine.m_bounds.SetMinMax(vector, vector2); } finally { Monitor.Exit(instance.m_lineMeshData); } return(flag); }
protected override void SimulationStepImpl(int subStep) { if (this.m_linesUpdated) { this.m_linesUpdated = false; int num = this.m_updatedLines.Length; for (int i = 0; i < num; i++) { ulong num2 = this.m_updatedLines[i]; if (num2 != 0uL) { for (int j = 0; j < 64; j++) { if ((num2 & 1uL << j) != 0uL) { ushort num3 = (ushort)(i << 6 | j); if (this.m_lines.m_buffer[(int)num3].m_flags != TransportLine.Flags.None) { if (BusTransportLineAI.UpdatePaths(ref this.m_lines.m_buffer[(int)num3], num3) && BusTransportLineAI.UpdateMeshData(ref this.m_lines.m_buffer[(int)num3], num3)) //if (this.m_lines.m_buffer[(int)num3].UpdatePaths(num3) && this.m_lines.m_buffer[(int)num3].UpdateMeshData(num3)) { num2 &= ~(1uL << j); } } else { num2 &= ~(1uL << j); } } } this.m_updatedLines[i] = num2; if (num2 != 0uL) { this.m_linesUpdated = true; } } } } if (this.m_patchesDirty) { this.m_patchesDirty = false; int num4 = this.m_patches.Length; for (int k = 0; k < num4; k++) { TransportPatch transportPatch = this.m_patches[k]; int num5 = 0; while (transportPatch != null) { if (transportPatch.m_isDirty) { transportPatch.UpdateMeshData(); } transportPatch = transportPatch.m_nextPatch; if (++num5 >= 100) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace); break; } } } } if (subStep != 0) { int num6 = (int)(Singleton <SimulationManager> .instance.m_currentFrameIndex & 255u); int num7 = num6 * 1; int num8 = (num6 + 1) * 1 - 1; for (int l = num7; l <= num8; l++) { TransportLine.Flags flags = this.m_lines.m_buffer[l].m_flags; if ((flags & (TransportLine.Flags.Created | TransportLine.Flags.Temporary)) == TransportLine.Flags.Created) { this.m_lines.m_buffer[l].SimulationStep((ushort)l); } } if ((Singleton <SimulationManager> .instance.m_currentFrameIndex & 4095u) == 0u) { StatisticsManager instance = Singleton <StatisticsManager> .instance; StatisticBase statisticBase = instance.Acquire <StatisticArray>(StatisticType.AveragePassengers); for (int m = 0; m < 5; m++) { this.m_passengers[m].Update(); this.m_passengers[m].Reset(); statisticBase.Acquire <StatisticInt32>(m, 5).Set((int)(this.m_passengers[m].m_residentPassengers.m_averageCount + this.m_passengers[m].m_touristPassengers.m_averageCount)); } } } if (subStep <= 1) { int num9 = (int)(Singleton <SimulationManager> .instance.m_currentTickIndex & 1023u); int num10 = num9 * PrefabCollection <TransportInfo> .PrefabCount() >> 10; int num11 = ((num9 + 1) * PrefabCollection <TransportInfo> .PrefabCount() >> 10) - 1; for (int n = num10; n <= num11; n++) { TransportInfo prefab = PrefabCollection <TransportInfo> .GetPrefab((uint)n); if (prefab != null) { MilestoneInfo unlockMilestone = prefab.m_UnlockMilestone; if (unlockMilestone != null) { Singleton <UnlockManager> .instance.CheckMilestone(unlockMilestone, false, false); } } } } }
/* * In here I'm changing the prefabs to have my classes. This way, every time the game instantiates * a prefab that I've changed, that object will run my code. * The prefabs aren't available at the moment of creation of this class, that's why I keep trying to * run it on update. I want to make sure I make the switch as soon as they exist to prevent the game * from instantianting objects without my code. */ void TryReplacePrefabs() { NetCollection beautificationNetCollection = null; NetCollection roadsNetCollection = null; NetCollection publicTansportNetCollection = null; VehicleCollection garbageVehicleCollection = null; VehicleCollection policeVehicleCollection = null; VehicleCollection publicTansportVehicleCollection = null; VehicleCollection healthCareVehicleCollection = null; VehicleCollection fireDepartmentVehicleCollection = null; VehicleCollection industrialVehicleCollection = null; TransportCollection publicTransportTransportCollection = null; ToolController toolController = null; try { // NetCollections beautificationNetCollection = TryGetComponent <NetCollection>("Beautification"); if (beautificationNetCollection == null) { return; } roadsNetCollection = TryGetComponent <NetCollection>("Road"); if (roadsNetCollection == null) { return; } publicTansportNetCollection = TryGetComponent <NetCollection>("Public Transport"); if (publicTansportNetCollection == null) { return; } // VehicleCollections garbageVehicleCollection = TryGetComponent <VehicleCollection>("Garbage"); if (garbageVehicleCollection == null) { return; } policeVehicleCollection = TryGetComponent <VehicleCollection>("Police Department"); if (policeVehicleCollection == null) { return; } publicTansportVehicleCollection = TryGetComponent <VehicleCollection>("Public Transport"); if (publicTansportVehicleCollection == null) { return; } healthCareVehicleCollection = TryGetComponent <VehicleCollection>("Health Care"); if (healthCareVehicleCollection == null) { return; } fireDepartmentVehicleCollection = TryGetComponent <VehicleCollection>("Fire Department"); if (fireDepartmentVehicleCollection == null) { return; } industrialVehicleCollection = TryGetComponent <VehicleCollection>("Industrial"); if (industrialVehicleCollection == null) { return; } // Transports publicTransportTransportCollection = TryGetComponent <TransportCollection>("Public Transport"); if (publicTransportTransportCollection == null) { return; } // Tools toolController = TryGetComponent <ToolController>("Tool Controller"); if (toolController == null) { return; } } catch (Exception e) { Debug.Log("Traffic++: Unexpected " + e.GetType().Name + " getting required components: " + e.Message + "\n" + e.StackTrace + "\n"); return; } Debug.Log("Traffic++: Queueing prefabs for loading..."); Singleton <LoadingManager> .instance.QueueLoadingAction(ActionWrapper(() => { try { // roads ZonablePedestrianPathAI.Initialize(beautificationNetCollection, transform); ZonablePedestrianBridgeAI.Initialize(beautificationNetCollection, transform); LargeRoadWithBusLanesAI.Initialize(roadsNetCollection, transform); LargeRoadWithBusLanesBridgeAI.Initialize(roadsNetCollection, transform); if ((CSLTraffic.Options & OptionsManager.ModOptions.GhostMode) != OptionsManager.ModOptions.GhostMode) { // Transports BusTransportLineAI.Initialize(publicTansportNetCollection, publicTansportVehicleCollection, publicTransportTransportCollection, transform); // vehicles CustomAmbulanceAI.Initialize(healthCareVehicleCollection, transform); CustomBusAI.Initialize(publicTansportVehicleCollection, transform); CustomCargoTruckAI.Initialize(industrialVehicleCollection, transform); CustomFireTruckAI.Initialize(fireDepartmentVehicleCollection, transform); CustomGarbageTruckAI.Initialize(garbageVehicleCollection, transform); CustomHearseAI.Initialize(healthCareVehicleCollection, transform); CustomPoliceCarAI.Initialize(policeVehicleCollection, transform); //Tools CustomTransportTool.Initialize(toolController); } // Localization UpdateLocalization(); AddQueuedActionsToLoadingQueue(); } catch (KeyNotFoundException knf) { Debug.Log("Traffic++: Error initializing a prefab: " + knf.Message + "\n" + knf.StackTrace + "\n"); } catch (Exception e) { Debug.Log("Traffic++: Unexpected " + e.GetType().Name + " initializing prefabs: " + e.Message + "\n" + e.StackTrace + "\n"); } })); m_initialized = true; Debug.Log("Traffic++: Prefabs queued for loading."); }