Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Commit

Permalink
More AI Refactoring and Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
seiggy committed Jul 14, 2015
1 parent 47cca04 commit d85f7cc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion TLM/TLM/CustomAI/CustomRoadAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CustomRoadAI : RoadBaseAI
{
public static Dictionary<ushort, TrafficLightSimulation> NodeDictionary = new Dictionary<ushort, TrafficLightSimulation>();

private uint _lastFrame = 0;
private uint _lastFrame;

public void Awake()
{
Expand Down
59 changes: 29 additions & 30 deletions TLM/TLM/CustomAI/CustomTransportLineAI.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
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)
{
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)
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;
Expand All @@ -53,22 +52,22 @@ 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);
}
startPosA.m_offset = 128;
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;
Expand All @@ -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;
Expand All @@ -111,10 +110,10 @@ private static bool GetStopLane(ref PathUnit.Position pos, VehicleInfo.VehicleTy
{
if (pos.m_segment != 0)
{
NetManager instance = Singleton<NetManager>.instance;
var instance = Singleton<NetManager>.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;
Expand Down

0 comments on commit d85f7cc

Please sign in to comment.