extract method

This commit is contained in:
in0finite 2021-09-11 04:09:19 +02:00
parent 167e313456
commit 6b66065ba5
2 changed files with 25 additions and 14 deletions

View file

@ -158,19 +158,9 @@ namespace SanAndreasUnity.Behaviours
private static PathNode GetNextPathNode(PathNode previousNode, PathNode currentNode)
{
var possibilities = new List<PathNode>();
var currentNodeArea = NodeReader.GetAreaById(currentNode.AreaID);
for (int i = 0; i < currentNode.LinkCount; i++)
{
NodeLink link = currentNodeArea.NodeLinks[currentNode.BaseLinkID + i];
NodeFile targetArea = NodeReader.GetAreaById(link.AreaID);
PathNode targetNode = targetArea.GetPedNodeById(link.NodeID);
if (!targetNode.Equals(previousNode))
possibilities.Add(targetNode);
}
var possibilities = new List<PathNode>(
NodeReader.GetAllAdjacentNodes(currentNode)
.Where(_ => !_.Equals(previousNode)));
if (possibilities.Count > 0)
{
@ -181,7 +171,6 @@ namespace SanAndreasUnity.Behaviours
//No possibilities found, returning to previous node
return previousNode;
}
}
}

View file

@ -115,6 +115,21 @@ namespace SanAndreasUnity.Importing.Paths
{
return NodeFiles[id];
}
public static IEnumerable<PathNode> GetAllAdjacentNodes(PathNode pathNode)
{
var nodeArea = GetAreaById(pathNode.AreaID);
for (int i = 0; i < pathNode.LinkCount; i++)
{
NodeLink link = nodeArea.NodeLinks[pathNode.BaseLinkID + i];
NodeFile targetArea = GetAreaById(link.AreaID);
PathNode targetNode = targetArea.GetNodeById(link.NodeID);
yield return targetNode;
}
}
}
public class NodeFile
@ -278,6 +293,13 @@ namespace SanAndreasUnity.Importing.Paths
return PedNodes[nodeId - NumOfVehNodes];
}
public PathNode GetNodeById(int nodeId)
{
if (nodeId < NumOfVehNodes)
return VehicleNodes[nodeId];
return PedNodes[nodeId - NumOfVehNodes];
}
/**
* Returns all the areas ID around the given areaID
*/