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

Trains maintain their lanes #236

Merged
merged 5 commits into from
Mar 14, 2019
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
31 changes: 26 additions & 5 deletions TLM/TLM/Custom/PathFinding/CustomPathFind2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1963,15 +1963,19 @@ private bool ProcessItemCosts(

float baseLength = offsetLength / (prevLaneSpeed * m_maxLength); // NON-STOCK CODE
float comparisonValue = item.m_comparisonValue; // NON-STOCK CODE
#if ADVANCEDAI && ROUTING
#if ROUTING
#if DEBUG
if (debug) {
Debug(unitId, item, nextSegmentId, $"ProcessItemCosts: Calculated base length\n"
+ "\t" + $"baseLength={baseLength}"
);
}
#endif
if (!enableAdvancedAI) {
if (
#if ADVANCEDAI
!enableAdvancedAI &&
#endif
!m_stablePath) {
comparisonValue += baseLength;
}
#endif
Expand Down Expand Up @@ -2043,9 +2047,8 @@ private bool ProcessItemCosts(
#endif
return blocked;
}
#if ADVANCEDAI

laneDist = trans.distance;
#endif
#if DEBUG
if (debug) {
Debug(unitId, item, nextSegmentId, $"ProcessItemCosts: Custom transition given\n"
Expand Down Expand Up @@ -2235,7 +2238,8 @@ private bool ProcessItemCosts(
// NON-STOCK CODE END
#endif

#if ADVANCEDAI && ROUTING
#if ROUTING
#if ADVANCEDAI
if (enableAdvancedAI) {
float adjustedBaseLength = baseLength;
if (m_queueItem.spawned || (nextLaneId != m_startLaneA && nextLaneId != m_startLaneB)) {
Expand All @@ -2260,6 +2264,23 @@ private bool ProcessItemCosts(
+ "\t" + $"laneChangingCost={laneChangingCost}"
);
}
#endif
} else
#endif
if (m_stablePath) {
// all non-road vehicles with stable paths (trains, trams, etc.): apply lane distance factor
float adjustedBaseLength = baseLength;
adjustedBaseLength *= 1 + laneDist;
nextItem.m_comparisonValue += adjustedBaseLength;

#if DEBUG
if (debug) {
Debug(unitId, item, nextSegmentId, nextLaneIndex, nextLaneId, $"ProcessItemCosts: Applied stable path lane distance costs\n"
+ "\t" + $"baseLength={baseLength}\n"
+ "\t" + $"adjustedBaseLength={adjustedBaseLength}\n"
+ "\t" + $"laneDist={laneDist}"
);
}
#endif
}
#endif
Expand Down
9 changes: 8 additions & 1 deletion TLM/TLM/Manager/Impl/RoutingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,14 @@ protected void RecalculateLaneEndRoutingData(ushort segmentId, int laneIndex, ui
transitionType = LaneEndTransitionType.Default;

if (numNextForcedTransitionDatas < MAX_NUM_TRANSITIONS) {
nextForcedTransitionDatas[numNextForcedTransitionDatas++].Set(nextLaneId, nextLaneIndex, transitionType, nextSegmentId, isNextStartNodeOfNextSegment);
nextForcedTransitionDatas[numNextForcedTransitionDatas].Set(nextLaneId, nextLaneIndex, transitionType, nextSegmentId, isNextStartNodeOfNextSegment);

if (! isNextRealJunction) {
// simple forced lane transition: set lane distance
nextForcedTransitionDatas[numNextForcedTransitionDatas].distance = (byte)Math.Abs(prevOuterSimilarLaneIndex - nextOuterSimilarLaneIndex);
}

++numNextForcedTransitionDatas;
} else {
Log.Warning($"nextForcedTransitionDatas overflow @ source lane {prevLaneId}, idx {prevLaneIndex} @ seg. {prevSegmentId}");
}
Expand Down