Skip to content

Commit

Permalink
Bots don't do visibility while dead/spectator
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Dec 15, 2018
1 parent c11ceb5 commit 0dcbaa5
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Pongbot/Bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "BotTaskMaster.h"
#include "BotVisibles.h"
#include "BotTaskMasterCollection.h"
#include "TFTeam.h"
#include "TFClass.h"
#include <metamod/ISmmPlugin.h>
#include <string>

Expand Down Expand Up @@ -87,10 +89,18 @@ TFClass Bot::GetClass() const {
return _CurrentClass;
}

TFTeam Bot::GetTeam() const {
return (TFTeam) _IIPlayerInfo->GetTeamIndex();
}

BotVisibles *Bot::GetBotVisibles() const {
return _BotVisibles;
}

bool Bot::IsDead() const {
return _IIPlayerInfo->IsDead();
}

void Bot::ChangeClass(TFClass tfClass) {
char newClass[16];
_TFClassToJoinName(tfClass, newClass);
Expand Down
5 changes: 4 additions & 1 deletion Pongbot/Bot.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once
#include "TFClass.h"
#include <hlsdk/public/edict.h>
#include <hlsdk/public/game/server/iplayerinfo.h>

class BotHelper;
class BotTaskMaster;
class BotVisibles;
class WaypointNode;
enum TFClass;
enum TFTeam;

class Bot {
public:
Expand All @@ -23,7 +24,9 @@ class Bot {
Vector GetEarPos() const;
QAngle GetAngle() const;
TFClass GetClass() const;
TFTeam GetTeam() const;
BotVisibles *GetBotVisibles() const;
bool IsDead() const;
void ChangeClass(TFClass tfClass);

private:
Expand Down
4 changes: 4 additions & 0 deletions Pongbot/BotVisibles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "BotVisiblesProvider.h"
#include "Util.h"
#include "TraceFilters.h"
#include "TFTeam.h"
#include <metamod/ISmmAPI.h>

#define BOT_VISIBILITY_TICK 0.2
Expand All @@ -24,6 +25,9 @@ std::vector<edict_t*> BotVisibles::GetVisibleEdicts() const {
}

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

float currentTime = Engine->Time();

if (_TickTime > currentTime)
Expand Down
3 changes: 2 additions & 1 deletion Pongbot/BotVisiblesProvider.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "BotVisiblesProvider.h"
#include "TFTeam.h"
#include <hlsdk/public/game/server/iplayerinfo.h>

extern IVEngineServer *Engine;
Expand Down Expand Up @@ -48,6 +49,6 @@ bool BotVisiblesProvider::_IsEdictRelevant(edict_t *edict) {
const char *className = edict->GetClassName();

// Don't add spectators to visibles
if ((strcmp(className, "player") != 0 || IIPlayerInfoManager->GetPlayerInfo(edict)->GetTeamIndex() != 1))
if ((strcmp(className, "player") != 0 || IIPlayerInfoManager->GetPlayerInfo(edict)->GetTeamIndex() != TFTeam::SPECTATOR))
return strcmp(className, "player") == 0;
}
1 change: 1 addition & 0 deletions Pongbot/Pongbot.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
<ClCompile Include="Main.cpp" />
<ClCompile Include="Util.cpp" />
<ClInclude Include="TFClass.h" />
<ClInclude Include="TFTeam.h" />
<ClInclude Include="TraceFilters.h" />
<ClInclude Include="TraceHeaders.h" />
<ClInclude Include="WaypointFileManager.h" />
Expand Down
3 changes: 3 additions & 0 deletions Pongbot/Pongbot.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,8 @@
<ClInclude Include="TraceHeaders.h">
<Filter>src\TF2Util</Filter>
</ClInclude>
<ClInclude Include="TFTeam.h">
<Filter>src\TF2Util</Filter>
</ClInclude>
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions Pongbot/TFTeam.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

enum TFTeam {
SPECTATOR = 1,
RED,
BLUE
};

0 comments on commit 0dcbaa5

Please sign in to comment.