Skip to content

Commit

Permalink
Bots don't add spectators to visibility pool
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Dec 15, 2018
1 parent 38148a2 commit a9a335d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 35 deletions.
10 changes: 1 addition & 9 deletions Pongbot/BotVisibles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,19 @@ std::vector<edict_t*> BotVisibles::GetVisibleEdicts() const {
}

void BotVisibles::OnThink() {
if (_MBot->GetTeam() == TFTeam::SPECTATOR || _MBot->IsDead())
if (_MBot->IsDead())
return;

float currentTime = Engine->Time();

if (_TickTime > currentTime)
return;

_TickTime = currentTime + BOT_VISIBILITY_TICK;

_VisibleEdicts.clear();

Vector botPos = _MBot->GetEarPos();
edict_t *botEdict = _MBot->GetEdict();
IHandleEntity *botPassEntity = botEdict->GetIServerEntity();

for (edict_t *edict : _BotVisiblesProvider->GetAllEdicts()) {
if (edict == botEdict)
continue;
Expand All @@ -49,12 +46,9 @@ void BotVisibles::OnThink() {

Ray_t traceLine;
traceLine.Init(botPos, edictPos);

trace_t traceResult;

IIEngineTrace->TraceRay(traceLine, MASK_SOLID, &TraceFilterSimple(botPassEntity,
edict->GetIServerEntity(), COLLISION_GROUP_NONE), &traceResult);

bool traceHit = traceResult.DidHit();

if (_DrawDebugBeams)
Expand All @@ -63,14 +57,12 @@ void BotVisibles::OnThink() {
if (!traceHit) {
// Insert according to distance bot <-> edict
vec_t edictBotDistance = edictPos.DistTo(botPos);

if (_VisibleEdicts.size() == 0)
_VisibleEdicts.push_back(edict);
else
for (uint8_t i = 0; i < _VisibleEdicts.size(); i++) {
if (Util::GetEdictOrigin(_VisibleEdicts[i]).DistTo(botPos) >= edictBotDistance) {
_VisibleEdicts.insert(_VisibleEdicts.begin() + i, edict);

break;
}
}
Expand Down
5 changes: 1 addition & 4 deletions Pongbot/BotVisiblesProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,5 @@ void BotVisiblesProvider::OnGameFrame() {
bool BotVisiblesProvider::_IsEdictRelevant(edict_t *edict) {
// TODO: more filters
const char *className = edict->GetClassName();

// Don't add spectators to visibles
if ((strcmp(className, "player") != 0 || IIPlayerInfoManager->GetPlayerInfo(edict)->GetTeamIndex() != TFTeam::SPECTATOR))
return strcmp(className, "player") == 0;
return (strcmp(className, "player") == 0 && !IIPlayerInfoManager->GetPlayerInfo(edict)->IsDead());
}
22 changes: 0 additions & 22 deletions Pongbot/WaypointManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,14 @@ void WaypointManager::OnGameFrame() {

static float waitTime;
float currentTime = Engine->Time();

if (waitTime > currentTime)
return;

waitTime = currentTime + WAYPOINT_NODE_BEAM_TICK;

for (WaypointNode *node : _WaypointNodes) {
Vector startPos = node->Pos;
Vector endPos = Vector(startPos.x, startPos.y, startPos.z + 75);

Util::DrawBeam(startPos, endPos, 0, 255, 0, WAYPOINT_NODE_BEAM_TICK);

for (WaypointNode *connectedNode : *node->GetConnectedNodes())
Util::DrawBeam(endPos, connectedNode->Pos, 255, 255, 255, WAYPOINT_NODE_BEAM_TICK);
}
Expand All @@ -125,22 +121,17 @@ void WaypointManager::OnGameFrame() {
static IPlayerInfo *_CheckCommandTargetPlayerExists() {
edict_t *playerEdict = Engine->PEntityOfEntIndex(1);
IPlayerInfo *playerInfo = IIPlayerInfoManager->GetPlayerInfo(playerEdict);

if (!playerEdict || !playerInfo || !playerInfo->IsPlayer()) {
Util::Log("No player found!");

return nullptr;
}

return playerInfo;
}

CON_COMMAND(pongbot_waypoint_createnode, "Creates a waypoint node wherever the first player is standing") {
IPlayerInfo *playerInfo = _CheckCommandTargetPlayerExists();

if (playerInfo) {
uint8_t id = _WaypointNodes.size();

if (id == 256) // Above max size of 8 bit (255)
Util::Log("Max amount of waypoint nodes reached (255)!");
else {
Expand All @@ -153,10 +144,8 @@ CON_COMMAND(pongbot_waypoint_createnode, "Creates a waypoint node wherever the f

CON_COMMAND(pongbot_waypoint_connectnode1, "Selects nearest waypoint node for connection with another node") {
IPlayerInfo *playerInfo = _CheckCommandTargetPlayerExists();

if (playerInfo) {
_SelectedNode = _WaypointManager->GetClosestWaypointNode(playerInfo->GetAbsOrigin());

if (!_SelectedNode)
Util::Log("No waypoint node found!");
else
Expand All @@ -169,10 +158,8 @@ CON_COMMAND(pongbot_waypoint_connectnode2, "Connects previously selected waypoin
Util::Log("Select a node via pongbot_connectnode1 first");
else {
IPlayerInfo *playerInfo = _CheckCommandTargetPlayerExists();

if (playerInfo) {
WaypointNode *currentNode = _WaypointManager->GetClosestWaypointNode(playerInfo->GetAbsOrigin());

if (_SelectedNode == currentNode)
Util::Log("Can't connect waypoint node to itself!");
else {
Expand All @@ -183,7 +170,6 @@ CON_COMMAND(pongbot_waypoint_connectnode2, "Connects previously selected waypoin
Util::Log("Node #%d and #%d were already connected!", selectedNodeID, currentNodeID);
else {
Util::Log("Connected waypoint node #%d with node #%d", selectedNodeID, currentNodeID);

_SelectedNode = nullptr;
}
}
Expand All @@ -193,7 +179,6 @@ CON_COMMAND(pongbot_waypoint_connectnode2, "Connects previously selected waypoin

CON_COMMAND(pongbot_waypoint_biconnect, "Toggles automatic node bidirectional connections") {
_NodeBiConnect = !_NodeBiConnect;

if (_NodeBiConnect)
Util::Log("Bidirectional node connections enabled!");
else
Expand All @@ -204,16 +189,13 @@ CON_COMMAND(pongbot_waypoint_clearnodes, "Removes all waypoint nodes") {
for (WaypointNode *node : _WaypointNodes)
delete node;
_WaypointNodes.clear();

Util::Log("All waypoint nodes cleared!");
}

CON_COMMAND(pongbot_waypoint_clearnode, "Removes the nearest node") {
IPlayerInfo *playerInfo = _CheckCommandTargetPlayerExists();

if (playerInfo) {
WaypointNode *node = _WaypointManager->GetClosestWaypointNode(playerInfo->GetAbsOrigin());

if (!node)
Util::Log("No waypoint node found!");
else {
Expand All @@ -232,15 +214,12 @@ CON_COMMAND(pongbot_waypoint_clearnode, "Removes the nearest node") {

CON_COMMAND(pongbot_waypoint_clearnodeto, "Clears all connections to other nodes from node") {
IPlayerInfo *playerInfo = _CheckCommandTargetPlayerExists();

if (playerInfo) {
WaypointNode *node = _WaypointManager->GetClosestWaypointNode(playerInfo->GetAbsOrigin());

if (!node)
Util::Log("No waypoint node found!");
else {
std::vector<WaypointNode*> *connectedNodes = node->GetConnectedNodes();

for (uint8_t i = 0; i < connectedNodes->size(); i++)
connectedNodes->erase(connectedNodes->begin() + i);

Expand All @@ -251,7 +230,6 @@ CON_COMMAND(pongbot_waypoint_clearnodeto, "Clears all connections to other nodes

CON_COMMAND(pongbot_waypoint_debug, "Toggle beams to visualize nodes & their connections") {
_DrawBeams = !_DrawBeams;

if (_DrawBeams)
Util::Log("Waypoint Debugging enabled!");
else
Expand Down

0 comments on commit a9a335d

Please sign in to comment.