Skip to content

Commit ccf13b5

Browse files
committed
Re-added support for infinite jumpheight (legacy pathfinds, dropships etc)
Added lua bindings and plumbing to allow configurable jumpHeight from actor. Crabs right now are assumed to have 0 height, Humans are assumed to have 20, and anything else has infinite.
1 parent e4dc0a0 commit ccf13b5

15 files changed

+85
-37
lines changed

Source/Entities/ACrab.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,10 @@ MovableObject* ACrab::LookForMOs(float FOVSpread, unsigned char ignoreMaterial,
758758
return pSeenMO;
759759
}
760760

761+
float ACrab::EstimateJumpHeight() const {
762+
return 0.0f; // todo, add support to detect crabs with jetpacks
763+
}
764+
761765
void ACrab::OnNewMovePath() {
762766
Actor::OnNewMovePath();
763767
}

Source/Entities/ACrab.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ namespace RTE {
267267
/// @param aimRangeLowerLimit The new lower limit of this ACrab's aim range.
268268
void SetAimRangeLowerLimit(float aimRangeLowerLimit) { m_AimRangeLowerLimit = aimRangeLowerLimit; }
269269

270+
// Estimates how high this actor can jump.
271+
/// @return The actor's jump height.
272+
virtual float EstimateJumpHeight() const override;
273+
270274
/// Protected member variable and method declarations
271275
protected:
272276
/// Function that is called when we get a new movepath.

Source/Entities/AHuman.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,10 @@ float AHuman::EstimateDigStrength() const {
933933
return maxPenetration;
934934
}
935935

936+
float AHuman::EstimateJumpHeight() const {
937+
return 20.0f; // hardcoded for now
938+
}
939+
936940
bool AHuman::EquipShield() {
937941
if (!(m_pFGArm && m_pFGArm->IsAttached())) {
938942
return false;

Source/Entities/AHuman.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ namespace RTE {
287287
/// @return The maximum material strength this AHuman's digger can penetrate, or a default dig strength if they don't have a digger.
288288
float EstimateDigStrength() const override;
289289

290+
// Estimates how high this actor can jump.
291+
/// @return The actor's jump height.
292+
virtual float EstimateJumpHeight() const override;
293+
290294
/// Switches the currently held device (if any) to the first found shield
291295
/// in the inventory. If the held device already is a shield, or no
292296
/// shield is in inventory, nothing happens.

Source/Entities/Actor.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -989,17 +989,18 @@ void Actor::UpdateMovePath() {
989989

990990
// Estimate how much material this actor can dig through
991991
float digStrength = EstimateDigStrength();
992+
float jumpHeight = EstimateJumpHeight();
992993

993994
// If we're following someone/thing, then never advance waypoints until that thing disappears
994995
if (g_MovableMan.ValidMO(m_pMOMoveTarget)) {
995-
m_PathRequest = g_SceneMan.GetScene()->CalculatePathAsync(g_SceneMan.MovePointToGround(m_Pos, m_CharHeight * 0.2, 10), m_pMOMoveTarget->GetPos(), digStrength, static_cast<Activity::Teams>(m_Team));
996+
m_PathRequest = g_SceneMan.GetScene()->CalculatePathAsync(g_SceneMan.MovePointToGround(m_Pos, m_CharHeight * 0.2, 10), m_pMOMoveTarget->GetPos(), digStrength, jumpHeight, static_cast<Activity::Teams>(m_Team));
996997
} else {
997998
// Do we currently have a path to a static target we would like to still pursue?
998999
if (m_MovePath.empty()) {
9991000
// Ok no path going, so get a new path to the next waypoint, if there is a next waypoint
10001001
if (!m_Waypoints.empty()) {
10011002
// Make sure the path starts from the ground and not somewhere up in the air if/when dropped out of ship
1002-
m_PathRequest = g_SceneMan.GetScene()->CalculatePathAsync(g_SceneMan.MovePointToGround(m_Pos, m_CharHeight * 0.2, 10), m_Waypoints.front().first, digStrength, static_cast<Activity::Teams>(m_Team));
1003+
m_PathRequest = g_SceneMan.GetScene()->CalculatePathAsync(g_SceneMan.MovePointToGround(m_Pos, m_CharHeight * 0.2, 10), m_Waypoints.front().first, digStrength, jumpHeight, static_cast<Activity::Teams>(m_Team));
10031004

10041005
// If the waypoint was tied to an MO to pursue, then load it into the current MO target
10051006
if (g_MovableMan.ValidMO(m_Waypoints.front().second)) {
@@ -1013,12 +1014,12 @@ void Actor::UpdateMovePath() {
10131014
}
10141015
// Just try to get to the last Move Target
10151016
else {
1016-
m_PathRequest = g_SceneMan.GetScene()->CalculatePathAsync(g_SceneMan.MovePointToGround(m_Pos, m_CharHeight * 0.2, 10), m_MoveTarget, digStrength, static_cast<Activity::Teams>(m_Team));
1017+
m_PathRequest = g_SceneMan.GetScene()->CalculatePathAsync(g_SceneMan.MovePointToGround(m_Pos, m_CharHeight * 0.2, 10), m_MoveTarget, digStrength, jumpHeight, static_cast<Activity::Teams>(m_Team));
10171018
}
10181019
}
10191020
// We had a path before trying to update, so use its last point as the final destination
10201021
else {
1021-
m_PathRequest = g_SceneMan.GetScene()->CalculatePathAsync(g_SceneMan.MovePointToGround(m_Pos, m_CharHeight * 0.2, 10), Vector(m_MovePath.back()), digStrength, static_cast<Activity::Teams>(m_Team));
1022+
m_PathRequest = g_SceneMan.GetScene()->CalculatePathAsync(g_SceneMan.MovePointToGround(m_Pos, m_CharHeight * 0.2, 10), Vector(m_MovePath.back()), digStrength, jumpHeight, static_cast<Activity::Teams>(m_Team));
10221023
}
10231024
}
10241025

@@ -1029,6 +1030,10 @@ float Actor::EstimateDigStrength() const {
10291030
return m_AIBaseDigStrength;
10301031
}
10311032

1033+
float Actor::EstimateJumpHeight() const {
1034+
return FLT_MAX;
1035+
}
1036+
10321037
void Actor::VerifyMOIDs() {
10331038
std::vector<MOID> MOIDs;
10341039
GetMOIDs(MOIDs);

Source/Entities/Actor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,10 @@ namespace RTE {
647647
/// @return The actor's dig strength.
648648
virtual float EstimateDigStrength() const;
649649

650+
/// Estimates how high this actor can jump.
651+
/// @return The actor's jump height.
652+
virtual float EstimateJumpHeight() const;
653+
650654
/// Gets this Actor's base dig strength, or the strength of terrain they can expect to walk through without tools.
651655
/// @return The actors base dig strength.
652656
float GetAIBaseDigStrength() const { return m_AIBaseDigStrength; }

Source/Entities/Scene.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,16 +2398,16 @@ void Scene::UpdatePathFinding() {
23982398
m_PathfindingUpdated = true;
23992399
}
24002400

2401-
float Scene::CalculatePath(const Vector& start, const Vector& end, std::list<Vector>& pathResult, float digStrength, Activity::Teams team) {
2401+
float Scene::CalculatePath(const Vector& start, const Vector& end, std::list<Vector>& pathResult, float digStrength, float jumpHeight, Activity::Teams team) {
24022402
float totalCostResult = -1;
2403-
int result = GetPathFinder(team).CalculatePath(start, end, pathResult, totalCostResult, digStrength);
2403+
int result = GetPathFinder(team).CalculatePath(start, end, pathResult, totalCostResult, digStrength, jumpHeight);
24042404

24052405
// It's ok if start and end nodes happen to be the same, the exact pixel locations are added at the front and end of the result regardless
24062406
return (result == micropather::MicroPather::SOLVED || result == micropather::MicroPather::START_END_SAME) ? totalCostResult : -1;
24072407
}
24082408

2409-
std::shared_ptr<volatile PathRequest> Scene::CalculatePathAsync(const Vector& start, const Vector& end, float digStrength, Activity::Teams team, PathCompleteCallback callback) {
2410-
return GetPathFinder(team).CalculatePathAsync(start, end, digStrength, callback);
2409+
std::shared_ptr<volatile PathRequest> Scene::CalculatePathAsync(const Vector& start, const Vector& end, float digStrength, float jumpHeight, Activity::Teams team, PathCompleteCallback callback) {
2410+
return GetPathFinder(team).CalculatePathAsync(start, end, digStrength, jumpHeight, callback);
24112411
}
24122412

24132413
int Scene::GetScenePathSize() const {

Source/Entities/Scene.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -652,20 +652,24 @@ namespace RTE {
652652
/// When pathing using the NoTeam pathFinder, no doors are considered passable.
653653
/// @param start Start and end positions on the scene to find the path between.
654654
/// @param end A list which will be filled out with waypoints between the start and end.
655-
/// @param pathResult The maximum material strength any actor traveling along the path can dig through.
656-
/// @param digStrength The team we're pathing for (doors for this team will be considered passable) (default: c_PathFindingDefaultDigStrength)
655+
/// @param pathResult The generated path.
656+
/// @param digStrength The maximum material strength any actor traveling along the path can dig through.
657+
/// @param jumpHeight How high, in metres, the search can jump vertically.
658+
/// @param team The team we're pathing for (doors for this team will be considered passable).
657659
/// @return The total minimum difficulty cost calculated between the two points on
658660
/// the scene.
659-
float CalculatePath(const Vector& start, const Vector& end, std::list<Vector>& pathResult, float digStrength = c_PathFindingDefaultDigStrength, Activity::Teams team = Activity::Teams::NoTeam);
661+
float CalculatePath(const Vector& start, const Vector& end, std::list<Vector>& pathResult, float digStrength = c_PathFindingDefaultDigStrength, float jumpHeight = FLT_MAX, Activity::Teams team = Activity::Teams::NoTeam);
660662

661663
/// Asynchronously calculates the least difficult path between two points on the current Scene. Takes both distance and materials into account.
662664
/// When pathing using the NoTeam pathFinder, no doors are considered passable.
663665
/// @param start Start position of the pathfinding request.
664666
/// @param end End position of the pathfinding request.
665667
/// @param digStrength The maximum material strength any actor traveling along the path can dig through.
666-
/// @param team The team we're pathing for (doors for this team will be considered passable)
668+
/// @param jumpHeight How high, in metres, the search can jump vertically.
669+
/// @param team The team we're pathing for (doors for this team will be considered passable).
670+
/// @param callback The callback function we'll call after our pathfind request has finished calculating.
667671
/// @return A shared pointer to the volatile PathRequest to be used to track whehter the asynchrnous path calculation has been completed, and check its results.
668-
std::shared_ptr<volatile PathRequest> CalculatePathAsync(const Vector& start, const Vector& end, float digStrength = c_PathFindingDefaultDigStrength, Activity::Teams team = Activity::Teams::NoTeam, PathCompleteCallback callback = nullptr);
672+
std::shared_ptr<volatile PathRequest> CalculatePathAsync(const Vector& start, const Vector& end, float digStrength = c_PathFindingDefaultDigStrength, float jumpHeight = FLT_MAX, Activity::Teams team = Activity::Teams::NoTeam, PathCompleteCallback callback = nullptr);
669673

670674
/// Gets how many waypoints there are in the ScenePath currently
671675
/// @return The number of waypoints in the ScenePath.

Source/Lua/LuaAdapterDefinitions.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,21 @@ namespace RTE {
301301

302302
#pragma region Scene Lua Adapters
303303
struct LuaAdaptersScene {
304-
static int CalculatePath1(Scene* luaSelfObject, const Vector& start, const Vector& end, bool movePathToGround, float digStrength) { return CalculatePath2(luaSelfObject, start, end, movePathToGround, digStrength, Activity::Teams::NoTeam); }
305-
static int CalculatePath2(Scene* luaSelfObject, const Vector& start, const Vector& end, bool movePathToGround, float digStrength, Activity::Teams team);
306-
307-
static void CalculatePathAsync1(Scene* luaSelfObject, const luabind::object& callback, const Vector& start, const Vector& end, bool movePathToGround, float digStrength) { return CalculatePathAsync2(luaSelfObject, callback, start, end, movePathToGround, digStrength, Activity::Teams::NoTeam); }
308-
static void CalculatePathAsync2(Scene* luaSelfObject, const luabind::object& callback, const Vector& start, const Vector& end, bool movePathToGround, float digStrength, Activity::Teams team);
304+
static int CalculatePath1(Scene* luaSelfObject, const Vector& start, const Vector& end, bool movePathToGround, float digStrength) {
305+
return CalculatePath(luaSelfObject, start, end, movePathToGround, digStrength, FLT_MAX, Activity::Teams::NoTeam);
306+
}
307+
static int CalculatePath2(Scene* luaSelfObject, const Vector& start, const Vector& end, bool movePathToGround, float digStrength, Activity::Teams team) {
308+
return CalculatePath(luaSelfObject, start, end, movePathToGround, digStrength, FLT_MAX, team);
309+
}
310+
static int CalculatePath(Scene* luaSelfObject, const Vector& start, const Vector& end, bool movePathToGround, float digStrength, float jumpHeight, Activity::Teams team);
311+
312+
static void CalculatePathAsync1(Scene* luaSelfObject, const luabind::object& callback, const Vector& start, const Vector& end, bool movePathToGround, float digStrength) {
313+
return CalculatePathAsync(luaSelfObject, callback, start, end, movePathToGround, digStrength, FLT_MAX, Activity::Teams::NoTeam);
314+
}
315+
static void CalculatePathAsync2(Scene* luaSelfObject, const luabind::object& callback, const Vector& start, const Vector& end, bool movePathToGround, float digStrength, Activity::Teams team) {
316+
return CalculatePathAsync(luaSelfObject, callback, start, end, movePathToGround, digStrength, FLT_MAX, team);
317+
}
318+
static void CalculatePathAsync(Scene* luaSelfObject, const luabind::object& callback, const Vector& start, const Vector& end, bool movePathToGround, float digStrength, float jumpHeight, Activity::Teams team);
309319
};
310320
#pragma endregion
311321

Source/Lua/LuaAdapters.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ std::vector<Vector>* LuaAdaptersActor::GetSceneWaypoints(Actor* luaSelfObject) {
275275
return sceneWaypoints;
276276
}
277277

278-
int LuaAdaptersScene::CalculatePath2(Scene* luaSelfObject, const Vector& start, const Vector& end, bool movePathToGround, float digStrength, Activity::Teams team) {
278+
int LuaAdaptersScene::CalculatePath(Scene* luaSelfObject, const Vector& start, const Vector& end, bool movePathToGround, float digStrength, float jumpHeight, Activity::Teams team) {
279279
std::list<Vector>& threadScenePath = luaSelfObject->GetScenePath();
280280
team = std::clamp(team, Activity::Teams::NoTeam, Activity::Teams::TeamFour);
281-
luaSelfObject->CalculatePath(start, end, threadScenePath, digStrength, team);
281+
luaSelfObject->CalculatePath(start, end, threadScenePath, digStrength, jumpHeight, team);
282282
if (!threadScenePath.empty()) {
283283
if (movePathToGround) {
284284
for (Vector& scenePathPoint: threadScenePath) {
@@ -291,7 +291,7 @@ int LuaAdaptersScene::CalculatePath2(Scene* luaSelfObject, const Vector& start,
291291
return -1;
292292
}
293293

294-
void LuaAdaptersScene::CalculatePathAsync2(Scene* luaSelfObject, const luabind::object& callbackParam, const Vector& start, const Vector& end, bool movePathToGround, float digStrength, Activity::Teams team) {
294+
void LuaAdaptersScene::CalculatePathAsync(Scene* luaSelfObject, const luabind::object& callbackParam, const Vector& start, const Vector& end, bool movePathToGround, float digStrength, float jumpHeight, Activity::Teams team) {
295295
team = std::clamp(team, Activity::Teams::NoTeam, Activity::Teams::TeamFour);
296296

297297
// So, luabind::object is a weak reference, holding just a stack and a position in the stack
@@ -319,7 +319,7 @@ void LuaAdaptersScene::CalculatePathAsync2(Scene* luaSelfObject, const luabind::
319319
});
320320
};
321321

322-
luaSelfObject->CalculatePathAsync(start, end, digStrength, team, callLuaCallback);
322+
luaSelfObject->CalculatePathAsync(start, end, digStrength, jumpHeight, team, callLuaCallback);
323323
}
324324

325325
void LuaAdaptersAHuman::ReloadFirearms(AHuman* luaSelfObject) {

0 commit comments

Comments
 (0)