Skip to content

Commit e4dc0a0

Browse files
committed
Fixes to how costs are calculated
1 parent 1b0c7d5 commit e4dc0a0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Source/System/PathFinder.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
354354
break;
355355
}
356356

357-
totalMaterialCost += 1.0F + extraUpCost + (GetMaterialTransitionCost(*node->UpMaterial) * 3.0F) + radiatedCost;
357+
totalMaterialCost += 1.0F + extraUpCost + (GetMaterialTransitionCost(*currentNode->UpMaterial) * 3.0F) + radiatedCost;
358358

359359
adjCost.cost = totalMaterialCost;
360360
adjCost.state = static_cast<void*>(currentNode->Up);
@@ -367,14 +367,14 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
367367
// Jumping diagonally
368368
if (node->UpRight) {
369369
const PathNode* currentNode = node->UpRight;
370-
float totalMaterialCost = 0.0F;
370+
float totalMaterialCost = 1.4F + (extraUpCost * 1.4F) + (GetMaterialTransitionCost(*node->UpRightMaterial) * 1.4F * 3.0F) + radiatedCost;
371371
for (int i = 0; i < diagonalJumpHeightInNodes; ++i) {
372372
if (currentNode->UpRight == nullptr || !currentNode->UpRight->m_Navigatable || currentNode->UpRightMaterial->GetIntegrity() > c_PathFindingDefaultDigStrength) {
373373
// solid ceiling, stop
374374
break;
375375
}
376376

377-
totalMaterialCost += 1.4F + (extraUpCost * 1.4F) + (GetMaterialTransitionCost(*node->UpRightMaterial) * 1.4F * 3.0F) + radiatedCost;
377+
totalMaterialCost += 1.4F + (extraUpCost * 1.4F) + (GetMaterialTransitionCost(*currentNode->UpRightMaterial) * 1.4F * 3.0F) + radiatedCost;
378378

379379
adjCost.cost = totalMaterialCost;
380380
adjCost.state = static_cast<void*>(currentNode->UpRight);
@@ -386,14 +386,14 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
386386

387387
if (node->LeftUp) {
388388
const PathNode* currentNode = node->LeftUp;
389-
float totalMaterialCost = 0.0F;
389+
float totalMaterialCost = 1.4F + (extraUpCost * 1.4F) + (GetMaterialTransitionCost(*node->LeftUpMaterial) * 1.4F * 3.0F) + radiatedCost;
390390
for (int i = 0; i < diagonalJumpHeightInNodes; ++i) {
391391
if (currentNode->LeftUp == nullptr || !currentNode->LeftUp->m_Navigatable || currentNode->LeftUpMaterial->GetIntegrity() > c_PathFindingDefaultDigStrength) {
392392
// solid ceiling, stop
393393
break;
394394
}
395395

396-
totalMaterialCost += 1.4F + (extraUpCost * 1.4F) + (GetMaterialTransitionCost(*node->LeftUpMaterial) * 1.4F * 3.0F) + radiatedCost;
396+
totalMaterialCost += 1.4F + (extraUpCost * 1.4F) + (GetMaterialTransitionCost(*currentNode->LeftUpMaterial) * 1.4F * 3.0F) + radiatedCost;
397397

398398
adjCost.cost = totalMaterialCost;
399399
adjCost.state = static_cast<void*>(currentNode->LeftUp);
@@ -405,13 +405,13 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
405405

406406
// Add cost for digging at 45 degrees and for digging upwards.
407407
if (node->UpRight && node->UpRight->m_Navigatable) {
408-
adjCost.cost = 1.4F + extraUpCost + (GetMaterialTransitionCost(*node->UpRightMaterial) * 1.4F * 3.0F) + radiatedCost; // Three times more expensive when digging.
408+
adjCost.cost = 1.4F + (extraUpCost * 1.4F) + (GetMaterialTransitionCost(*node->UpRightMaterial) * 1.4F * 3.0F) + radiatedCost; // Three times more expensive when digging.
409409
adjCost.state = static_cast<void*>(node->UpRight);
410410
adjacentList->push_back(adjCost);
411411
}
412412

413413
if (node->LeftUp && node->LeftUp->m_Navigatable) {
414-
adjCost.cost = 1.4F + extraUpCost + (GetMaterialTransitionCost(*node->LeftUpMaterial) * 1.4F * 3.0F) + radiatedCost; // Three times more expensive when digging.
414+
adjCost.cost = 1.4F + (extraUpCost * 1.4F) + (GetMaterialTransitionCost(*node->LeftUpMaterial) * 1.4F * 3.0F) + radiatedCost; // Three times more expensive when digging.
415415
adjCost.state = static_cast<void*>(node->LeftUp);
416416
adjacentList->push_back(adjCost);
417417
}

0 commit comments

Comments
 (0)