Skip to content

Commit 3c6a010

Browse files
committed
Fix to stale access
1 parent 0c70dcb commit 3c6a010

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

Data/Base.rte/AI/HumanBehaviors.lua

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ function HumanBehaviors.WeaponSearch(AI, Owner, Abort)
949949
if _abrt then return true end
950950
end
951951

952-
if IsHeldDevice(movableObject) and MovableMan:ValidMO(movableObject) then
952+
if MovableMan:ValidMO(movableObject) and IsHeldDevice(movableObject) then
953953
local device = ToHeldDevice(movableObject);
954954
if device:IsPickupableBy(Owner) and not device:IsActivated() and device.Vel.Largest < 3 and not SceneMan:IsUnseen(device.Pos.X, device.Pos.Y, Owner.Team) then
955955
local distanceToDevice = SceneMan:ShortestDistance(Owner.Pos, device.Pos, SceneMan.SceneWrapsX or SceneMan.SceneWrapsY);
@@ -974,33 +974,34 @@ function HumanBehaviors.WeaponSearch(AI, Owner, Abort)
974974
local devicesToPickUp = {};
975975
for _, deviceEntry in pairs(devices) do
976976
local device = deviceEntry.device;
977-
978-
local pathMultipler = 1;
979-
if device:HasObjectInGroup("Weapons - Primary") or device:HasObjectInGroup("Weapons - Heavy") then
980-
pathMultipler = 0.4; -- prioritize primary or heavy weapons
981-
elseif device.ClassName == "TDExplosive" then
982-
pathMultipler = 1.4; -- avoid grenades if there are other weapons
983-
elseif device:IsTool() then
984-
if pickupDiggers and device:HasObjectInGroup("Tools - Diggers") then
985-
pathMultipler = 1.8; -- avoid diggers if there are other weapons
986-
else
987-
pathMultipler = -1; -- disregard non-digger tools
977+
if MovableMan:ValidMO(device) then
978+
local pathMultipler = 1;
979+
if device:HasObjectInGroup("Weapons - Primary") or device:HasObjectInGroup("Weapons - Heavy") then
980+
pathMultipler = 0.4; -- prioritize primary or heavy weapons
981+
elseif device.ClassName == "TDExplosive" then
982+
pathMultipler = 1.4; -- avoid grenades if there are other weapons
983+
elseif device:IsTool() then
984+
if pickupDiggers and device:HasObjectInGroup("Tools - Diggers") then
985+
pathMultipler = 1.8; -- avoid diggers if there are other weapons
986+
else
987+
pathMultipler = -1; -- disregard non-digger tools
988+
end
988989
end
989-
end
990990

991-
if MovableMan:ValidMO(device) and pathMultipler ~= -1 then
992-
local deviceID = device.UniqueID;
993-
SceneMan.Scene:CalculatePathAsync(
994-
function(pathRequest)
995-
local pathLength = pathRequest.PathLength;
996-
if pathRequest.Status ~= PathRequest.NoSolution and pathLength < maxPathLength then
997-
local score = pathLength * pathMultipler;
998-
table.insert(devicesToPickUp, {deviceId = deviceID, score = score});
999-
end
1000-
searchesRemaining = searchesRemaining - 1;
1001-
end,
1002-
Owner.Pos, device.Pos, false, Owner.DigStrength, Owner.Team
1003-
);
991+
if pathMultipler ~= -1 then
992+
local deviceID = device.UniqueID;
993+
SceneMan.Scene:CalculatePathAsync(
994+
function(pathRequest)
995+
local pathLength = pathRequest.PathLength;
996+
if pathRequest.Status ~= PathRequest.NoSolution and pathLength < maxPathLength then
997+
local score = pathLength * pathMultipler;
998+
table.insert(devicesToPickUp, {deviceId = deviceID, score = score});
999+
end
1000+
searchesRemaining = searchesRemaining - 1;
1001+
end,
1002+
Owner.Pos, device.Pos, false, Owner.DigStrength, Owner.Team
1003+
);
1004+
end
10041005
end
10051006
end
10061007

@@ -1077,7 +1078,7 @@ function HumanBehaviors.ToolSearch(AI, Owner, Abort)
10771078
for movableObject in MovableMan:GetMOsInRadius(Owner.Pos, maxSearchDistance, -1, true) do
10781079
mosSearched = mosSearched + 1;
10791080

1080-
if IsHeldDevice(movableObject) and MovableMan:ValidMO(movableObject) then
1081+
if MovableMan:ValidMO(movableObject) and IsHeldDevice(movableObject) then
10811082
local device = ToHeldDevice(movableObject);
10821083
if device:IsPickupableBy(Owner) and not device:IsActivated() and device.Vel.Largest < 3 and not SceneMan:IsUnseen(device.Pos.X, device.Pos.Y, Owner.Team) and device:HasObjectInGroup("Tools - Diggers") then
10831084
local distanceToDevice = SceneMan:ShortestDistance(Owner.Pos, device.Pos, SceneMan.SceneWrapsX or SceneMan.SceneWrapsY);

0 commit comments

Comments
 (0)