@@ -55,7 +55,7 @@ PathFinder::~PathFinder() {
55
55
56
56
void PathFinder::Clear () {
57
57
m_NodeGrid.clear ();
58
- m_NodeDimension = 18 ;
58
+ m_NodeDimension = SCENEGRIDSIZE ;
59
59
m_Offset = Vector ();
60
60
}
61
61
@@ -302,7 +302,7 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
302
302
// We do a little trick here, where we radiate out a little percentage of our average cost in all directions.
303
303
// This encourages the AI to generally try to give hard surfaces some berth when pathing, so we don't get too close and get stuck.
304
304
const float costRadiationMultiplier = 0 .2F ;
305
- float radiatedCost = 0 .0f ; // GetNodeAverageTransitionCost(*node) * costRadiationMultiplier;
305
+ float radiatedCost = 0 .0F ; // GetNodeAverageTransitionCost(*node) * costRadiationMultiplier;
306
306
307
307
if (node->Down && node->Down ->m_Navigatable ) {
308
308
adjCost.cost = 1 .0F + GetMaterialTransitionCost (*node->DownMaterial ) + radiatedCost;
@@ -326,9 +326,6 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
326
326
// Cost to discourage us from going up
327
327
const float extraUpCost = 3 .0F ;
328
328
329
- // How high up we can jump from this node
330
- const int jumpHeightInNodes = static_cast <int >(s_JumpHeight / (m_NodeDimension * c_MPP));
331
-
332
329
// We can only go straight left or right if we're on solid ground, otherwise we need to go downwards
333
330
if (node->Left && node->Left ->m_Navigatable ) {
334
331
adjCost.cost = 1 .0F + GetMaterialTransitionCost (*node->LeftMaterial ) + radiatedCost;
@@ -342,6 +339,70 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
342
339
adjacentList->push_back (adjCost);
343
340
}
344
341
342
+ // How high up we can jump from this node
343
+ const int verticalJumpHeightInNodes = static_cast <int >(s_JumpHeight / (m_NodeDimension * c_MPP));
344
+ const int diagonalJumpHeightInNodes = static_cast <int >((s_JumpHeight * 0 .7F ) / (m_NodeDimension * c_MPP));
345
+
346
+ // Jumping vertically
347
+ {
348
+ // How high up we can jump from this node
349
+ const PathNode* currentNode = node;
350
+ float totalMaterialCost = 0 .0F ;
351
+ for (int i = 0 ; i < verticalJumpHeightInNodes; ++i) {
352
+ if (currentNode->Up == nullptr || !currentNode->Up ->m_Navigatable || currentNode->UpMaterial ->GetIntegrity () > c_PathFindingDefaultDigStrength) {
353
+ // solid ceiling, stop
354
+ break ;
355
+ }
356
+
357
+ totalMaterialCost += 1 .0F + extraUpCost + (GetMaterialTransitionCost (*node->UpMaterial ) * 3 .0F ) + radiatedCost;
358
+
359
+ adjCost.cost = totalMaterialCost;
360
+ adjCost.state = static_cast <void *>(currentNode->Up );
361
+ adjacentList->push_back (adjCost);
362
+
363
+ currentNode = currentNode->Up ;
364
+ }
365
+ }
366
+
367
+ // Jumping diagonally
368
+ if (node->UpRight ) {
369
+ const PathNode* currentNode = node->UpRight ;
370
+ float totalMaterialCost = 0 .0F ;
371
+ for (int i = 0 ; i < diagonalJumpHeightInNodes; ++i) {
372
+ if (currentNode->UpRight == nullptr || !currentNode->UpRight ->m_Navigatable || currentNode->UpRightMaterial ->GetIntegrity () > c_PathFindingDefaultDigStrength) {
373
+ // solid ceiling, stop
374
+ break ;
375
+ }
376
+
377
+ totalMaterialCost += 1 .4F + (extraUpCost * 1 .4F ) + (GetMaterialTransitionCost (*node->UpRightMaterial ) * 1 .4F * 3 .0F ) + radiatedCost;
378
+
379
+ adjCost.cost = totalMaterialCost;
380
+ adjCost.state = static_cast <void *>(currentNode->UpRight );
381
+ adjacentList->push_back (adjCost);
382
+
383
+ currentNode = currentNode->UpRight ;
384
+ }
385
+ }
386
+
387
+ if (node->LeftUp ) {
388
+ const PathNode* currentNode = node->LeftUp ;
389
+ float totalMaterialCost = 0 .0F ;
390
+ for (int i = 0 ; i < diagonalJumpHeightInNodes; ++i) {
391
+ if (currentNode->LeftUp == nullptr || !currentNode->LeftUp ->m_Navigatable || currentNode->LeftUpMaterial ->GetIntegrity () > c_PathFindingDefaultDigStrength) {
392
+ // solid ceiling, stop
393
+ break ;
394
+ }
395
+
396
+ totalMaterialCost += 1 .4F + (extraUpCost * 1 .4F ) + (GetMaterialTransitionCost (*node->LeftUpMaterial ) * 1 .4F * 3 .0F ) + radiatedCost;
397
+
398
+ adjCost.cost = totalMaterialCost;
399
+ adjCost.state = static_cast <void *>(currentNode->LeftUp );
400
+ adjacentList->push_back (adjCost);
401
+
402
+ currentNode = currentNode->LeftUp ;
403
+ }
404
+ }
405
+
345
406
// Add cost for digging at 45 degrees and for digging upwards.
346
407
if (node->UpRight && node->UpRight ->m_Navigatable ) {
347
408
adjCost.cost = 1 .4F + extraUpCost + (GetMaterialTransitionCost (*node->UpRightMaterial ) * 1 .4F * 3 .0F ) + radiatedCost; // Three times more expensive when digging.
@@ -354,23 +415,6 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
354
415
adjCost.state = static_cast <void *>(node->LeftUp );
355
416
adjacentList->push_back (adjCost);
356
417
}
357
-
358
- const PathNode* currentNode = node;
359
- float totalMaterialCost = 0 ;
360
- for (int i = 0 ; i < jumpHeightInNodes; ++i) {
361
- if (currentNode->Up == nullptr || !currentNode->Up ->m_Navigatable || currentNode->UpMaterial ->GetIntegrity () > c_PathFindingDefaultDigStrength) {
362
- // solid ceiling, stop
363
- break ;
364
- }
365
-
366
- totalMaterialCost += 1 .0f + extraUpCost + (GetMaterialTransitionCost (*node->UpMaterial ) * 3 .0F ) + radiatedCost;
367
-
368
- adjCost.cost = totalMaterialCost;
369
- adjCost.state = static_cast <void *>(currentNode->Up );
370
- adjacentList->push_back (adjCost);
371
-
372
- currentNode = currentNode->Up ;
373
- }
374
418
}
375
419
}
376
420
0 commit comments