mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-26 14:00:17 +00:00
extract method
This commit is contained in:
parent
167e313456
commit
6b66065ba5
2 changed files with 25 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue