Skip to content

Commit 2856faf

Browse files
committed
Automovers and nav improvements
1 parent b86f42f commit 2856faf

File tree

3 files changed

+18
-60
lines changed

3 files changed

+18
-60
lines changed

Data/Base.rte/AI/HumanBehaviors.lua

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,24 +1894,23 @@ function HumanBehaviors.GoToWpt(AI, Owner, Abort)
18941894
local TmpWpts = {};
18951895
table.insert(TmpWpts, {Pos=Owner.Pos});
18961896

1897-
local Origin;
18981897
local LastPos = PathDump[1];
18991898
local index = 1;
19001899
for _, WptPos in pairs(PathDump) do
1901-
Origin = TmpWpts[index].Pos;
1902-
local Dist = SceneMan:ShortestDistance(Origin, WptPos, false);
1903-
if math.abs(Dist.Y) > 30 or Dist:MagnitudeIsGreaterThan(80) or -- skip any waypoint too close to the previous one
1904-
SceneMan:CastStrengthSumRay(Origin, WptPos, 3, rte.grassID) > 5
1905-
then
1900+
--Origin = TmpWpts[index].Pos;
1901+
--local Dist = SceneMan:ShortestDistance(Origin, WptPos, false);
1902+
--if math.abs(Dist.Y) > 30 or Dist:MagnitudeIsGreaterThan(80) or -- skip any waypoint too close to the previous one
1903+
-- SceneMan:CastStrengthSumRay(Origin, WptPos, 3, rte.grassID) > 5
1904+
--then
19061905
table.insert(TmpWpts, {Pos=LastPos});
19071906
index = index + 1;
1908-
end
1907+
--end
19091908

19101909
LastPos = WptPos;
19111910
end
19121911

19131912
-- No path
1914-
if #PathDump == 0 then
1913+
if #TmpWpts == 0 then
19151914
break;
19161915
end
19171916

@@ -1922,50 +1921,6 @@ function HumanBehaviors.GoToWpt(AI, Owner, Abort)
19221921
while TmpWpts[1] do
19231922
local NextWpt = table.remove(TmpWpts, 1);
19241923

1925-
if Lower(NextWpt, StartWpt, 30) then -- scan for sharp drops
1926-
local Dist = SceneMan:ShortestDistance(StartWpt.Pos, NextWpt.Pos, false);
1927-
if math.abs(Dist.X) < Dist.Y then -- check the slope
1928-
if SceneMan:CastObstacleRay(StartWpt.Pos, Dist, Vector(), Vector(), Owner.ID, Owner.IgnoresWhichTeam, rte.grassID, 4) < 0 then
1929-
NextWpt.Type = "drop"; -- LOS from StartWpt to NextWpt
1930-
end
1931-
1932-
local GapList = {};
1933-
for j, JumpWpt in pairs(TmpWpts) do -- look for the other side
1934-
local Gap = SceneMan:ShortestDistance(StartWpt.Pos, JumpWpt.Pos, false);
1935-
if Gap:MagnitudeIsGreaterThan(400 - Gap.Y) then -- TODO: use actor properties here
1936-
break; -- too far
1937-
end
1938-
1939-
if Gap.Y > -40 then -- no more than 2m above
1940-
table.insert(GapList, {Wpt=JumpWpt, score=math.abs(Gap.X/Gap.Y), index=j});
1941-
end
1942-
end
1943-
1944-
table.sort(GapList, function(A, B) return A.score > B.score end); -- sort largest first
1945-
1946-
for _, LZ in pairs(GapList) do
1947-
-- check if we can jump
1948-
local Trace = SceneMan:ShortestDistance(StartWpt.Pos, LZ.Wpt.Pos, false);
1949-
if SceneMan:CastObstacleRay(StartWpt.Pos, Trace, Vector(), Vector(), Owner.ID, Owner.IgnoresWhichTeam, rte.grassID, 4) < 0 then
1950-
-- find a point mid-air
1951-
local TestPos = StartWpt.Pos + Trace * 0.6;
1952-
local Free = Vector();
1953-
if 0 ~= SceneMan:CastObstacleRay(TestPos, Vector(0, -math.abs(Trace.X)/2), Vector(), Free, Owner.ID, Owner.IgnoresWhichTeam, rte.grassID, 2) then -- TODO: check LOS? what if 0?
1954-
table.insert(WptList, {Pos=Free+Vector(0,Owner.Height/3), Type="air"}); -- guide point in the air
1955-
NextWpt = LZ.Wpt;
1956-
1957-
-- delete any waypoints between StartWpt and the LZ
1958-
for i = LZ.index, 1, -1 do
1959-
table.remove(TmpWpts, i);
1960-
end
1961-
1962-
break;
1963-
end
1964-
end
1965-
end
1966-
end
1967-
end
1968-
19691924
table.insert(WptList, NextWpt);
19701925
StartWpt = NextWpt;
19711926
end

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,8 @@ automoverActorFunctions.updateDirectionsFromActorControllerInput = function(self
11321132
actor:RemoveMovePathBeginning();
11331133
end
11341134

1135+
analogMove:Normalize();
1136+
11351137
if (actor.Pos - actor.PrevPos):MagnitudeIsLessThan(0.05) then
11361138
-- choose a random direction to get unstuck
11371139
-- TODO, it'd be better if the AI logic can communicate this to us instead!
@@ -1579,16 +1581,17 @@ automoverActorFunctions.centreActorToClosestNodeIfMovingInAppropriateDirection =
15791581
local centeringSpeedAndDistance = self.movementAcceleration * 5;
15801582

15811583
for _, centeringAxis in pairs(centeringAxes) do
1582-
if actor.MovePathSize > 0 then
1584+
if actor.MovePathSize > 0 and directionConnectingArea == nil ~= nil then
15831585
-- Collect all points ahead of us in the box to adjust to centre
15841586
local positionsToFixUp = {};
1587+
local stop = false;
15851588
for pos in actor.MovePath do
1586-
if pos[centeringAxis] == closestNode.Pos[centeringAxis] or directionConnectingArea == nil or not directionConnectingArea:IsInside(pos) then
1587-
break;
1588-
end
15891589
local adjustedPos = pos;
15901590
adjustedPos[centeringAxis] = closestNode.Pos[centeringAxis];
15911591
table.insert(positionsToFixUp, adjustedPos);
1592+
if not directionConnectingArea:IsInside(pos) then
1593+
break;
1594+
end
15921595
end
15931596

15941597
-- Clear these points from our move path

Source/System/PathFinder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,13 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
313313
adjacentList->push_back(adjCost);
314314
}
315315

316-
if (node->RightDown && node->RightDown->m_Navigatable && !isInNoGrav) {
316+
if (node->RightDown && node->RightDown->m_Navigatable && allowDiagonal) {
317317
adjCost.cost = 1.4F + (GetMaterialTransitionCost(*node->RightDownMaterial) * 1.4F) + radiatedCost;
318318
adjCost.state = static_cast<void*>(node->RightDown);
319319
adjacentList->push_back(adjCost);
320320
}
321321

322-
if (node->DownLeft && node->DownLeft->m_Navigatable && !isInNoGrav) {
322+
if (node->DownLeft && node->DownLeft->m_Navigatable && allowDiagonal) {
323323
adjCost.cost = 1.4F + (GetMaterialTransitionCost(*node->DownLeftMaterial) * 1.4F) + radiatedCost;
324324
adjCost.state = static_cast<void*>(node->DownLeft);
325325
adjacentList->push_back(adjCost);
@@ -411,13 +411,13 @@ void PathFinder::AdjacentCost(void* state, std::vector<micropather::StateCost>*
411411
}
412412

413413
// Add cost for digging at 45 degrees and for digging upwards.
414-
if (node->UpRight && node->UpRight->m_Navigatable && !isInNoGrav) {
414+
if (node->UpRight && node->UpRight->m_Navigatable && allowDiagonal) {
415415
adjCost.cost = 1.4F + (extraUpCost * 1.4F) + (GetMaterialTransitionCost(*node->UpRightMaterial) * 1.4F * 3.0F) + radiatedCost; // Three times more expensive when digging.
416416
adjCost.state = static_cast<void*>(node->UpRight);
417417
adjacentList->push_back(adjCost);
418418
}
419419

420-
if (node->LeftUp && node->LeftUp->m_Navigatable && !isInNoGrav) {
420+
if (node->LeftUp && node->LeftUp->m_Navigatable && allowDiagonal) {
421421
adjCost.cost = 1.4F + (extraUpCost * 1.4F) + (GetMaterialTransitionCost(*node->LeftUpMaterial) * 1.4F * 3.0F) + radiatedCost; // Three times more expensive when digging.
422422
adjCost.state = static_cast<void*>(node->LeftUp);
423423
adjacentList->push_back(adjCost);

0 commit comments

Comments
 (0)