Skip to content

Commit b6368c7

Browse files
committed
Don't allow diagonals in nograv
1 parent 7b64754 commit b6368c7

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Source/System/PathFinder.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,25 +304,28 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
304304
const float costRadiationMultiplier = 0.2F;
305305
float radiatedCost = 0.0F; //GetNodeAverageTransitionCost(*node) * costRadiationMultiplier;
306306

307+
bool isInNoGrav = g_SceneMan.IsPointInNoGravArea(node->Pos);
308+
bool allowDiagonal = !isInNoGrav; // We don't allow diagonals in nograv to improve automover behaviour
309+
307310
if (node->Down && node->Down->m_Navigatable) {
308311
adjCost.cost = 1.0F + GetMaterialTransitionCost(*node->DownMaterial) + radiatedCost;
309312
adjCost.state = static_cast<void*>(node->Down);
310313
adjacentList->push_back(adjCost);
311314
}
312315

313-
if (node->RightDown && node->RightDown->m_Navigatable) {
316+
if (node->RightDown && node->RightDown->m_Navigatable && !isInNoGrav) {
314317
adjCost.cost = 1.4F + (GetMaterialTransitionCost(*node->RightDownMaterial) * 1.4F) + radiatedCost;
315318
adjCost.state = static_cast<void*>(node->RightDown);
316319
adjacentList->push_back(adjCost);
317320
}
318321

319-
if (node->DownLeft && node->DownLeft->m_Navigatable) {
322+
if (node->DownLeft && node->DownLeft->m_Navigatable && !isInNoGrav) {
320323
adjCost.cost = 1.4F + (GetMaterialTransitionCost(*node->DownLeftMaterial) * 1.4F) + radiatedCost;
321324
adjCost.state = static_cast<void*>(node->DownLeft);
322325
adjacentList->push_back(adjCost);
323326
}
324327

325-
if (NodeIsOnSolidGround(*node)) {
328+
if (isInNoGrav || NodeIsOnSolidGround(*node)) {
326329
// Cost to discourage us from going up
327330
const float extraUpCost = 3.0F;
328331

@@ -369,7 +372,7 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
369372
}
370373

371374
// Jumping diagonally
372-
if (s_JumpHeight < FLT_MAX && node->UpRight) {
375+
if (s_JumpHeight < FLT_MAX && node->UpRight && !isInNoGrav) {
373376
const PathNode* currentNode = node->UpRight;
374377
float totalMaterialCost = 1.4F + (extraUpCost * 1.4F) + (GetMaterialTransitionCost(*node->UpRightMaterial) * 1.4F * 3.0F) + radiatedCost;
375378
for (int i = 0; i < diagonalJumpHeightInNodes; ++i) {
@@ -388,7 +391,7 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
388391
}
389392
}
390393

391-
if (s_JumpHeight < FLT_MAX && node->LeftUp) {
394+
if (s_JumpHeight < FLT_MAX && node->LeftUp && !isInNoGrav) {
392395
const PathNode* currentNode = node->LeftUp;
393396
float totalMaterialCost = 1.4F + (extraUpCost * 1.4F) + (GetMaterialTransitionCost(*node->LeftUpMaterial) * 1.4F * 3.0F) + radiatedCost;
394397
for (int i = 0; i < diagonalJumpHeightInNodes; ++i) {
@@ -408,13 +411,13 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
408411
}
409412

410413
// Add cost for digging at 45 degrees and for digging upwards.
411-
if (node->UpRight && node->UpRight->m_Navigatable) {
414+
if (node->UpRight && node->UpRight->m_Navigatable && !isInNoGrav) {
412415
adjCost.cost = 1.4F + (extraUpCost * 1.4F) + (GetMaterialTransitionCost(*node->UpRightMaterial) * 1.4F * 3.0F) + radiatedCost; // Three times more expensive when digging.
413416
adjCost.state = static_cast<void*>(node->UpRight);
414417
adjacentList->push_back(adjCost);
415418
}
416419

417-
if (node->LeftUp && node->LeftUp->m_Navigatable) {
420+
if (node->LeftUp && node->LeftUp->m_Navigatable && !isInNoGrav) {
418421
adjCost.cost = 1.4F + (extraUpCost * 1.4F) + (GetMaterialTransitionCost(*node->LeftUpMaterial) * 1.4F * 3.0F) + radiatedCost; // Three times more expensive when digging.
419422
adjCost.state = static_cast<void*>(node->LeftUp);
420423
adjacentList->push_back(adjCost);
@@ -431,7 +434,7 @@ bool PathFinder::PositionsAreTheSamePathNode(const Vector& pos1, const Vector& p
431434
}
432435

433436
bool PathFinder::NodeIsOnSolidGround(const PathNode& node) const {
434-
return s_JumpHeight == FLT_MAX || (node.Down && node.DownMaterial->GetIntegrity() > c_PathFindingDefaultDigStrength) || g_SceneMan.IsPointInNoGravArea(node.Pos);
437+
return s_JumpHeight == FLT_MAX || (node.Down && node.DownMaterial->GetIntegrity() > c_PathFindingDefaultDigStrength);
435438
}
436439

437440
float PathFinder::GetMaterialTransitionCost(const Material& material) const {

0 commit comments

Comments
 (0)