fix calculation of link weight

This commit is contained in:
in0finite 2022-02-20 05:20:54 +01:00
parent 30f69225ea
commit f325ff298b

View file

@ -190,7 +190,7 @@ namespace SanAndreasUnity.Behaviours
if (idM.Equals(targetId))
{
var dataM = GetResettedData();
dataM.g = dataN.g + link.Length;
dataM.g = dataN.g + CalculateLinkWeight(idN, idM);
float h = CalculateHeuristic(idM, targetId);
dataM.f = dataM.g + h;
dataM.parentId = idN;
@ -205,7 +205,7 @@ namespace SanAndreasUnity.Behaviours
if (openList.Contains(idM))
{
float gNew = dataN.g + link.Length;
float gNew = dataN.g + CalculateLinkWeight(idN, idM);
float hNew = CalculateHeuristic(idM, targetId);
float fNew = gNew + hNew;
@ -230,7 +230,7 @@ namespace SanAndreasUnity.Behaviours
else
{
var dataM = GetResettedData();
dataM.g = dataN.g + link.Length;
dataM.g = dataN.g + CalculateLinkWeight(idN, idM);
float h = CalculateHeuristic(idM, targetId);
dataM.f = dataM.g + h;
dataM.parentId = idN;
@ -266,6 +266,11 @@ namespace SanAndreasUnity.Behaviours
return NodeReader.GetDistanceBetweenNodes(source, destination);
}
private float CalculateLinkWeight(PathNodeId parentId, PathNodeId neighbourId)
{
return NodeReader.GetDistanceBetweenNodes(parentId, neighbourId);
}
private void RestoreModifiedDatas()
{
foreach (var id in m_modifiedDatas)