Skip to content

Commit a24b362

Browse files
committed
Improvements to allow diagonal jumps
Went back to SCENEGRIDSIZE
1 parent b3bd2b3 commit a24b362

File tree

2 files changed

+67
-23
lines changed

2 files changed

+67
-23
lines changed

Source/Managers/SettingsMan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void SettingsMan::Clear() {
4848
m_SceneBackgroundAutoScaleMode = 1;
4949
m_DisableFactionBuyMenuThemes = false;
5050
m_DisableFactionBuyMenuThemeCursors = false;
51-
m_PathFinderGridNodeSize = 18;
51+
m_PathFinderGridNodeSize = SCENEGRIDSIZE;
5252
m_AIUpdateInterval = 2;
5353

5454
m_NumberOfLuaStatesOverride = -1;

Source/System/PathFinder.cpp

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ PathFinder::~PathFinder() {
5555

5656
void PathFinder::Clear() {
5757
m_NodeGrid.clear();
58-
m_NodeDimension = 18;
58+
m_NodeDimension = SCENEGRIDSIZE;
5959
m_Offset = Vector();
6060
}
6161

@@ -302,7 +302,7 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
302302
// We do a little trick here, where we radiate out a little percentage of our average cost in all directions.
303303
// 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.
304304
const float costRadiationMultiplier = 0.2F;
305-
float radiatedCost = 0.0f; //GetNodeAverageTransitionCost(*node) * costRadiationMultiplier;
305+
float radiatedCost = 0.0F; //GetNodeAverageTransitionCost(*node) * costRadiationMultiplier;
306306

307307
if (node->Down && node->Down->m_Navigatable) {
308308
adjCost.cost = 1.0F + GetMaterialTransitionCost(*node->DownMaterial) + radiatedCost;
@@ -326,9 +326,6 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
326326
// Cost to discourage us from going up
327327
const float extraUpCost = 3.0F;
328328

329-
// How high up we can jump from this node
330-
const int jumpHeightInNodes = static_cast<int>(s_JumpHeight / (m_NodeDimension * c_MPP));
331-
332329
// We can only go straight left or right if we're on solid ground, otherwise we need to go downwards
333330
if (node->Left && node->Left->m_Navigatable) {
334331
adjCost.cost = 1.0F + GetMaterialTransitionCost(*node->LeftMaterial) + radiatedCost;
@@ -342,6 +339,70 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
342339
adjacentList->push_back(adjCost);
343340
}
344341

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+
345406
// Add cost for digging at 45 degrees and for digging upwards.
346407
if (node->UpRight && node->UpRight->m_Navigatable) {
347408
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>*
354415
adjCost.state = static_cast<void*>(node->LeftUp);
355416
adjacentList->push_back(adjCost);
356417
}
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-
}
374418
}
375419
}
376420

0 commit comments

Comments
 (0)