Skip to content

Commit bcd13ae

Browse files
committed
Made actors generate less jump-heavy paths that they can follow more accurately
1 parent e14859e commit bcd13ae

File tree

4 files changed

+20
-36
lines changed

4 files changed

+20
-36
lines changed

Source/Entities/Actor.cpp

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,32 +1082,11 @@ void Actor::OnNewMovePath() {
10821082
m_MoveTarget = m_PrevPathTarget = m_Pos;
10831083
}
10841084

1085-
if (!m_MovePath.empty()) {
1086-
// Smash all non-airborne waypoints down to just above the ground, so they more accurately represent the ground path
1087-
std::list<Vector>::iterator finalItr = m_MovePath.end();
1088-
finalItr--;
1089-
Vector smashedPoint;
1090-
Vector previousPoint = *(m_MovePath.begin());
1091-
std::list<Vector>::iterator nextItr = m_MovePath.begin();
1092-
for (std::list<Vector>::iterator lItr = m_MovePath.begin(); lItr != finalItr; ++lItr) {
1093-
nextItr++;
1094-
smashedPoint = g_SceneMan.MovePointToGround((*lItr), m_CharHeight * 0.2, 0, g_SettingsMan.GetPathFinderGridNodeSize() * 2.0f);
1095-
1096-
// Only smash if the new location doesn't cause the path to intersect hard terrain ahead or behind of it
1097-
// Try three times to halve the height to see if that won't intersect
1098-
for (int i = 0; i < 3; i++) {
1099-
Vector notUsed;
1100-
if (!g_SceneMan.CastStrengthRay(previousPoint, smashedPoint - previousPoint, 5, notUsed, 3, g_MaterialDoor) &&
1101-
nextItr != m_MovePath.end() && !g_SceneMan.CastStrengthRay(smashedPoint, (*nextItr) - smashedPoint, 5, notUsed, 3, g_MaterialDoor)) {
1102-
(*lItr) = smashedPoint;
1103-
break;
1104-
} else {
1105-
smashedPoint.m_Y -= ((smashedPoint.m_Y - (*lItr).m_Y) / 2);
1106-
}
1107-
}
1108-
1109-
previousPoint = (*lItr);
1110-
}
1085+
// Smash all non-airborne waypoints down to just above the ground, so they more accurately represent the ground path
1086+
std::list<Vector>::iterator finalItr = m_MovePath.end();
1087+
--finalItr;
1088+
for (std::list<Vector>::iterator lItr = m_MovePath.begin(); lItr != finalItr; ++lItr) {
1089+
(*lItr) = g_SceneMan.MovePointToGround((*lItr), m_CharHeight * 0.2, 0, g_SettingsMan.GetPathFinderGridNodeSize() * 2.5f);
11111090
}
11121091
}
11131092

Source/Managers/SceneMan.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,7 +2242,7 @@ bool SceneMan::IsPointInNoGravArea(const Vector& point) const {
22422242
return false;
22432243
}
22442244

2245-
Vector SceneMan::MovePointToGround(const Vector& from, int maxAltitude, int accuracy, int maxDistance) {
2245+
Vector SceneMan::MovePointToGround(const Vector& from, int heightAboveGround, int accuracy, int maxDistance) {
22462246
if (IsPointInNoGravArea(from)) {
22472247
return from;
22482248
}
@@ -2257,8 +2257,7 @@ Vector SceneMan::MovePointToGround(const Vector& from, int maxAltitude, int accu
22572257
return temp;
22582258
}
22592259

2260-
// Only move down if we're above the maxAltitude over the ground
2261-
Vector groundPoint(temp.m_X, temp.m_Y + (altitude > maxAltitude ? altitude - maxAltitude : 0));
2260+
Vector groundPoint(temp.m_X, temp.m_Y + (altitude - heightAboveGround));
22622261
return groundPoint;
22632262
}
22642263

Source/Managers/SceneMan.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -787,16 +787,16 @@ namespace RTE {
787787
/// down at a certain maximum distance from the ground.
788788
/// @param from The point to start from. Should be in the air, or the same point will
789789
/// be returned (null operation)
790-
/// @param maxAltitude The max altitude in px you want the point to be above the ground. (default: 0)
790+
/// @param heightAboveGround The altitude in px you want the point to be above the ground. (default: 0)
791791
/// @param accuracy The accuracy within screen measurement is acceptable. Higher number (default: 0) here means less calculation.
792792
/// @param maxDistance The maximum distance downwards the point will be moved. Points higher than this will not be moved down.
793793
/// @return The new point screen is no higher than accuracy + max altitude over
794794
/// the terrain.
795-
Vector MovePointToGround(const Vector& from, int maxAltitude, int accuracy, int maxDistance);
795+
Vector MovePointToGround(const Vector& from, int heightAboveGround, int accuracy, int maxDistance);
796796

797797
// Luabind makes this such a pain
798-
Vector MovePointToGround(const Vector& from, int maxAltitude = 0, int accuracy = 0) {
799-
return MovePointToGround(from, maxAltitude, accuracy, 0);
798+
Vector MovePointToGround(const Vector& from, int heightAboveGround = 0, int accuracy = 0) {
799+
return MovePointToGround(from, heightAboveGround, accuracy, 0);
800800
}
801801

802802
/// Returns whether the integer coordinates passed in are within the

Source/System/PathFinder.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
361361
break;
362362
}
363363

364-
float extraJumpCost = i * i * 0.5F; // Exponential cost increase for jumping higher
364+
float f = i + 2; // Exponential cost increase for jumping higher
365+
float extraJumpCost = f * f * 0.5F; // Exponential cost increase for jumping higher
366+
365367
totalMaterialCost += 1.0F + extraUpCost + extraJumpCost + (GetMaterialTransitionCost(*currentNode->UpMaterial) * 3.0F) + radiatedCost;
366368

367369
adjCost.cost = totalMaterialCost;
@@ -386,7 +388,9 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
386388
break;
387389
}
388390

389-
float extraJumpCost = i * i * 0.5F; // Exponential cost increase for jumping higher
391+
float f = i + 2; // Exponential cost increase for jumping higher
392+
float extraJumpCost = f * f * 0.5F; // Exponential cost increase for jumping higher
393+
390394
totalMaterialCost += 1.4F + (extraUpCost * 1.4F) + (extraJumpCost * 1.4f) + (GetMaterialTransitionCost(*currentNode->UpRightMaterial) * 1.4F * 3.0F) + radiatedCost;
391395

392396
adjCost.cost = totalMaterialCost;
@@ -406,7 +410,9 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
406410
break;
407411
}
408412

409-
float extraJumpCost = i * i * 0.5F; // Exponential cost increase for jumping higher
413+
float f = i + 2; // Exponential cost increase for jumping higher
414+
float extraJumpCost = f * f * 0.5F; // Exponential cost increase for jumping higher
415+
410416
totalMaterialCost += 1.4F + (extraUpCost * 1.4F) + (extraJumpCost * 1.4f) + (GetMaterialTransitionCost(*currentNode->LeftUpMaterial) * 1.4F * 3.0F) + radiatedCost;
411417

412418
adjCost.cost = totalMaterialCost;

0 commit comments

Comments
 (0)