From d85f7ccfbc01e0c66a454e809928be0af8247937 Mon Sep 17 00:00:00 2001 From: seiggy Date: Mon, 13 Jul 2015 22:32:18 -0400 Subject: [PATCH] More AI Refactoring and Code Cleanup --- TLM/TLM/CustomAI/CustomRoadAI.cs | 2 +- TLM/TLM/CustomAI/CustomTransportLineAI.cs | 59 +++++++++++------------ 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/TLM/TLM/CustomAI/CustomRoadAI.cs b/TLM/TLM/CustomAI/CustomRoadAI.cs index ab6fe2d1..097c8019 100644 --- a/TLM/TLM/CustomAI/CustomRoadAI.cs +++ b/TLM/TLM/CustomAI/CustomRoadAI.cs @@ -10,7 +10,7 @@ class CustomRoadAI : RoadBaseAI { public static Dictionary NodeDictionary = new Dictionary(); - private uint _lastFrame = 0; + private uint _lastFrame; public void Awake() { diff --git a/TLM/TLM/CustomAI/CustomTransportLineAI.cs b/TLM/TLM/CustomAI/CustomTransportLineAI.cs index 0b2c3f27..b99e5d8a 100644 --- a/TLM/TLM/CustomAI/CustomTransportLineAI.cs +++ b/TLM/TLM/CustomAI/CustomTransportLineAI.cs @@ -1,11 +1,10 @@ using ColossalFramework; -using UnityEngine; namespace TrafficManager.CustomAI { class CustomTransportLineAI { - protected static bool StartPathFind(ushort segmentID, ref NetSegment data, ItemClass.Service netService, VehicleInfo.VehicleType vehicleType, bool skipQueue) + protected static bool StartPathFind(ushort segmentId, ref NetSegment data, ItemClass.Service netService, VehicleInfo.VehicleType vehicleType, bool skipQueue) { if (data.m_path != 0u) { @@ -13,30 +12,30 @@ protected static bool StartPathFind(ushort segmentID, ref NetSegment data, ItemC data.m_path = 0u; } NetManager instance = Singleton.instance; - if ((instance.m_nodes.m_buffer[(int)data.m_startNode].m_flags & NetNode.Flags.Ambiguous) != NetNode.Flags.None) + if ((instance.m_nodes.m_buffer[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) + ushort segment = instance.m_nodes.m_buffer[data.m_startNode].GetSegment(i); + if (segment != 0 && segment != segmentId && instance.m_segments.m_buffer[segment].m_path != 0u) { return true; } } } - if ((instance.m_nodes.m_buffer[(int)data.m_endNode].m_flags & NetNode.Flags.Ambiguous) != NetNode.Flags.None) + if ((instance.m_nodes.m_buffer[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) + ushort segment2 = instance.m_nodes.m_buffer[data.m_endNode].GetSegment(j); + if (segment2 != 0 && segment2 != segmentId && instance.m_segments.m_buffer[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; + var position = instance.m_nodes.m_buffer[data.m_startNode].m_position; + var position2 = instance.m_nodes.m_buffer[data.m_endNode].m_position; PathUnit.Position startPosA; PathUnit.Position startPosB; float num; @@ -53,11 +52,11 @@ protected static bool StartPathFind(ushort segmentID, ref NetSegment data, ItemC { return true; } - if ((instance.m_nodes.m_buffer[(int)data.m_startNode].m_flags & NetNode.Flags.Fixed) != NetNode.Flags.None) + if ((instance.m_nodes.m_buffer[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) + if ((instance.m_nodes.m_buffer[data.m_endNode].m_flags & NetNode.Flags.Fixed) != NetNode.Flags.None) { endPosB = default(PathUnit.Position); } @@ -65,10 +64,10 @@ protected static bool StartPathFind(ushort segmentID, ref NetSegment data, ItemC startPosB.m_offset = 128; endPosA.m_offset = 128; endPosB.m_offset = 128; - bool stopLane = CustomTransportLineAI.GetStopLane(ref startPosA, vehicleType); - bool stopLane2 = CustomTransportLineAI.GetStopLane(ref startPosB, vehicleType); - bool stopLane3 = CustomTransportLineAI.GetStopLane(ref endPosA, vehicleType); - bool stopLane4 = CustomTransportLineAI.GetStopLane(ref endPosB, vehicleType); + bool stopLane = GetStopLane(ref startPosA, vehicleType); + bool stopLane2 = GetStopLane(ref startPosB, vehicleType); + bool stopLane3 = GetStopLane(ref endPosA, vehicleType); + bool stopLane4 = GetStopLane(ref endPosB, vehicleType); if ((!stopLane && !stopLane2) || (!stopLane3 && !stopLane4)) { return true; @@ -78,27 +77,27 @@ protected static bool StartPathFind(ushort segmentID, ref NetSegment data, ItemC { 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); + var expr_2D9Cp0 = instance.m_nodes.m_buffer; + var expr_2D9Cp1 = data.m_startNode; + expr_2D9Cp0[expr_2D9Cp1].m_flags = (expr_2D9Cp0[expr_2D9Cp1].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); + var expr305Cp0 = instance.m_nodes.m_buffer; + var expr305Cp1 = data.m_startNode; + expr305Cp0[expr305Cp1].m_flags = (expr305Cp0[expr305Cp1].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); + var expr344Cp0 = instance.m_nodes.m_buffer; + var expr344Cp1 = data.m_endNode; + expr344Cp0[expr344Cp1].m_flags = (expr344Cp0[expr344Cp1].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); + var expr370Cp0 = instance.m_nodes.m_buffer; + var expr370Cp1 = data.m_endNode; + expr370Cp0[expr370Cp1].m_flags = (expr370Cp0[expr370Cp1].m_flags & ~NetNode.Flags.Ambiguous); } data.m_path = path; data.m_flags |= NetSegment.Flags.WaitingPath; @@ -111,10 +110,10 @@ private static bool GetStopLane(ref PathUnit.Position pos, VehicleInfo.VehicleTy { if (pos.m_segment != 0) { - NetManager instance = Singleton.instance; + var instance = Singleton.instance; int num; uint num2; - if (instance.m_segments.m_buffer[(int)pos.m_segment].GetClosestLane((int)pos.m_lane, NetInfo.LaneType.Vehicle, vehicleType, out num, out num2)) + if (instance.m_segments.m_buffer[pos.m_segment].GetClosestLane(pos.m_lane, NetInfo.LaneType.Vehicle, vehicleType, out num, out num2)) { pos.m_lane = (byte)num; return true;