Skip to content

Commit b3cc914

Browse files
Merge pull request #981 from FFXIV-CombatReborn/mergeWIP
pathfinding tweak
2 parents c6296b8 + a33e3b2 commit b3cc914

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

BossMod/Pathfinding/ThetaStar.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -387,38 +387,38 @@ private void VisitNeighbour(int parentIndex, int nodeX, int nodeY, int nodeIndex
387387
PathMinG = candidateMinG,
388388
Score = CalculateScore(destPixG, candidateMinG, candidateLeeway, nodeIndex)
389389
};
390-
391-
if (currentParentNode.Score >= Score.UnsafeImprove && altNode.Score == Score.JustBad) // don't leave safe cells if it requires going through bad cells
390+
ref var altnode = ref altNode;
391+
if ((currentParentNode.Score >= Score.Safe || currentParentNode.Score >= Score.UnsafeAsStart && altnode.PathLeeway < 0f) && altnode.Score == Score.JustBad) // don't leave safe cells if it requires going through bad cells
392392
return;
393393

394394
var grandParentIndex = currentParentNode.ParentIndex;
395-
396-
if (grandParentIndex != nodeIndex && _nodes[grandParentIndex].PathMinG >= currentParentNode.PathMinG)
395+
ref var grandparentnode = ref _nodes[grandParentIndex];
396+
if (grandParentIndex != nodeIndex && grandparentnode.PathMinG >= currentParentNode.PathMinG)
397397
{
398398
var (gx, gy) = _map.IndexToGrid(grandParentIndex);
399399

400400
// Attempt to see if we can go directly from grandparent to (nodeX, nodeY)
401-
if (LineOfSight(gx, gy, nodeX, nodeY, _nodes[grandParentIndex].GScore, out var losLeeway, out var losDist, out var losMinG))
401+
if (LineOfSight(gx, gy, nodeX, nodeY, grandparentnode.GScore, out var losLeeway, out var losDist, out var losMinG))
402402
{
403403
var losScore = CalculateScore(destPixG, losMinG, losLeeway, nodeIndex);
404-
if (losScore >= altNode.Score)
404+
if (losScore >= altnode.Score)
405405
{
406406
parentIndex = grandParentIndex;
407-
altNode.GScore = _nodes[parentIndex].GScore + _deltaGSide * losDist;
408-
altNode.ParentIndex = grandParentIndex;
409-
altNode.PathLeeway = losLeeway;
410-
altNode.PathMinG = losMinG;
411-
altNode.Score = losScore;
407+
altnode.GScore = _nodes[parentIndex].GScore + _deltaGSide * losDist;
408+
altnode.ParentIndex = grandParentIndex;
409+
altnode.PathLeeway = losLeeway;
410+
altnode.PathMinG = losMinG;
411+
altnode.Score = losScore;
412412
}
413413
}
414414
}
415415

416-
var visit = destNode.OpenHeapIndex == 0 || CompareNodeScores(ref altNode, ref destNode) < (destNode.OpenHeapIndex < 0 ? -1 : 0);
416+
var visit = destNode.OpenHeapIndex == 0 || CompareNodeScores(ref altnode, ref destNode) < (destNode.OpenHeapIndex < 0 ? -1 : 0);
417417
if (visit)
418418
{
419419
if (destNode.OpenHeapIndex < 0)
420420
++NumReopens;
421-
destNode = altNode;
421+
destNode = altnode;
422422
AddToOpen(nodeIndex);
423423
}
424424
}

0 commit comments

Comments
 (0)