@@ -203,11 +203,12 @@ end
203
203
--- Pathfinder context
204
204
--- @class PathfinderUtil.Context
205
205
PathfinderUtil .Context = CpObject ()
206
- function PathfinderUtil .Context :init (vehicle , vehiclesToIgnore )
206
+ function PathfinderUtil .Context :init (vehicle , vehiclesToIgnore , objectsToIgnore )
207
207
self .vehicleData = PathfinderUtil .VehicleData (vehicle , true , 0.5 )
208
208
self .trailerHitchLength = AIDriverUtil .getTowBarLength (vehicle )
209
209
self .turnRadius = vehicle .cp and vehicle .cp .driver and AIDriverUtil .getTurningRadius (vehicle ) or 10
210
- self .vehiclesToIgnore = vehiclesToIgnore
210
+ self .vehiclesToIgnore = vehiclesToIgnore or {}
211
+ self .objectsToIgnore = objectsToIgnore or {}
211
212
end
212
213
213
214
--- Calculate the four corners of a rectangle around a node (for example the area covered by a vehicle)
276
277
277
278
function PathfinderUtil .CollisionDetector :overlapBoxCallback (transformId )
278
279
local collidingObject = g_currentMission .nodeToObject [transformId ]
280
+ if collidingObject and PathfinderUtil .elementOf (self .objectsToIgnore , collidingObject ) then
281
+ -- an object we want to ignore
282
+ return
283
+ end
279
284
if collidingObject and collidingObject .getRootVehicle then
280
285
local rootVehicle = collidingObject :getRootVehicle ()
281
286
if rootVehicle == self .vehicleData .rootVehicle or
@@ -292,13 +297,14 @@ function PathfinderUtil.CollisionDetector:overlapBoxCallback(transformId)
292
297
text = text .. ' ' .. key
293
298
end
294
299
end
295
- self .collidingShapesText = text
300
+ self .collidingShapesText = text
296
301
self .collidingShapes = self .collidingShapes + 1
297
302
end
298
303
end
299
304
300
- function PathfinderUtil .CollisionDetector :findCollidingShapes (node , vehicleData , vehiclesToIgnore , log )
305
+ function PathfinderUtil .CollisionDetector :findCollidingShapes (node , vehicleData , vehiclesToIgnore , objectsToIgnore , log )
301
306
self .vehiclesToIgnore = vehiclesToIgnore or {}
307
+ self .objectsToIgnore = objectsToIgnore or {}
302
308
self .vehicleData = vehicleData
303
309
-- the box for overlapBox() is symmetric, so if our root node is not in the middle of the vehicle rectangle,
304
310
-- we have to translate it into the middle
@@ -311,8 +317,8 @@ function PathfinderUtil.CollisionDetector:findCollidingShapes(node, vehicleData,
311
317
local xRot , yRot , zRot = getWorldRotation (node )
312
318
local x , y , z = localToWorld (node , xOffset , 1 , zOffset )
313
319
314
- self .collidingShapes = 0
315
- self .collidingShapesText = ' unknown'
320
+ self .collidingShapes = 0
321
+ self .collidingShapesText = ' unknown'
316
322
317
323
overlapBox (x , y + 0.2 , z , xRot , yRot , zRot , width , 1 , length , ' overlapBoxCallback' , self , bitOR (AIVehicleUtil .COLLISION_MASK , 2 ), true , true , true )
318
324
if log and self .collidingShapes > 0 then
@@ -488,17 +494,18 @@ function PathfinderConstraints:isValidNode(node, log, ignoreTrailer)
488
494
local myCollisionData = PathfinderUtil .getBoundingBoxInWorldCoordinates (PathfinderUtil .helperNode , self .context .vehicleData , ' me' )
489
495
-- for debug purposes only, store validity info on node
490
496
node .collidingShapes = PathfinderUtil .collisionDetector :findCollidingShapes (
491
- PathfinderUtil .helperNode , self .context .vehicleData , self .context .vehiclesToIgnore , log )
497
+ PathfinderUtil .helperNode , self .context .vehicleData , self .context .vehiclesToIgnore , self . context . objectsToIgnore , log )
492
498
if self .context .vehicleData .trailer and not ignoreTrailer then
493
499
-- now check the trailer or towed implement
494
500
-- move the node to the rear of the vehicle (where approximately the trailer is attached)
495
- local x , y , z = localToWorld (PathfinderUtil .helperNode , 0 , 0 , self .context .vehicleData .trailerHitchOffset )
501
+ local x , y , z = localToWorld (PathfinderUtil .helperNode , 0 , 0 , self .context .vehicleData .trailerHitchOffset )
496
502
497
- PathfinderUtil .setWorldPositionAndRotationOnTerrain (PathfinderUtil .helperNode , x , z ,
498
- courseGenerator .toCpAngle (node .tTrailer ), 0.5 )
503
+ PathfinderUtil .setWorldPositionAndRotationOnTerrain (PathfinderUtil .helperNode , x , z ,
504
+ courseGenerator .toCpAngle (node .tTrailer ), 0.5 )
499
505
500
506
node .collidingShapes = node .collidingShapes + PathfinderUtil .collisionDetector :findCollidingShapes (
501
- PathfinderUtil .helperNode , self .context .vehicleData .trailerRectangle , self .context .vehiclesToIgnore , log )
507
+ PathfinderUtil .helperNode , self .context .vehicleData .trailerRectangle , self .context .vehiclesToIgnore ,
508
+ self .context .objectsToIgnore , log )
502
509
end
503
510
local isValid = node .collidingShapes == 0
504
511
if not isValid then
@@ -542,17 +549,18 @@ end
542
549
--- @param goal State3D
543
550
function PathfinderUtil .startPathfindingFromVehicleToGoal (vehicle , goal ,
544
551
allowReverse , fieldNum ,
545
- vehiclesToIgnore , maxFruitPercent , offFieldPenalty , mustBeAccurate )
552
+ vehiclesToIgnore , objectsToIgnore ,
553
+ maxFruitPercent , offFieldPenalty , mustBeAccurate )
546
554
547
- local start = PathfinderUtil .getVehiclePositionAsState3D (vehicle )
555
+ local start = PathfinderUtil .getVehiclePositionAsState3D (vehicle )
548
556
549
- local vehicleData = PathfinderUtil .VehicleData (vehicle , true , 0.5 )
557
+ local vehicleData = PathfinderUtil .VehicleData (vehicle , true , 0.5 )
550
558
551
- PathfinderUtil .initializeTrailerHeading (start , vehicleData )
559
+ PathfinderUtil .initializeTrailerHeading (start , vehicleData )
552
560
553
- local context = PathfinderUtil .Context (vehicle , vehiclesToIgnore )
561
+ local context = PathfinderUtil .Context (vehicle , vehiclesToIgnore , objectsToIgnore )
554
562
555
- local constraints = PathfinderConstraints (context ,
563
+ local constraints = PathfinderConstraints (context ,
556
564
maxFruitPercent or (vehicle .cp .settings .useRealisticDriving :is (true ) and 50 or math.huge ),
557
565
offFieldPenalty or PathfinderUtil .defaultOffFieldPenalty ,
558
566
fieldNum )
@@ -709,7 +717,7 @@ function PathfinderUtil.startPathfindingFromVehicleToWaypoint(vehicle, goalWaypo
709
717
local offset = Vector (zOffset , - xOffset )
710
718
goal :add (offset :rotate (goal .t ))
711
719
return PathfinderUtil .startPathfindingFromVehicleToGoal (
712
- vehicle , goal , allowReverse , fieldNum , vehiclesToIgnore , maxFruitPercent , offFieldPenalty )
720
+ vehicle , goal , allowReverse , fieldNum , vehiclesToIgnore , {}, maxFruitPercent , offFieldPenalty )
713
721
end
714
722
---- --------------------------------------------------------------------------------------------------------------------
715
723
--- Interface function to start the pathfinder in the game. The goal is a point at sideOffset meters from the goal node
@@ -733,7 +741,7 @@ function PathfinderUtil.startPathfindingFromVehicleToNode(vehicle, goalNode,
733
741
local goal = State3D (x , - z , courseGenerator .fromCpAngle (yRot ))
734
742
return PathfinderUtil .startPathfindingFromVehicleToGoal (
735
743
vehicle , goal , allowReverse , fieldNum ,
736
- vehiclesToIgnore , maxFruitPercent , offFieldPenalty , mustBeAccurate )
744
+ vehiclesToIgnore , {}, maxFruitPercent , offFieldPenalty , mustBeAccurate )
737
745
end
738
746
739
747
---- --------------------------------------------------------------------------------------------------------------------
778
786
-- Then check all three for collisions with obstacles.
779
787
--- @return boolean , boolean , boolean true if no obstacles left , right , straight ahead
780
788
---- --------------------------------------------------------------------------------------------------------------------
781
- function PathfinderUtil .checkForObstaclesAhead (vehicle , turnRadius )
789
+ function PathfinderUtil .checkForObstaclesAhead (vehicle , turnRadius , objectsToIgnore )
782
790
783
791
local function isValidPath (constraints , path )
784
792
for i , node in ipairs (path ) do
@@ -806,7 +814,7 @@ function PathfinderUtil.checkForObstaclesAhead(vehicle, turnRadius)
806
814
local start = PathfinderUtil .getVehiclePositionAsState3D (vehicle )
807
815
local vehicleData = PathfinderUtil .VehicleData (vehicle , true , 0.5 )
808
816
PathfinderUtil .initializeTrailerHeading (start , vehicleData )
809
- local context = PathfinderUtil .Context (vehicle , {})
817
+ local context = PathfinderUtil .Context (vehicle , {}, objectsToIgnore )
810
818
local constraints = PathfinderConstraints (context , math.huge , 0 , 0 )
811
819
ensureHelperNode ()
812
820
0 commit comments