Skip to content

Commit 548220b

Browse files
committed
Automover controller fixes
Change MovableMan:IsActor to MovableMan:ValidMO Replace unneeded string comparison Turn off some SceneMan:CalculatePath calls on big maps Fixed up exiting movators so it doesn't constantly call SceneMan:CalculatePath, which is expensive on big maps
1 parent 6b51e2c commit 548220b

File tree

1 file changed

+27
-25
lines changed
  • Data/Base.rte/Scenes/Objects/Bunkers/BunkerSystems/Automovers/Controller

1 file changed

+27
-25
lines changed

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

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ function Create(self)
153153
self.actorMovementUpdateTimer = Timer(15);
154154

155155
self.heldInputTimer = Timer(50);
156+
157+
self.allowExpensiveFindClosestNode = SceneMan.SceneWidth * SceneMan.SceneHeight < 10000000;
156158

157159
self.leaveAutomoverNetworkPieSlice = CreatePieSlice("Leave Automover Network", "Base.rte");
158160
self.chooseTeleporterPieSlice = CreatePieSlice("Choose Teleporter", "Base.rte");
@@ -185,7 +187,7 @@ function Update(self)
185187
if self.actorMovementUpdateTimer:IsPastSimTimeLimit() then
186188
for actorUniqueID, actorData in pairs(self.affectedActors) do
187189
local actor = actorData.actor;
188-
if not MovableMan:IsActor(actor) or not self.combinedAutomoverArea:IsInside(actor.Pos) then
190+
if not MovableMan:ValidMO(actor) or not self.combinedAutomoverArea:IsInside(actor.Pos) then
189191
self:removeActorFromAutomoverTable(actor, actorUniqueID);
190192
else
191193
if actor:NumberValueExists("Automover_LeaveAutomoverNetwork") then
@@ -585,7 +587,7 @@ automoverUtilityFunctions.addAllPaths = function(self)
585587
end
586588
end
587589

588-
while type(next(tentativeNodes)) ~= "nil" do
590+
while next(tentativeNodes) ~= nil do
589591
local closestNode;
590592
local distanceToClosestNode;
591593
for tentativeNode, tentativeNodeData in pairs(tentativeNodes) do
@@ -668,7 +670,7 @@ automoverUtilityFunctions.findClosestNode = function(self, positionToFindClosest
668670
end
669671
end
670672
end
671-
if nodeSatisfiesConditions and checkForShortestPathfinderPath then
673+
if nodeSatisfiesConditions and checkForShortestPathfinderPath and self.allowExpensiveFindClosestNode then
672674
nodeSatisfiesConditions = false;
673675
local lengthOfScenePathToNode = SceneMan.Scene:CalculatePath(positionToFindClosestNodeFor, node.Pos, false, GetPathFindingDefaultDigStrength(), pathfinderTeam);
674676
if lengthOfScenePathToClosestNode == nil or lengthOfScenePathToNode < lengthOfScenePathToClosestNode then
@@ -801,7 +803,6 @@ automoverVisualEffectsFunctions.drawVisualEffects = function(self)
801803
end
802804
end
803805

804-
805806
automoverActorFunctions.checkForNewActors = function(self)
806807
for box in self.combinedAutomoverArea.Boxes do
807808
for movableObject in MovableMan:GetMOsInBox(box, -1, true) do
@@ -841,7 +842,7 @@ automoverActorFunctions.removeActorFromAutomoverTable = function(self, actor, op
841842
optionalActorUniqueID = actor.UniqueID;
842843
end
843844

844-
if MovableMan:IsActor(actor) then
845+
if MovableMan:ValidMO(actor) then
845846
actor.PieMenu:RemovePieSlicesByPresetName(self.leaveAutomoverNetworkPieSlice.PresetName);
846847
actor.PieMenu:RemovePieSlicesByPresetName(self.chooseTeleporterPieSlice.PresetName);
847848

@@ -1304,30 +1305,31 @@ automoverActorFunctions.handleActorThatHasReachedItsEndNode = function(self, act
13041305
end
13051306
end
13061307
else
1307-
if teamNodeTable[waypointData.endNode].zoneBox:IsWithinBox(actor.Pos) then
1308-
waypointData.actorReachedEndNodeForTargetOutsideAutomoverArea = true;
1309-
end
1310-
if waypointData.actorReachedEndNodeForTargetOutsideAutomoverArea and waypointData.delayTimer:IsPastSimTimeLimit() then
1311-
local scenePathSize = SceneMan.Scene:CalculatePath(actor.Pos, waypointData.targetPosition, false, GetPathFindingDefaultDigStrength(), self.Team);
1312-
local secondScenePathEntryPosition;
1313-
local scenePathEntryIndex = 0;
1314-
for scenePathEntryPosition in SceneMan.Scene.ScenePath do
1315-
if scenePathEntryIndex == 2 then
1316-
secondScenePathEntryPosition = scenePathEntryPosition;
1317-
break;
1308+
if teamNodeTable[waypointData.endNode].zoneBox:IsWithinBox(actor.Pos) and waypointData.exitPath == nil then
1309+
waypointData.exitPath = {};
1310+
local distanceFromActorToTargetPosition = SceneMan:ShortestDistance(waypointData.targetPosition, actor.Pos, self.checkWrapping);
1311+
if distanceFromActorToTargetPosition:MagnitudeIsLessThan(20) or not SceneMan:CastStrengthRay(actor.Pos, distanceFromActorToTargetPosition, 5, Vector(), 4, rte.grassID, true) then
1312+
waypointData.exitPath[#waypointData.exitPath + 1] = waypointData.targetPosition;
1313+
else
1314+
SceneMan.Scene:CalculatePath(actor.Pos, waypointData.targetPosition, false, GetPathFindingDefaultDigStrength(), self.Team);
1315+
for scenePathEntryPosition in SceneMan.Scene.ScenePath do
1316+
waypointData.exitPath[#waypointData.exitPath + 1] = scenePathEntryPosition;
13181317
end
1319-
scenePathEntryIndex = scenePathEntryIndex + 1;
13201318
end
1321-
if secondScenePathEntryPosition ~= nil then
1322-
local distanceFromActorToSecondScenePathEntryPosition = SceneMan:ShortestDistance(secondScenePathEntryPosition, actor.Pos, self.checkWrapping);
1323-
actorData.direction = getDirectionForDistanceLargerAxis(distanceFromActorToSecondScenePathEntryPosition, 0);
1324-
1325-
local endNodeData = teamNodeTable[waypointData.endNode];
1326-
if not endNodeData.zoneBox:IsWithinBox(secondScenePathEntryPosition) and (endNodeData.connectedNodeData[actorData.direction] == nil or not endNodeData.connectingAreas[actorData.direction]:IsInside(secondScenePathEntryPosition)) then
1327-
actor.Vel = actor.Vel + (distanceFromActorToSecondScenePathEntryPosition.Normalized:FlipX(true):FlipY(true) * self.movementAcceleration * 10);
1328-
end
1319+
waypointData.delayTimer:Reset();
1320+
elseif waypointData.exitPath ~= nil and #waypointData.exitPath > 0 then
1321+
local distanceFromActorToFirstExitPathPosition = SceneMan:ShortestDistance(waypointData.exitPath[1], actor.Pos, self.checkWrapping);
1322+
if distanceFromActorToFirstExitPathPosition:MagnitudeIsLessThan(20) then
1323+
table.remove(waypointData.exitPath, 1);
1324+
local distanceFromActorToFirstExitPathPosition = SceneMan:ShortestDistance(waypointData.exitPath[1], actor.Pos, self.checkWrapping);
13291325
end
1326+
PrimitiveMan:DrawCircleFillPrimitive(0, waypointData.exitPath[1], 10, 7)
1327+
actorData.direction = getDirectionForDistanceLargerAxis(distanceFromActorToFirstExitPathPosition, 0);
13301328

1329+
local endNodeData = teamNodeTable[waypointData.endNode];
1330+
if not endNodeData.zoneBox:IsWithinBox(waypointData.exitPath[1]) and (endNodeData.connectedNodeData[actorData.direction] == nil or not endNodeData.connectingAreas[actorData.direction]:IsInside(waypointData.exitPath[1])) then
1331+
actor.Vel = actor.Vel + (distanceFromActorToFirstExitPathPosition.Normalized:FlipX(true):FlipY(true) * self.movementAcceleration * 10);
1332+
end
13311333
waypointData.delayTimer:Reset();
13321334
end
13331335
end

0 commit comments

Comments
 (0)