Skip to content

Commit a0ffdb7

Browse files
committed
Fixed numerous issues with automovers that were causing inaccurate results and extreme lag
1 parent 20e56eb commit a0ffdb7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

Data/Base.rte/Scenes/Objects/Bunkers/BunkerSystems/Automovers/Controller/Controller.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require("Utilities");
12
require("Scenes/Objects/Bunkers/BunkerSystems/Automovers/GlobalAutomoverFunctions");
23

34
local automoverUtilityFunctions = {};
@@ -678,7 +679,7 @@ automoverUtilityFunctions.findClosestNode = function(self, positionToFindClosest
678679
return closestNode;
679680
end
680681

681-
automoverUtilityFunctions.findNodeWithShortestScenePath = function(self, positionToFindClosestNodeFor, nodeThatMustHaveConnectingAutomoverPath, checkThatPositionIsInsideNodeZoneBoxOrConnectingAreas, pathfinderTeam, pathfinderDigStrength)
682+
automoverUtilityFunctions.findNodeWithShortestScenePath = function(self, positionToFindClosestNodeFor, nodeToCheckForPathsFrom, checkThatPositionIsInsideNodeZoneBoxOrConnectingAreas, pathfinderTeam, pathfinderDigStrength)
682683
local teamNodeTable = AutomoverData[self.Team].nodeData;
683684
local teamTeleporterTable = AutomoverData[self.Team].teleporterNodes;
684685

@@ -690,6 +691,7 @@ automoverUtilityFunctions.findNodeWithShortestScenePath = function(self, positio
690691
nodeSatisfiesConditions = nodeData.zoneBox:IsWithinBox(positionToFindClosestNodeFor);
691692
if not nodeSatisfiesConditions then
692693
local connectingAreaDirectionToCheck = Directions.None;
694+
local distanceToNode = SceneMan:ShortestDistance(node.Pos, positionToFindClosestNodeFor, self.checkWrapping);
693695
if distanceToNode.Y + (nodeData.size.Y * 0.5) < 0 then
694696
connectingAreaDirectionToCheck = Directions.Up;
695697
elseif distanceToNode.Y - (nodeData.size.Y * 0.5) > 0 then
@@ -713,7 +715,7 @@ automoverUtilityFunctions.findNodeWithShortestScenePath = function(self, positio
713715
while coroutine.status(shortestPathCoroutine) ~= "dead" do
714716
local _, result = coroutine.resume(shortestPathCoroutine, potentialClosestNodes, positionToFindClosestNodeFor, pathfinderTeam, false, pathfinderDigStrength);
715717
if result then
716-
return result.key;
718+
return result;
717719
else
718720
coroutine.yield();
719721
end

Data/Base.rte/Utilities.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@ function FindStartPositionWithShortestPathToEndPosition(startPositions, endPosit
1717

1818
local closestStartPositionKey;
1919
local closestStartPosition;
20-
local totalCostToClosestStartPosition;
20+
local totalCostToClosestStartPosition = 1/0;
2121
local pathRequestsCompleted = 0;
22+
local totalPathingRequests = 0;
2223
for startPositionKey, startPosition in pairs(startPositions) do
2324
SceneMan.Scene:CalculatePathAsync(
2425
function(pathRequest)
25-
if totalCostToClosestStartPosition == nil or pathRequest.TotalCost < totalCostToClosestStartPosition then
26+
if pathRequest.TotalCost < totalCostToClosestStartPosition then
2627
closestStartPositionKey = startPositionKey;
2728
closestStartPosition = startPosition;
2829
totalCostToClosestStartPosition = pathRequest.TotalCost;
2930
end
3031
pathRequestsCompleted = pathRequestsCompleted + 1;
31-
end
32-
, startPosition, endPosition, movePathToGround, digStrength, team);
32+
end,
33+
startPosition, endPosition, movePathToGround, digStrength, team
34+
);
35+
totalPathingRequests = totalPathingRequests + 1;
3336
end
3437

35-
while pathRequestsCompleted < #startPositions do
38+
while pathRequestsCompleted < totalPathingRequests do
3639
if totalCostToClosestStartPosition == 0 then
3740
break;
3841
end

0 commit comments

Comments
 (0)