mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-29 06:07:57 +03:00
Improve bot movements
- Do random movements if the path cannot be found - Reset the movement if the bot is really blocked - Set an higher fall height
This commit is contained in:
parent
090ba308d8
commit
dfde4a58de
2 changed files with 36 additions and 22 deletions
|
@ -50,7 +50,7 @@ PlayerBot::PlayerBot()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Path.SetFallHeight(96);
|
m_Path.SetFallHeight(400);
|
||||||
m_bPathing = false;
|
m_bPathing = false;
|
||||||
m_bTempAway = false;
|
m_bTempAway = false;
|
||||||
m_bDeltaMove = true;
|
m_bDeltaMove = true;
|
||||||
|
@ -77,6 +77,7 @@ PlayerBot::PlayerBot()
|
||||||
m_vCurrentAng = vec_zero;
|
m_vCurrentAng = vec_zero;
|
||||||
m_iCheckPathTime = 0;
|
m_iCheckPathTime = 0;
|
||||||
m_iTempAwayTime = 0;
|
m_iTempAwayTime = 0;
|
||||||
|
m_iNumBlocks = 0;
|
||||||
m_fYawSpeedMult = 1.0f;
|
m_fYawSpeedMult = 1.0f;
|
||||||
|
|
||||||
m_iCuriousTime = 0;
|
m_iCuriousTime = 0;
|
||||||
|
@ -213,6 +214,7 @@ void PlayerBot::MoveThink(void)
|
||||||
m_Path.FindPath(origin, m_vTargetPos, this, 0, NULL, 0);
|
m_Path.FindPath(origin, m_vTargetPos, this, 0, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!m_bTempAway) {
|
||||||
if (m_Path.CurrentNode()) {
|
if (m_Path.CurrentNode()) {
|
||||||
m_Path.UpdatePos(origin, 8);
|
m_Path.UpdatePos(origin, 8);
|
||||||
|
|
||||||
|
@ -223,8 +225,7 @@ void PlayerBot::MoveThink(void)
|
||||||
// Clear the path
|
// Clear the path
|
||||||
m_Path.Clear();
|
m_Path.Clear();
|
||||||
}
|
}
|
||||||
} else if (!m_bTempAway) {
|
}
|
||||||
m_vCurrentGoal = origin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ai_debugpath->integer) {
|
if (ai_debugpath->integer) {
|
||||||
|
@ -233,29 +234,32 @@ void PlayerBot::MoveThink(void)
|
||||||
|
|
||||||
// Check if we're blocked
|
// Check if we're blocked
|
||||||
if (level.inttime >= m_iCheckPathTime) {
|
if (level.inttime >= m_iCheckPathTime) {
|
||||||
Vector end;
|
|
||||||
|
|
||||||
m_bDeltaMove = false;
|
m_bDeltaMove = false;
|
||||||
|
|
||||||
m_iCheckPathTime = level.inttime + 2000;
|
m_iCheckPathTime = level.inttime + 2000;
|
||||||
|
|
||||||
if (m_Path.CurrentNode() && m_Path.CurrentNode() != m_Path.LastNode()) {
|
if (m_iNumBlocks >= 10) {
|
||||||
end = m_Path.NextNode()->point;
|
// Give up
|
||||||
} else {
|
ClearMove();
|
||||||
end = m_vCurrentGoal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetMoveResult() >= MOVERESULT_BLOCKED || velocity.lengthSquared() <= 8 * 8) {
|
if (GetMoveResult() >= MOVERESULT_BLOCKED || velocity.lengthSquared() <= Square(8)) {
|
||||||
gi.DPrintf2("Updating path for bot client %i\n", edict - g_entities);
|
|
||||||
|
|
||||||
m_bTempAway = true;
|
m_bTempAway = true;
|
||||||
m_bDeltaMove = false;
|
m_bDeltaMove = false;
|
||||||
m_iTempAwayTime = level.inttime + 750;
|
m_iTempAwayTime = level.inttime + 750;
|
||||||
|
m_iNumBlocks++;
|
||||||
|
|
||||||
// Try to backward a little
|
// Try to backward a little
|
||||||
m_Path.Clear();
|
m_Path.Clear();
|
||||||
m_vCurrentGoal = origin + Vector(G_Random(256) - 128, G_Random(256) - 128, G_Random(256) - 128);
|
m_vCurrentGoal = origin + Vector(G_Random(256) - 128, G_Random(256) - 128, G_Random(256) - 128);
|
||||||
return;
|
} else {
|
||||||
|
m_iNumBlocks = 0;
|
||||||
|
|
||||||
|
if (!m_Path.CurrentNode()) {
|
||||||
|
m_vTargetPos = origin + Vector(G_Random(256) - 128, G_Random(256) - 128, G_Random(256) - 128);
|
||||||
|
m_vCurrentGoal = m_vTargetPos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,9 +279,15 @@ void PlayerBot::MoveThink(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((m_vTargetPos - origin).lengthSquared() <= 16 * 16) {
|
if (m_Path.CurrentNode()) {
|
||||||
|
if ((m_vTargetPos - origin).lengthSquared() <= Square(16)) {
|
||||||
ClearMove();
|
ClearMove();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if ((m_vTargetPos - origin).lengthXYSquared() <= Square(16)) {
|
||||||
|
ClearMove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//vDir = m_vCurrentGoal - centroid;
|
//vDir = m_vCurrentGoal - centroid;
|
||||||
|
|
||||||
|
@ -749,6 +759,7 @@ void PlayerBot::ClearMove(void)
|
||||||
{
|
{
|
||||||
m_Path.Clear();
|
m_Path.Clear();
|
||||||
m_bPathing = false;
|
m_bPathing = false;
|
||||||
|
m_iNumBlocks = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -795,7 +806,9 @@ void PlayerBot::AvoidPath(
|
||||||
m_Path.FindPathAway(origin, vAvoid, vDir, this, fAvoidRadius, vLeashHome, fLeashRadius * fLeashRadius);
|
m_Path.FindPathAway(origin, vAvoid, vDir, this, fAvoidRadius, vLeashHome, fLeashRadius * fLeashRadius);
|
||||||
|
|
||||||
if (!m_Path.CurrentNode()) {
|
if (!m_Path.CurrentNode()) {
|
||||||
m_bPathing = false;
|
// Random movements
|
||||||
|
m_vTargetPos = origin + Vector(G_Random(256) - 128, G_Random(256) - 128, G_Random(256) - 128);
|
||||||
|
m_vCurrentGoal = m_vTargetPos;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ private:
|
||||||
bool m_bAimPath;
|
bool m_bAimPath;
|
||||||
bool m_bDeltaMove;
|
bool m_bDeltaMove;
|
||||||
int m_iTempAwayTime;
|
int m_iTempAwayTime;
|
||||||
|
int m_iNumBlocks;
|
||||||
int m_iCheckPathTime;
|
int m_iCheckPathTime;
|
||||||
AttractiveNodePtr m_pPrimaryAttract;
|
AttractiveNodePtr m_pPrimaryAttract;
|
||||||
float m_fAttractTime;
|
float m_fAttractTime;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue