Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vehicle stop at yield sign if no traffic #662

Merged
merged 2 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TLM/TLM/Custom/AI/CustomCarAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ public void CustomCalculateSegmentPosition(ushort vehicleId,
ref netManager.m_nodes.m_buffer[nextSourceNodeId],
nextLaneId,
ref nextNextPosition,
nextTargetNodeId)) {
nextTargetNodeId,
out maxSpeed)) {
// NON-STOCK CODE
maxSpeed = 0;
return;
}

Expand Down
3 changes: 2 additions & 1 deletion TLM/TLM/Custom/AI/CustomTrainAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,8 @@ public void CustomCheckNextLane(ushort vehicleId,
ref nextPosition,
refTargetNodeId,
ref netManager.m_nodes.m_buffer[refTargetNodeId],
nextLaneId)) {
nextLaneId,
out maxSpeed)) {
#if DEBUG
if (logLogic) {
Log._Debug($"CustomTrainAI.CustomCheckNextLane({vehicleId}): " +
Expand Down
3 changes: 2 additions & 1 deletion TLM/TLM/Custom/AI/CustomTramBaseAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ public void CustomCalculateSegmentPosition(ushort vehicleId,
ref netManager.m_nodes.m_buffer[prevSourceNodeId],
prevLaneId,
ref nextPosition,
prevTargetNodeId)) {
prevTargetNodeId,
out maxSpeed)) {
maxSpeed = 0;
return;
}
Expand Down
4 changes: 1 addition & 3 deletions TLM/TLM/Manager/Impl/ExtVehicleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,6 @@ public void UpdatePosition(ref ExtVehicle extVehicle,
extVehicle.nextLaneIndex = nextPos.m_lane;
}

bool startNode = IsTransitNodeCurStartNode(ref curPos, ref nextPos);

if (extVehicle.currentSegmentId != segEnd.segmentId ||
extVehicle.currentStartNode != segEnd.startNode ||
extVehicle.currentLaneIndex != curPos.m_lane) {
Expand Down Expand Up @@ -836,7 +834,7 @@ public void UpdateDynamicLaneSelectionParameters(ref ExtVehicle extVehicle) {
extVehicle.dlsReady = true;
}

[UsedImplicitly]
// [UsedImplicitly]
private static ushort GetTransitNodeId(ref PathUnit.Position curPos,
ref PathUnit.Position nextPos) {
bool startNode = IsTransitNodeCurStartNode(ref curPos, ref nextPos);
Expand Down
19 changes: 13 additions & 6 deletions TLM/TLM/Manager/Impl/VehicleBehaviorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,8 @@ public bool MayChangeSegment(ushort frontVehicleId,
ref PathUnit.Position position,
ushort targetNodeId,
ref NetNode targetNode,
uint laneID)
{
uint laneID,
out float maxSpeed) {
VehicleJunctionTransitState transitState = MayChangeSegment(
frontVehicleId,
ref Constants.ManagerFactory.ExtVehicleManager.ExtVehicles[frontVehicleId],
Expand All @@ -1031,7 +1031,8 @@ public bool MayChangeSegment(ushort frontVehicleId,
ref targetNode,
laneID,
ref DUMMY_POS,
0);
0,
out maxSpeed);

Constants.ManagerFactory.ExtVehicleManager.SetJunctionTransitState(
ref Constants.ManagerFactory.ExtVehicleManager.ExtVehicles[frontVehicleId],
Expand Down Expand Up @@ -1071,7 +1072,8 @@ public bool MayChangeSegment(ushort frontVehicleId,
ref NetNode targetNode,
uint laneID,
ref PathUnit.Position nextPosition,
ushort nextTargetNodeId) {
ushort nextTargetNodeId,
out float maxSpeed) {
VehicleJunctionTransitState transitState = MayChangeSegment(
frontVehicleId,
ref Constants.ManagerFactory.ExtVehicleManager.ExtVehicles[frontVehicleId],
Expand All @@ -1086,7 +1088,8 @@ public bool MayChangeSegment(ushort frontVehicleId,
ref targetNode,
laneID,
ref nextPosition,
nextTargetNodeId);
nextTargetNodeId,
out maxSpeed);

Constants.ManagerFactory.ExtVehicleManager.SetJunctionTransitState(
ref Constants.ManagerFactory.ExtVehicleManager.ExtVehicles[frontVehicleId],
Expand All @@ -1110,14 +1113,16 @@ protected VehicleJunctionTransitState MayChangeSegment(
ref NetNode targetNode,
uint laneId,
ref PathUnit.Position nextPosition,
ushort nextTargetNodeId)
ushort nextTargetNodeId,
out float maxSpeed)
{
#if DEBUG
bool logPriority = DebugSwitch.PriorityRules.Get() &&
(DebugSettings.NodeId <= 0 || targetNodeId == DebugSettings.NodeId);
#else
const bool logPriority = false;
#endif
maxSpeed = 0;
if (prevTargetNodeId != targetNodeId
|| (vehicleData.m_blockCounter == 255
&& !Instance.MayDespawn(ref vehicleData)) // NON-STOCK CODE
Expand Down Expand Up @@ -1595,6 +1600,8 @@ ref segEndMan.ExtSegmentEnds[
() => $"VehicleBehaviorManager.MayChangeSegment({frontVehicleId}): " +
$"Vehicle has not yet reached yield speed (sqrVelocity={sqrVelocity})");

//slow down to target speed
maxSpeed = GlobalConfig.Instance.PriorityRules.MaxYieldVelocity;
// vehicle has not yet reached yield speed
return VehicleJunctionTransitState.Stop;
}
Expand Down