Skip to content

Commit f7209ca

Browse files
committed
attempts to improve nav- todo, make us jump less.
1 parent 0fc6a5a commit f7209ca

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

Source/Entities/Actor.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,34 @@ void Actor::OnNewMovePath() {
10811081
// Nowhere to gooooo
10821082
m_MoveTarget = m_PrevPathTarget = m_Pos;
10831083
}
1084+
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);
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+
}
1111+
}
10841112
}
10851113

10861114
void Actor::PreControllerUpdate() {

Source/Lua/LuaBindingsManagers.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,10 @@ LuaBindingRegisterFunctionDefinitionForType(ManagerLuaBindings, SceneMan) {
345345
.def("CastObstacleRay", &LuaAdaptersSceneMan::CastObstacleRay2)
346346
.def("CastTerrainPenetrationRay", &SceneMan::CastTerrainPenetrationRay)
347347
.def("GetLastRayHitPos", &SceneMan::GetLastRayHitPos)
348-
.def("FindAltitude", (float(SceneMan::*)(const Vector&, int, int)) & SceneMan::FindAltitude)
349-
.def("FindAltitude", (float(SceneMan::*)(const Vector&, int, int, bool)) & SceneMan::FindAltitude)
350-
.def("MovePointToGround", &SceneMan::MovePointToGround)
348+
.def("FindAltitude", (float(SceneMan::*)(const Vector&, int, int)) &SceneMan::FindAltitude)
349+
.def("FindAltitude", (float(SceneMan::*)(const Vector&, int, int, bool)) &SceneMan::FindAltitude)
350+
.def("MovePointToGround", (Vector(SceneMan::*)(const Vector&, int, int)) &SceneMan::MovePointToGround)
351+
.def("MovePointToGround", (Vector(SceneMan::*)(const Vector&, int, int, int)) &SceneMan::MovePointToGround)
351352
.def("IsWithinBounds", &SceneMan::IsWithinBounds)
352353
.def("ForceBounds", (bool(SceneMan::*)(Vector&) const) & SceneMan::ForceBounds) //, out_value(_2))
353354
.def("WrapPosition", (bool(SceneMan::*)(Vector&) const) & SceneMan::WrapPosition) //, out_value(_2))

Source/Managers/SceneMan.cpp

Lines changed: 2 additions & 2 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) {
2245+
Vector SceneMan::MovePointToGround(const Vector& from, int maxAltitude, int accuracy, int maxDistance) {
22462246
if (IsPointInNoGravArea(from)) {
22472247
return from;
22482248
}
@@ -2253,7 +2253,7 @@ Vector SceneMan::MovePointToGround(const Vector& from, int maxAltitude, int accu
22532253
float altitude = FindAltitude(temp, g_SceneMan.GetSceneHeight(), accuracy);
22542254

22552255
// If there's no ground beneath us, do nothing
2256-
if (altitude == g_SceneMan.GetSceneHeight()) {
2256+
if (altitude == g_SceneMan.GetSceneHeight() || (maxDistance != 0 && altitude > maxDistance)) {
22572257
return temp;
22582258
}
22592259

Source/Managers/SceneMan.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -788,11 +788,16 @@ namespace RTE {
788788
/// @param from The point to start from. Should be in the air, or the same point will
789789
/// be returned (null operation)
790790
/// @param maxAltitude The max altitude in px you want the point to be above the ground. (default: 0)
791-
/// @param accuracy The accuracy within screen measurement is acceptable. Higher number (default: 0)
792-
/// here means less calculation.
791+
/// @param accuracy The accuracy within screen measurement is acceptable. Higher number (default: 0) here means less calculation.
792+
/// @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 = 0, int accuracy = 0);
795+
Vector MovePointToGround(const Vector& from, int maxAltitude, int accuracy, int maxDistance);
796+
797+
// 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);
800+
}
796801

797802
/// Returns whether the integer coordinates passed in are within the
798803
/// bounds of the current Scene, considering its wrapping.

0 commit comments

Comments
 (0)