Skip to content

Commit

Permalink
Highway rules work again, info message on routing recalculation
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorPhilipp committed May 7, 2017
1 parent 1e78192 commit ae7be3f
Show file tree
Hide file tree
Showing 19 changed files with 376 additions and 262 deletions.
2 changes: 1 addition & 1 deletion TLM/TLM/Custom/AI/CustomRoadAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public void CustomClickNodeButton(ushort nodeID, ref NetNode data, int index) {
/*data.m_flags ^= NetNode.Flags.TrafficLights;
data.m_flags |= NetNode.Flags.CustomTrafficLights;*/
// NON-STOCK CODE START
ToggleTrafficLightsTool toggleTool = (ToggleTrafficLightsTool)LoadingExtension.TrafficManagerTool.GetSubTool(ToolMode.SwitchTrafficLight);
ToggleTrafficLightsTool toggleTool = (ToggleTrafficLightsTool)UIBase.GetTrafficManagerTool(true).GetSubTool(ToolMode.SwitchTrafficLight);
toggleTool.ToggleTrafficLight(nodeID, false);
// NON-STOCK CODE END
this.UpdateNodeFlags(nodeID, ref data);
Expand Down
27 changes: 18 additions & 9 deletions TLM/TLM/Custom/PathFinding/CustomPathFind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -893,12 +893,13 @@ private void ProcessItemMain(uint unitId, BufferItem item, ref NetSegment prevSe
// we are going to a non-pedestrian lane

bool allowPedestrian = (byte)(this._laneTypes & NetInfo.LaneType.Pedestrian) != 0; // allow pedestrian switching to vehicle?
bool isPedestrianSwitchingToBicycleAtBeautificationNode = false;
bool nextIsBeautificationNode = nextNode.Info.m_class.m_service == ItemClass.Service.Beautification;
bool allowPedestrians = false; // is true if cim is using a bike
byte parkingConnectOffset = 0;
if (allowPedestrian) {
if (prevIsBicycleLane) {
parkingConnectOffset = connectOffset;
isPedestrianSwitchingToBicycleAtBeautificationNode = (nextNode.Info.m_class.m_service == ItemClass.Service.Beautification);
allowPedestrians = nextIsBeautificationNode;
} else if (this._vehicleLane != 0u) {
// there is a parked vehicle position
if (this._vehicleLane != item.m_laneID) {
Expand Down Expand Up @@ -932,7 +933,7 @@ private void ProcessItemMain(uint unitId, BufferItem item, ref NetSegment prevSe
continue;
}

this.ProcessItemCosts(debug, item, nextNodeId, nextSegmentId, ref prevSegment, ref prevSegmentRouting, ref netManager.m_segments.m_buffer[nextSegmentId], ref prevSimilarLaneIndexFromInner, connectOffset, true, isPedestrianSwitchingToBicycleAtBeautificationNode);
this.ProcessItemCosts(debug, item, nextNodeId, nextSegmentId, ref prevSegment, ref prevSegmentRouting, ref netManager.m_segments.m_buffer[nextSegmentId], ref prevSimilarLaneIndexFromInner, connectOffset, true, allowPedestrians);
}

if ((nextNode.m_flags & (NetNode.Flags.End | NetNode.Flags.Bend | NetNode.Flags.Junction)) != NetNode.Flags.None &&
Expand All @@ -948,6 +949,7 @@ private void ProcessItemMain(uint unitId, BufferItem item, ref NetSegment prevSe
SegmentEndGeometry prevEndGeometry = prevGeometry.GetEnd(nextIsStartNode);*/
bool prevIsOutgoingOneWay = nextIsStartNode ? prevSegmentRouting.startNodeOutgoingOneWay : prevSegmentRouting.endNodeOutgoingOneWay;
//bool nextIsRealJunction = prevEndGeometry.NumConnectedSegments > 1;
bool nextIsUntouchable = (nextNode.m_flags & (NetNode.Flags.Untouchable)) != NetNode.Flags.None;
bool nextIsTransitionOrJunction = (nextNode.m_flags & (NetNode.Flags.Junction | NetNode.Flags.Transition)) != NetNode.Flags.None;
bool nextIsBend = (nextNode.m_flags & (NetNode.Flags.Bend)) != NetNode.Flags.None;
bool nextIsEndOrOneWayOut = (nextNode.m_flags & (NetNode.Flags.End | NetNode.Flags.OneWayOut)) != NetNode.Flags.None;
Expand All @@ -958,14 +960,15 @@ private void ProcessItemMain(uint unitId, BufferItem item, ref NetSegment prevSe
nextIsEndOrOneWayOut || // stock u-turn points
(Options.junctionRestrictionsEnabled &&
isCustomUturnAllowed && // only do u-turns if allowed
!isPedestrianSwitchingToBicycleAtBeautificationNode && // no u-turn at beautification nodes
!nextIsBeautificationNode && // no u-turns at beautification nodes
_isRoadVehicle && // only road vehicles may perform u-turns
!_isHeavyVehicle && // only small vehicles may perform u-turns
(nextIsTransitionOrJunction || nextIsBend) && // perform u-turns at transitions, junctions and bend nodes
!prevIsOutgoingOneWay); // do not u-turn on one-ways

bool isStrictLaneArrowPolicyEnabled =
!isPedestrianSwitchingToBicycleAtBeautificationNode && // do not obey lane arrows at beautification nodes
!nextIsBeautificationNode && // do not obey lane arrows at beautification nodes
!nextIsUntouchable &&
_isLaneArrowObeyingEntity &&
nextIsTransitionOrJunction && // follow lane arrows only at transitions and junctions
!(
Expand All @@ -974,6 +977,8 @@ private void ProcessItemMain(uint unitId, BufferItem item, ref NetSegment prevSe
#endif
(Options.relaxedBusses && _extVehicleType == ExtVehicleType.Bus)); // option: busses may ignore lane arrows

bool useRouting = prevLaneEndRouting.routed && !nextIsBeautificationNode;

bool handleStockUturn = !explorePrevSegment;
bool stockUturn = false;

Expand All @@ -992,18 +997,20 @@ private void ProcessItemMain(uint unitId, BufferItem item, ref NetSegment prevSe
"\t" + $"prevIsOutgoingOneWay={prevIsOutgoingOneWay}\n" +
"\t" + $"prevLaneHasRouting={prevLaneEndRouting.routed}\n\n" +
"\t" + $"nextIsStartNode={nextIsStartNode}\n" +
"\t" + $"isNextBeautificationNode={nextIsBeautificationNode}\n" +
//"\t" + $"nextIsRealJunction={nextIsRealJunction}\n" +
"\t" + $"nextIsBend={nextIsBend}\n" +
"\t" + $"nextIsUntouchable={nextIsUntouchable}\n" +
"\t" + $"nextIsEndOrOneWayOut={nextIsEndOrOneWayOut}\n\n" +
"\t" + $"isPedestrianSwitchingToBicycleAtBeautificationNode={isPedestrianSwitchingToBicycleAtBeautificationNode}\n" +
"\t" + $"allowPedestrians={allowPedestrians}\n" +
"\t" + $"isCustomUturnAllowed={isCustomUturnAllowed}\n" +
"\t" + $"explorePrevSegment={explorePrevSegment}\n" +
"\t" + $"isStrictLaneArrowPolicyEnabled={isStrictLaneArrowPolicyEnabled}\n" +
"\t" + $"handleStockUturn={handleStockUturn}\n"
);
#endif

if (!prevLaneEndRouting.routed || isPedestrianSwitchingToBicycleAtBeautificationNode) {
if (allowPedestrians || !prevLaneEndRouting.routed) {
/* pedestrian to bicycle switch or no routing information available */

#if DEBUGNEWPF
Expand All @@ -1025,13 +1032,15 @@ private void ProcessItemMain(uint unitId, BufferItem item, ref NetSegment prevSe
break;
}

if (ProcessItemCosts(debug, item, nextNodeId, nextSegmentId, ref prevSegment, ref prevSegmentRouting, ref netManager.m_segments.m_buffer[nextSegmentId], ref prevSimilarLaneIndexFromInner, connectOffset, !prevLaneEndRouting.routed, true)) {
if (ProcessItemCosts(debug, item, nextNodeId, nextSegmentId, ref prevSegment, ref prevSegmentRouting, ref netManager.m_segments.m_buffer[nextSegmentId], ref prevSimilarLaneIndexFromInner, connectOffset, !prevLaneEndRouting.routed, allowPedestrians)) {
stockUturn = true;
}

nextSegmentId = netManager.m_segments.m_buffer[nextSegmentId].GetRightSegment(nextNodeId);
}
} else {
}

if (prevLaneEndRouting.routed) {
/* routed vehicle paths */

#if DEBUGNEWPF
Expand Down
63 changes: 5 additions & 58 deletions TLM/TLM/LoadingExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public static bool IsRushHourLoaded {
public static CustomPathManager CustomPathManager { get; set; }
public static bool DetourInited { get; set; }
public static List<Detour> Detours { get; set; }
public static TrafficManagerMode ToolMode { get; set; }
public static TrafficManagerTool TrafficManagerTool { get; set; }
//public static TrafficManagerMode ToolMode { get; set; }
//public static TrafficManagerTool TrafficManagerTool { get; set; }
#if !TAM
public static UIBase BaseUI { get; private set; }
#endif
Expand Down Expand Up @@ -1749,7 +1749,6 @@ public override void OnCreated(ILoading loading) {

base.OnCreated(loading);

ToolMode = TrafficManagerMode.None;
Detours = new List<Detour>();
RegisteredManagers = new List<ICustomManager>();
DetourInited = false;
Expand Down Expand Up @@ -1782,10 +1781,7 @@ private void RegisterCustomManagers() {
public override void OnReleased() {
base.OnReleased();

if (ToolMode != TrafficManagerMode.None) {
ToolMode = TrafficManagerMode.None;
DestroyTool();
}
UIBase.ReleaseTool();
}

public override void OnLevelUnloading() {
Expand Down Expand Up @@ -1938,8 +1934,8 @@ public override void OnLevelLoaded(LoadMode mode) {
manager.OnLevelLoading();
}

InitTool();
Log._Debug($"Current tool: {ToolManager.instance.m_properties.CurrentTool}");
//InitTool();
//Log._Debug($"Current tool: {ToolManager.instance.m_properties.CurrentTool}");

Log.Info("OnLevelLoaded complete.");
}
Expand Down Expand Up @@ -1992,54 +1988,5 @@ private bool Check3rdPartyModLoaded(string namespaceStr, bool printAll=false) {

return thirdPartyModLoaded;
}

public static void SetToolMode(TrafficManagerMode mode) {
if (mode == ToolMode) return;

ToolMode = mode;

if (mode != TrafficManagerMode.None) {
EnableTool();
} else {
DisableTool();
}
}

public static void InitTool() {
Log.Info("Initializing traffic manager tool...");
if (TrafficManagerTool == null) {
TrafficManagerTool = ToolsModifierControl.toolController.gameObject.GetComponent<TrafficManagerTool>() ??
ToolsModifierControl.toolController.gameObject.AddComponent<TrafficManagerTool>();
}

TrafficManagerTool.Initialize();
}

public static void EnableTool() {
Log._Debug("LoadingExtension.EnabledTool: called");
InitTool();

ToolsModifierControl.toolController.CurrentTool = TrafficManagerTool;
ToolsModifierControl.SetTool<TrafficManagerTool>();
}

public static void DisableTool() {
Log._Debug("LoadingExtension.DisableTool: called");
ToolsModifierControl.toolController.CurrentTool = ToolsModifierControl.GetTool<DefaultTool>();
ToolsModifierControl.SetTool<DefaultTool>();
}

private static void DestroyTool() {
if (ToolsModifierControl.toolController != null) {
ToolsModifierControl.toolController.CurrentTool = ToolsModifierControl.GetTool<DefaultTool>();
ToolsModifierControl.SetTool<DefaultTool>();

if (TrafficManagerTool != null) {
Object.Destroy(TrafficManagerTool);
TrafficManagerTool = null;
}
} else
Log.Warning("LoadingExtensions.DestroyTool: ToolsModifierControl.toolController is null!");
}
}
}
2 changes: 1 addition & 1 deletion TLM/TLM/Manager/LaneArrowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public bool ToggleLaneArrows(uint laneId, bool startNode, LaneArrows flags, out

protected void OnLaneChange(uint laneId) {
Services.NetService.ProcessLane(laneId, delegate (uint lId, ref NetLane lane) {
RoutingManager.Instance.RecalculateSegment(lane.m_segment);
RoutingManager.Instance.RequestRecalculation(lane.m_segment);
SubscribeToSegmentGeometry(lane.m_segment);
if (Options.instantEffects) {
Services.NetService.PublishSegmentChanges(lane.m_segment);
Expand Down
12 changes: 6 additions & 6 deletions TLM/TLM/Manager/LaneConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ internal bool RemoveLaneConnection(uint laneId1, uint laneId2, bool startNode1)
UnsubscribeFromSegmentGeometry(segmentId1);
UnsubscribeFromSegmentGeometry(segmentId2);

RoutingManager.Instance.RecalculateSegment(segmentId1, false);
RoutingManager.Instance.RecalculateSegment(segmentId2, false);
RoutingManager.Instance.RequestRecalculation(segmentId1, false);
RoutingManager.Instance.RequestRecalculation(segmentId2, false);

if (Options.instantEffects) {
Services.NetService.PublishSegmentChanges(segmentId1);
Expand Down Expand Up @@ -189,7 +189,7 @@ internal void RemoveLaneConnectionsFromSegment(ushort segmentId, bool startNode,
});

if (recalcAndPublish) {
RoutingManager.Instance.RecalculateSegment(segmentId);
RoutingManager.Instance.RequestRecalculation(segmentId);
if (Options.instantEffects) {
Services.NetService.PublishSegmentChanges(segmentId);
}
Expand Down Expand Up @@ -236,7 +236,7 @@ internal void RemoveLaneConnections(uint laneId, bool startNode, bool recalcAndP
}

if (recalcAndPublish) {
RoutingManager.Instance.RecalculateSegment(lane.m_segment);
RoutingManager.Instance.RequestRecalculation(lane.m_segment);

if (Options.instantEffects) {
Services.NetService.PublishSegmentChanges(lane.m_segment);
Expand Down Expand Up @@ -275,8 +275,8 @@ internal bool AddLaneConnection(uint sourceLaneId, uint targetLaneId, bool sourc
JunctionRestrictionsManager.Instance.SetUturnAllowed(sourceSegmentId, sourceStartNode, true);
}

RoutingManager.Instance.RecalculateSegment(sourceSegmentId, false);
RoutingManager.Instance.RecalculateSegment(targetSegmentId, false);
RoutingManager.Instance.RequestRecalculation(sourceSegmentId, false);
RoutingManager.Instance.RequestRecalculation(targetSegmentId, false);

SubscribeToSegmentGeometry(sourceSegmentId);
SubscribeToSegmentGeometry(targetSegmentId);
Expand Down
Loading

0 comments on commit ae7be3f

Please sign in to comment.