Update editor docs and crouch fix

* Bots now properly crouch in crouch areas rather than relying on their stuck detection to do it
* Updated Nav Editor docs to reflect recent changes
This commit is contained in:
RGreenlees 2024-06-29 20:31:51 +01:00 committed by pierow
parent 290ad067eb
commit b1bcdd2f70
5 changed files with 49 additions and 9 deletions

View file

@ -5605,7 +5605,7 @@ bool AICOMM_BuildOutOutpost(AvHAIPlayer* pBot, AvHAIMarineBase* BaseToBuildOut)
return pBot->Player->GetResources() <= 15; return pBot->Player->GetResources() <= 15;
} }
Vector BuildLocation = AITAC_GetRandomBuildHintInLocation(StructureToDeploy, BaseToBuildOut->BaseLocation, UTIL_MetresToGoldSrcUnits(10.0f)); Vector BuildLocation = AITAC_GetRandomBuildHintInLocation(StructureToDeploy, BaseToBuildOut->BaseLocation, UTIL_MetresToGoldSrcUnits(15.0f));
if (!vIsZero(BuildLocation)) if (!vIsZero(BuildLocation))
{ {

View file

@ -342,7 +342,17 @@ void AIDEBUG_DrawPath(edict_t* OutputPlayer, vector<bot_path_node>& path, float
UTIL_DrawLine(OutputPlayer, FromLoc, ToLoc, DrawTime, 255, 128, 128); UTIL_DrawLine(OutputPlayer, FromLoc, ToLoc, DrawTime, 255, 128, 128);
break; break;
default: default:
UTIL_DrawLine(OutputPlayer, FromLoc, ToLoc, DrawTime); {
if (it->area == SAMPLE_POLYAREA_CROUCH)
{
UTIL_DrawLine(OutputPlayer, FromLoc, ToLoc, DrawTime, 255, 150, 150);
}
else
{
UTIL_DrawLine(OutputPlayer, FromLoc, ToLoc, DrawTime);
}
}
break; break;
} }
} }

View file

@ -2386,24 +2386,27 @@ bool HasBotReachedPathPoint(const AvHAIPlayer* pBot)
bot_path_node CurrentPathNode = pBot->BotNavInfo.CurrentPath[pBot->BotNavInfo.CurrentPathPoint]; bot_path_node CurrentPathNode = pBot->BotNavInfo.CurrentPath[pBot->BotNavInfo.CurrentPathPoint];
SamplePolyFlags CurrentNavFlag = (SamplePolyFlags)CurrentPathNode.flag; SamplePolyFlags CurrentNavFlag = (SamplePolyFlags)CurrentPathNode.flag;
SamplePolyAreas CurrentNavArea = (SamplePolyAreas)CurrentPathNode.area;
Vector MoveFrom = CurrentPathNode.FromLocation; Vector MoveFrom = CurrentPathNode.FromLocation;
Vector MoveTo = CurrentPathNode.Location; Vector MoveTo = CurrentPathNode.Location;
float RequiredClimbHeight = CurrentPathNode.requiredZ; float RequiredClimbHeight = CurrentPathNode.requiredZ;
Vector NextMoveLocation = ZERO_VECTOR; Vector NextMoveLocation = ZERO_VECTOR;
SamplePolyFlags NextMoveFlag = SAMPLE_POLYFLAGS_DISABLED; SamplePolyFlags NextMoveFlag = SAMPLE_POLYFLAGS_DISABLED;
SamplePolyAreas NextMoveArea = SAMPLE_POLYAREA_GROUND;
if ((pBot->BotNavInfo.CurrentPathPoint + 1) < pBot->BotNavInfo.CurrentPath.size()) if ((pBot->BotNavInfo.CurrentPathPoint + 1) < pBot->BotNavInfo.CurrentPath.size())
{ {
bot_path_node NextPathNode = pBot->BotNavInfo.CurrentPath[pBot->BotNavInfo.CurrentPathPoint + 1]; bot_path_node NextPathNode = pBot->BotNavInfo.CurrentPath[pBot->BotNavInfo.CurrentPathPoint + 1];
NextMoveLocation = NextPathNode.Location; NextMoveLocation = NextPathNode.Location;
NextMoveFlag = (SamplePolyFlags)NextPathNode.flag; NextMoveFlag = (SamplePolyFlags)NextPathNode.flag;
NextMoveArea = (SamplePolyAreas)NextPathNode.area;
} }
switch (CurrentNavFlag) switch (CurrentNavFlag)
{ {
case SAMPLE_POLYFLAGS_WALK: case SAMPLE_POLYFLAGS_WALK:
return HasBotCompletedWalkMove(pBot, MoveFrom, MoveTo, NextMoveLocation, NextMoveFlag); return HasBotCompletedWalkMove(pBot, MoveFrom, MoveTo, CurrentNavArea, NextMoveLocation, NextMoveFlag, NextMoveArea);
case SAMPLE_POLYFLAGS_WELD: case SAMPLE_POLYFLAGS_WELD:
case SAMPLE_POLYFLAGS_DOOR: case SAMPLE_POLYFLAGS_DOOR:
case SAMPLE_POLYFLAGS_TEAM1STRUCTURE: case SAMPLE_POLYFLAGS_TEAM1STRUCTURE:
@ -2425,17 +2428,17 @@ bool HasBotReachedPathPoint(const AvHAIPlayer* pBot)
case SAMPLE_POLYFLAGS_LIFT: case SAMPLE_POLYFLAGS_LIFT:
return HasBotCompletedLiftMove(pBot, MoveFrom, MoveTo, NextMoveLocation, NextMoveFlag); return HasBotCompletedLiftMove(pBot, MoveFrom, MoveTo, NextMoveLocation, NextMoveFlag);
default: default:
return HasBotCompletedWalkMove(pBot, MoveFrom, MoveTo, NextMoveLocation, NextMoveFlag); return HasBotCompletedWalkMove(pBot, MoveFrom, MoveTo, CurrentNavArea, NextMoveLocation, NextMoveFlag, NextMoveArea);
} }
return HasBotCompletedWalkMove(pBot, MoveFrom, MoveTo, NextMoveLocation, NextMoveFlag); return HasBotCompletedWalkMove(pBot, MoveFrom, MoveTo, CurrentNavArea, NextMoveLocation, NextMoveFlag, NextMoveArea);
} }
bool HasBotCompletedWalkMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, Vector NextMoveDestination, SamplePolyFlags NextMoveFlag) bool HasBotCompletedWalkMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, SamplePolyAreas MoveArea, Vector NextMoveDestination, SamplePolyFlags NextMoveFlag, SamplePolyAreas NextMoveArea)
{ {
bool bNextPointReachable = false; bool bNextPointReachable = false;
if (NextMoveFlag != SAMPLE_POLYFLAGS_DISABLED) if (NextMoveFlag != SAMPLE_POLYFLAGS_DISABLED && MoveArea == NextMoveArea)
{ {
bNextPointReachable = UTIL_PointIsDirectlyReachable(pBot->CurrentFloorPosition, NextMoveDestination, GetPlayerRadius(pBot->Edict)); bNextPointReachable = UTIL_PointIsDirectlyReachable(pBot->CurrentFloorPosition, NextMoveDestination, GetPlayerRadius(pBot->Edict));
} }
@ -3571,6 +3574,8 @@ void GroundMove(AvHAIPlayer* pBot, const Vector StartPoint, const Vector EndPoin
Vector vForward = UTIL_GetVectorNormal2D(EndPoint - CurrentPos); Vector vForward = UTIL_GetVectorNormal2D(EndPoint - CurrentPos);
bool bShouldCrouch = false;
// If we are over our current path point and can't get to it, try walking towards the next path point if we have one, or just directly forwards // If we are over our current path point and can't get to it, try walking towards the next path point if we have one, or just directly forwards
if (vIsZero(vForward)) if (vIsZero(vForward))
{ {
@ -3586,6 +3591,31 @@ void GroundMove(AvHAIPlayer* pBot, const Vector StartPoint, const Vector EndPoin
} }
} }
if (CanPlayerCrouch(pBot->Edict))
{
if (CurrentPathNode.area == SAMPLE_POLYAREA_CROUCH)
{
bShouldCrouch = true;
}
else
{
if (pBot->BotNavInfo.CurrentPathPoint < pBot->BotNavInfo.CurrentPath.size() - 1)
{
bot_path_node NextPathNode = pBot->BotNavInfo.CurrentPath[pBot->BotNavInfo.CurrentPathPoint + 1];
if (NextPathNode.area == SAMPLE_POLYAREA_CROUCH && vDist2DSq(pBot->Edict->v.origin, NextPathNode.FromLocation) < sqrf(64.0f))
{
bShouldCrouch = true;
}
}
}
}
if (bShouldCrouch)
{
pBot->Button |= IN_DUCK;
}
// Same goes for the right vector, might not be the same as the bot's right // Same goes for the right vector, might not be the same as the bot's right
Vector vRight = UTIL_GetVectorNormal(UTIL_GetCrossProduct(vForward, UP_VECTOR)); Vector vRight = UTIL_GetVectorNormal(UTIL_GetCrossProduct(vForward, UP_VECTOR));
@ -3667,7 +3697,7 @@ void GroundMove(AvHAIPlayer* pBot, const Vector StartPoint, const Vector EndPoin
pBot->desiredMovementDir = UTIL_GetVectorNormal2D(pBot->desiredMovementDir); pBot->desiredMovementDir = UTIL_GetVectorNormal2D(pBot->desiredMovementDir);
if (CanPlayerCrouch(pEdict)) if (!bShouldCrouch && CanPlayerCrouch(pEdict))
{ {
Vector HeadLocation = GetPlayerTopOfCollisionHull(pEdict, false); Vector HeadLocation = GetPlayerTopOfCollisionHull(pEdict, false);

View file

@ -220,7 +220,7 @@ void NewMove(AvHAIPlayer* pBot);
// Returns true if the bot has completed the current movement along their path // Returns true if the bot has completed the current movement along their path
bool HasBotReachedPathPoint(const AvHAIPlayer* pBot); bool HasBotReachedPathPoint(const AvHAIPlayer* pBot);
bool HasBotCompletedLadderMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, Vector NextMoveDestination, SamplePolyFlags NextMoveFlag); bool HasBotCompletedLadderMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, Vector NextMoveDestination, SamplePolyFlags NextMoveFlag);
bool HasBotCompletedWalkMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, Vector NextMoveDestination, SamplePolyFlags NextMoveFlag); bool HasBotCompletedWalkMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, SamplePolyAreas MoveArea, Vector NextMoveDestination, SamplePolyFlags NextMoveFlag, SamplePolyAreas NextMoveArea);
bool HasBotCompletedFallMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, Vector NextMoveDestination, SamplePolyFlags NextMoveFlag); bool HasBotCompletedFallMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, Vector NextMoveDestination, SamplePolyFlags NextMoveFlag);
bool HasBotCompletedClimbMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, float RequiredClimbHeight, Vector NextMoveDestination, SamplePolyFlags NextMoveFlag); bool HasBotCompletedClimbMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, float RequiredClimbHeight, Vector NextMoveDestination, SamplePolyFlags NextMoveFlag);
bool HasBotCompletedJumpMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, Vector NextMoveDestination, SamplePolyFlags NextMoveFlag); bool HasBotCompletedJumpMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, Vector NextMoveDestination, SamplePolyFlags NextMoveFlag);