Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculate navcon distance using the navcon end point #2990

Merged
merged 1 commit into from
May 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 14 additions & 30 deletions src/sgame/botlib/bot_nav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ void G_BotUpdatePath( int botClientNum, const botRouteTarget_t *target, botNavCm

cmd->havePath = !bot->needReplan;

bool usingNavcon = false;

if ( overOffMeshConnectionStart( bot, spos ) )
{
dtPolyRef refs[ 2 ];
Expand All @@ -301,7 +299,20 @@ void G_BotUpdatePath( int botClientNum, const botRouteTarget_t *target, botNavCm
bot->offMeshEnd = end;
bot->offMeshStart = start;

usingNavcon = true;
// save some characteristics about the connection in the bot's mind, for later use
// this happens quite rarely, so we can afford a square root for the
// distance here
gentity_t *self = &g_entities[ botClientNum ];
self->botMind->lastNavconTime = level.time;
glm::vec3 nextCorner = glm::vec3( end[ 0 ], end[ 2 ], end[ 1 ] );
glm::vec3 ownPos = VEC2GLM( self->s.origin );
// HACK: if the bot wants to move upward, make the distance
// positive, make it negative otherwise
self->botMind->lastNavconDistance = glm::distance( ownPos , nextCorner );
if ( nextCorner.z - ownPos.z < 0 )
{
self->botMind->lastNavconDistance = -self->botMind->lastNavconDistance;
}
}
}

Expand Down Expand Up @@ -344,33 +355,6 @@ void G_BotUpdatePath( int botClientNum, const botRouteTarget_t *target, botNavCm
}
recast2quake( cmd->tpos );
}

// when the bot is using an offmesh connection:
// save some characteristics about the connection in its mind, for later use
// this happens quite rarely, so we can afford a square root for the
// distance here
if ( usingNavcon )
{
gentity_t *self = &g_entities[ botClientNum ];
self->botMind->lastNavconTime = level.time;
glm::vec3 nextCorner;
glm::vec3 ownPos = VEC2GLM( self->s.origin );
if ( G_BotPathNextCorner( self->client->num(), nextCorner ) )
{
// HACK: if the bot wants to move upward, make the distance
// positive, make it negative otherwise
self->botMind->lastNavconDistance = glm::distance( ownPos , nextCorner );
if ( nextCorner.z - ownPos.z < 0 )
{
self->botMind->lastNavconDistance = -self->botMind->lastNavconDistance;
}
}
else
{
// should not happen, but let's play it safe here
self->botMind->lastNavconDistance = 0;
}
}
}

if ( bot->offMesh )
Expand Down