Skip to content

Commit

Permalink
Bots don't attempt to run straight to objective if no way leads there
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Aug 10, 2019
1 parent 5330880 commit 29ae29f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
27 changes: 17 additions & 10 deletions Pongbot/Bot/Brain/Tasks/BotTaskGoto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ extern IVEngineServer* Engine;

static bool _DrawDebugBeam = false;

BotTaskGoto::BotTaskGoto(Bot* bot, Vector targetPos, bool shortestWay, int nodeFlagBlacklist) : BotTask(bot),
_TargetPos(targetPos), _ShortestWay(shortestWay), _NodeFlagBlacklist(nodeFlagBlacklist), _PosStuckTime(0),
_DebugBeamDrawTime(0.f)
{
_NewTargetNodeStack();
}

bool BotTaskGoto::_OnThink()
{
if (_Abort)
{
return true;
}

Bot* bot = _GetBot();
Vector currentPos = bot->GetPos();
float nodeTouchRadius = _ConVarHolder->CVarBotNodeTouchRadius->GetFloat();
Expand All @@ -38,9 +36,10 @@ bool BotTaskGoto::_OnThink()
if (_PosStuckTime > panicStuckTime + 50)
{
_PosStuckTime = 0;
if (!_ShortestWay)
if (!_ShortestWay && !_NewTargetNodeStack())
{
_NewTargetNodeStack();
// Can't get there
return true;
}
}
else if (_PosStuckTime > panicStuckTime)
Expand Down Expand Up @@ -84,7 +83,7 @@ bool BotTaskGoto::_OnThink()
return false;
}

void BotTaskGoto::_NewTargetNodeStack()
bool BotTaskGoto::_NewTargetNodeStack()
{
Bot* bot = _GetBot();
Vector currentPos = bot->GetPos();
Expand All @@ -110,6 +109,12 @@ void BotTaskGoto::_NewTargetNodeStack()
_WaypointManager->GetRandomWaypointNodeRouteToTargetNode(closestNode, targetNode, &_WaypointNodeStack,
nodeFlagBlacklist | _NodeFlagBlacklist);
}

if (_WaypointNodeStack.empty())
{
// Can't even get there, abort
return false;
}

_TargetPosQueue = std::queue<Vector>();
while (!_WaypointNodeStack.empty())
Expand All @@ -121,6 +126,8 @@ void BotTaskGoto::_NewTargetNodeStack()
}
_TargetPosQueue.push(_TargetPos);
}

return true;
}

CON_COMMAND(pongbot_bot_goto_debug, "Draw a beam to the bots' target pos")
Expand Down
7 changes: 5 additions & 2 deletions Pongbot/Bot/Brain/Tasks/BotTaskGoto.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class Bot;
class BotTaskGoto : public BotTask
{
public:
BotTaskGoto(Bot* bot, Vector targetPos, bool shortestWay = true, int nodeFlagBlacklist = 0);
BotTaskGoto(Bot* bot, Vector targetPos, bool shortestWay = true, int nodeFlagBlacklist = 0) : BotTask(bot),
_TargetPos(targetPos), _ShortestWay(shortestWay), _NodeFlagBlacklist(nodeFlagBlacklist), _PosStuckTime(0),
_DebugBeamDrawTime(0.f), _Abort(!_NewTargetNodeStack()) {}

private:
std::queue<Vector> _TargetPosQueue;
Expand All @@ -18,7 +20,8 @@ class BotTaskGoto : public BotTask
const bool _ShortestWay;
const int _NodeFlagBlacklist;
float _DebugBeamDrawTime;
bool _Abort;

virtual bool _OnThink();
void _NewTargetNodeStack();
bool _NewTargetNodeStack();
};

0 comments on commit 29ae29f

Please sign in to comment.