Skip to content

Commit d9565a6

Browse files
committed
Refactored and moved some stuff around to replace MovePathToGround with jumpheight
1 parent 44494ed commit d9565a6

File tree

19 files changed

+71
-79
lines changed

19 files changed

+71
-79
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
<details><summary><b>Added</b></summary>
1010

1111
- Pathfinding and navigation overhaul, including jetpack/jump-aware pathfinding.
12-
Actors will now intelligently choose their path depending on how high they can jump, instead of always taking the shortest path. This will reduce instances of the AI getting stuck while trying to take impossible paths.
12+
Actors will now intelligently choose their path depending on how high they can jump, instead of always taking the shortest path. This will reduce instances of the AI getting stuck while trying to take impossible paths.
13+
In the `CalculatePath` and `CalculatePathAsync` functions, the parameter `movePathToGround` has been replaced with `jumpHeight`, which is the height in metres the pathfind can jump vertically.
14+
The new function `GetPathFindingFlyingJumpHeight()` can be used to get a jumpHeight that allows flying (i.e infinite jump height).
15+
New `Actor` Lua property `JumpHeight` (R) to estimate the jump height of the actor (in metres), based on the actor's jetpack and weight.
1316

1417
- New music system, including a dynamic horizontal sequencing system, under the new music manager `MusicMan`.
1518
`PlayDynamicSong(string songName, string songSectionName, bool playImmediately, bool playTransition, bool smoothFade)` to play a new DynamicSong.

Data/Base.rte/AI/HumanBehaviors.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ function HumanBehaviors.WeaponSearch(AI, Owner, Abort)
10071007
end
10081008
searchesRemaining = searchesRemaining - 1;
10091009
end,
1010-
Owner.Pos, device.Pos, false, Owner.DigStrength, Owner.Team
1010+
Owner.Pos, device.Pos, Owner.JumpHeight, Owner.DigStrength, Owner.Team
10111011
);
10121012
end
10131013
end
@@ -1123,7 +1123,7 @@ function HumanBehaviors.ToolSearch(AI, Owner, Abort)
11231123
end
11241124
searchesRemaining = searchesRemaining - 1;
11251125
end,
1126-
Owner.Pos, device.Pos, false, Owner.DigStrength, Owner.Team
1126+
Owner.Pos, device.Pos, Owner.JumpHeight, Owner.DigStrength, Owner.Team
11271127
);
11281128
end
11291129
end

Data/Base.rte/Activities/BunkerBreach.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ function BunkerBreach:SendDefenderGuardsAtEnemiesInsideBunker()
504504
local closestFriendlyUnitData = {};
505505
for _, friendlyUnitInsideBunker in pairs(self.AI.friendlyUnitsInsideBunker) do
506506
if not friendlyUnitInsideBunker:IsInGroup("Brains") then
507-
local pathLengthFromFriendlyUnitToEnemy = SceneMan.Scene:CalculatePath(friendlyUnitInsideBunker.Pos, enemyUnitInsideBunker.Pos, false, GetPathFindingDefaultDigStrength(), self.CPUTeam);
507+
local pathLengthFromFriendlyUnitToEnemy = SceneMan.Scene:CalculatePath(friendlyUnitInsideBunker.Pos, enemyUnitInsideBunker.Pos, GetPathFindingFlyingJumpHeight(), GetPathFindingDefaultDigStrength(), self.CPUTeam);
508508
if closestFriendlyUnitData.pathLengthToEnemy == nil or pathLengthFromFriendlyUnitToEnemy < closestFriendlyUnitData.pathLengthToEnemy then
509509
closestFriendlyUnitData.pathLengthToEnemy = pathLengthFromFriendlyUnitToEnemy;
510510
closestFriendlyUnitData.actor = friendlyUnitInsideBunker;
@@ -632,7 +632,7 @@ function BunkerBreach:CalculateInternalReinforcementPositionsToEnemyTargets(numb
632632
local internalReinforcementPositionForEnemy;
633633
local pathLengthFromClosestInternalReinforcementPositionToEnemy = SceneMan.SceneWidth * SceneMan.SceneHeight;
634634
for _, internalReinforcementPosition in pairs(self.AI.internalReinforcementPositions) do
635-
local pathLengthFromInternalReinforcementPositionToEnemy = SceneMan.Scene:CalculatePath(internalReinforcementPosition, enemyToTarget.Pos, false, GetPathFindingDefaultDigStrength(), self.CPUTeam);
635+
local pathLengthFromInternalReinforcementPositionToEnemy = SceneMan.Scene:CalculatePath(internalReinforcementPosition, enemyToTarget.Pos, GetPathFindingFlyingJumpHeight(), GetPathFindingDefaultDigStrength(), self.CPUTeam);
636636
if pathLengthFromInternalReinforcementPositionToEnemy < pathLengthFromClosestInternalReinforcementPositionToEnemy then
637637
internalReinforcementPositionForEnemy = internalReinforcementPosition;
638638
pathLengthFromClosestInternalReinforcementPositionToEnemy = pathLengthFromInternalReinforcementPositionToEnemy;

Data/Base.rte/Activities/Siege.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ function Siege:PlayerBrainsReachable()
469469

470470
for actor in MovableMan.Actors do
471471
if actor.Team == self.PlayerTeam and actor:IsInGroup("Brains") then
472-
local pathCost = SceneMan.Scene:CalculatePath(actor.Pos, Vector(actor.Pos.X, 0), false, 0);
472+
local pathCost = SceneMan.Scene:CalculatePath(actor.Pos, Vector(actor.Pos.X, 0), GetPathFindingFlyingJumpHeight(), GetPathFindingDefaultDigStrength());
473473
if pathCost > 10000 then
474474
reachable = false;
475475
break;

Data/Base.rte/Activities/Utility/LandingZoneMap.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ function LandingZoneMap:FindLZ(team, Destination, digStrenght)
454454
end
455455

456456
-- A coroutine that search for a LZ. Input is team and destination. Output is LZ x-pos and obstacle height for two LZs, one close and one with an easy path
457-
function LandingZoneMap.SearchForLZ(self, team, Destination, digStrenght)
457+
function LandingZoneMap.SearchForLZ(self, team, Destination, digStrength)
458458
-- estimate how visible our descent is to the enemy
459459
local LOSgrid = self.EnemyTeamLOS[team];
460460
local GoodLZs = {};
@@ -493,7 +493,7 @@ function LandingZoneMap.SearchForLZ(self, team, Destination, digStrenght)
493493
pathRequestsCompleted = pathRequestsCompleted + 1;
494494
completedPathRequests[k] = pathRequest;
495495
end,
496-
Vector(LZ.X, LZ.Y), Destination, false, digStrenght, team);
496+
Vector(LZ.X, LZ.Y), Destination, GetPathFindingFlyingJumpHeight(), digStrength, team);
497497
end
498498

499499
while pathRequestsCompleted < #GoodLZs do
@@ -650,7 +650,7 @@ function LandingZoneMap:FindStartLZ(team, OccupiedLZs)
650650
distance = nil;
651651
local PosLZ = Vector(LZ.X, LZ.Y);
652652
for _, PosEnemy in pairs(EnemyLocations) do
653-
local wpts = SceneMan.Scene:CalculatePath(PosEnemy, PosLZ, false, 1, team);
653+
local wpts = SceneMan.Scene:CalculatePath(PosEnemy, PosLZ, GetPathFindingFlyingJumpHeight(), GetPathFindingDefaultDigStrength(), team);
654654
if wpts > -1 then
655655
if distance then
656656
distance = math.min(wpts, distance);

Data/Base.rte/Scenes/Objects/Bunkers/BunkerSystems/Automovers/Controller/Controller.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ automoverUtilityFunctions.findNodeWithShortestScenePath = function(self, positio
752752

753753
local shortestPathCoroutine = coroutine.create(FindStartPositionWithShortestPathToEndPosition);
754754
while coroutine.status(shortestPathCoroutine) ~= "dead" do
755-
local _, result = coroutine.resume(shortestPathCoroutine, potentialClosestNodes, positionToFindClosestNodeFor, pathfinderTeam, false, pathfinderDigStrength);
755+
local _, result = coroutine.resume(shortestPathCoroutine, potentialClosestNodes, positionToFindClosestNodeFor, pathfinderTeam, GetPathFindingFlyingJumpHeight(), pathfinderDigStrength);
756756
if result then
757757
return result;
758758
else
@@ -1490,7 +1490,7 @@ automoverActorFunctions.handleActorThatHasReachedItsEndNode = function(self, act
14901490
end
14911491
end
14921492
end,
1493-
actor.Pos, waypointData.targetPosition, false, GetPathFindingDefaultDigStrength(), self.Team
1493+
actor.Pos, waypointData.targetPosition, GetPathFindingFlyingJumpHeight(), GetPathFindingDefaultDigStrength(), self.Team
14941494
);
14951495
elseif waypointData.exitPath ~= nil and #waypointData.exitPath > 0 then
14961496
local distanceFromActorToFirstExitPathPosition = SceneMan:ShortestDistance(waypointData.exitPath[1], actor.Pos, self.checkWrapping);

Data/Base.rte/Utilities.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function FindStartPositionWithShortestPathToEndPosition(startPositions, endPosition, team, movePathToGround, digStrength)
1+
function FindStartPositionWithShortestPathToEndPosition(startPositions, endPosition, team, jumpHeight, digStrength)
22
if startPositions == nil or type(startPositions) ~= "table" then
33
print("FindShortestPathAsync Error: A table of start positions is required.");
44
return;
@@ -12,7 +12,7 @@ function FindStartPositionWithShortestPathToEndPosition(startPositions, endPosit
1212
return;
1313
end
1414

15-
movePathToGround = movePathToGround or false;
15+
jumpHeight = jumpHeight or GetPathFindingFlyingJumpHeight();
1616
digStrength = digStrength or GetPathFindingDefaultDigStrength();
1717

1818
local closestStartPositionKey;
@@ -30,7 +30,7 @@ function FindStartPositionWithShortestPathToEndPosition(startPositions, endPosit
3030
end
3131
pathRequestsCompleted = pathRequestsCompleted + 1;
3232
end,
33-
startPosition, endPosition, movePathToGround, digStrength, team
33+
startPosition, endPosition, jumpHeight, digStrength, team
3434
);
3535
totalPathingRequests = totalPathingRequests + 1;
3636
end

Data/Missions.rte/Activities/DecisionDay.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ function DecisionDay:UpdateAIDecisions()
16731673
for movableObject in MovableMan:GetMOsInRadius(captureAreaCenter, self.aiData.bunkerRegionDefenseRange, self.humanTeam, true) do
16741674
if (IsAHuman(movableObject) or IsACrab(movableObject)) and (not movableObject:IsInGroup("AI Region Defenders") or movableObject:IsInGroup("AI Region Defenders - " .. bunkerRegionName)) and movableObject.PinStrength == 0 and not movableObject:IsInGroup("Actors - Turrets") then
16751675
--TODO when we have calculate path async with limited max path length, use it here. Will have to do coroutine, etc.
1676-
--local pathLengthToCaptureArea = SceneMan.Scene:CalculatePath(movableObject.Pos, captureAreaCenter, false, GetPathFindingDefaultDigStrength(), self.aiTeam) * 20;
1676+
--local pathLengthToCaptureArea = SceneMan.Scene:CalculatePath(movableObject.Pos, captureAreaCenter, GetPathFindingFlyingJumpHeight(), GetPathFindingDefaultDigStrength(), self.aiTeam) * 20;
16771677
--if pathLengthToCaptureArea < self.aiData.bunkerRegionDefenseRange then
16781678
local actor = ToActor(movableObject);
16791679
actor.AIMode = Actor.AIMODE_GOTO;

Source/Entities/Actor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -993,14 +993,14 @@ void Actor::UpdateMovePath() {
993993

994994
// If we're following someone/thing, then never advance waypoints until that thing disappears
995995
if (g_MovableMan.ValidMO(m_pMOMoveTarget)) {
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));
996+
m_PathRequest = g_SceneMan.GetScene()->CalculatePathAsync(g_SceneMan.MovePointToGround(m_Pos, m_CharHeight * 0.2, 10), m_pMOMoveTarget->GetPos(), jumpHeight, digStrength, static_cast<Activity::Teams>(m_Team));
997997
} else {
998998
// Do we currently have a path to a static target we would like to still pursue?
999999
if (m_MovePath.empty()) {
10001000
// Ok no path going, so get a new path to the next waypoint, if there is a next waypoint
10011001
if (!m_Waypoints.empty()) {
10021002
// Make sure the path starts from the ground and not somewhere up in the air if/when dropped out of ship
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));
1003+
m_PathRequest = g_SceneMan.GetScene()->CalculatePathAsync(g_SceneMan.MovePointToGround(m_Pos, m_CharHeight * 0.2, 10), m_Waypoints.front().first, jumpHeight, digStrength, static_cast<Activity::Teams>(m_Team));
10041004

10051005
// If the waypoint was tied to an MO to pursue, then load it into the current MO target
10061006
if (g_MovableMan.ValidMO(m_Waypoints.front().second)) {
@@ -1014,12 +1014,12 @@ void Actor::UpdateMovePath() {
10141014
}
10151015
// Just try to get to the last Move Target
10161016
else {
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));
1017+
m_PathRequest = g_SceneMan.GetScene()->CalculatePathAsync(g_SceneMan.MovePointToGround(m_Pos, m_CharHeight * 0.2, 10), m_MoveTarget, jumpHeight, digStrength, static_cast<Activity::Teams>(m_Team));
10181018
}
10191019
}
10201020
// We had a path before trying to update, so use its last point as the final destination
10211021
else {
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));
1022+
m_PathRequest = g_SceneMan.GetScene()->CalculatePathAsync(g_SceneMan.MovePointToGround(m_Pos, m_CharHeight * 0.2, 10), Vector(m_MovePath.back()), jumpHeight, digStrength, static_cast<Activity::Teams>(m_Team));
10231023
}
10241024
}
10251025

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, float jumpHeight, Activity::Teams team) {
2401+
float Scene::CalculatePath(const Vector& start, const Vector& end, std::list<Vector>& pathResult, float jumpHeight, float digStrength, Activity::Teams team) {
24022402
float totalCostResult = -1;
2403-
int result = GetPathFinder(team).CalculatePath(start, end, pathResult, totalCostResult, digStrength, jumpHeight);
2403+
int result = GetPathFinder(team).CalculatePath(start, end, pathResult, totalCostResult, jumpHeight, digStrength);
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, float jumpHeight, Activity::Teams team, PathCompleteCallback callback) {
2410-
return GetPathFinder(team).CalculatePathAsync(start, end, digStrength, jumpHeight, callback);
2409+
std::shared_ptr<volatile PathRequest> Scene::CalculatePathAsync(const Vector& start, const Vector& end, float jumpHeight, float digStrength, Activity::Teams team, PathCompleteCallback callback) {
2410+
return GetPathFinder(team).CalculatePathAsync(start, end, jumpHeight, digStrength, callback);
24112411
}
24122412

24132413
int Scene::GetScenePathSize() const {

0 commit comments

Comments
 (0)