Skip to content

Commit

Permalink
Project Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Jul 26, 2019
1 parent 7825b67 commit eee7e24
Show file tree
Hide file tree
Showing 76 changed files with 643 additions and 420 deletions.
33 changes: 22 additions & 11 deletions Pongbot/Bot.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "stdafx.h"
#include "Bot.h"
#include "BotManager.h"
#include "Util.h"
Expand All @@ -19,12 +20,12 @@
#include <hlsdk/public/game/server/iplayerinfo.h>
#include <string>

extern IVEngineServer *Engine;
extern IBotManager *IIBotManager;
extern IServerPluginHelpers *IIServerPluginHelpers;
extern IPlayerInfoManager *IIPlayerInfoManager;
extern IVEngineServer* Engine;
extern IBotManager* IIBotManager;
extern IServerPluginHelpers* IIServerPluginHelpers;
extern IPlayerInfoManager* IIPlayerInfoManager;

Bot::Bot(Player player, const char *name) : Name(name), _Player(player), _Edict(player.GetEdict()),
Bot::Bot(Player player, const char* name) : Name(name), _Player(player), _Edict(player.GetEdict()),
_IBotController(IIBotManager->GetBotController(_Edict)),
_IPlayerInfo(IIPlayerInfoManager->GetPlayerInfo(_Edict))
{
Expand Down Expand Up @@ -119,7 +120,7 @@ TFTeam Bot::GetTeam() const
return GetPlayer().GetTeam();
}

BotVisibles *Bot::GetBotVisibles() const
BotVisibles* Bot::GetBotVisibles() const
{
return _BotVisibles;
}
Expand Down Expand Up @@ -180,7 +181,7 @@ void Bot::ChangeClass(TFClass tfClass)
_UpdateBotBrain();
}

void Bot::ExecClientCommand(const char *command, ...) const
void Bot::ExecClientCommand(const char* command, ...) const
{
char fullCommand[128];
va_list args;
Expand Down Expand Up @@ -208,11 +209,17 @@ WeaponSlot Bot::GetIdealWeaponForRange(float range) const
{
unsigned int weaponFlags = weaponInfos[i].WeaponFlags;
if (weaponFlags & WEAPONFLAG_PRIORITIZE_LONGDIST)
longRangeWeaponSlot = (WeaponSlot) i;
{
longRangeWeaponSlot = (WeaponSlot)i;
}
if (weaponFlags & WEAPONFLAG_PRIORITIZE_MIDDLEDIST)
middleRangeWeaponSlot = (WeaponSlot) i;
{
middleRangeWeaponSlot = (WeaponSlot)i;
}
if (weaponFlags & WEAPONFLAG_PRIORITIZE_SHORTDIST)
shortRangeWeaponSlot = (WeaponSlot) i;
{
shortRangeWeaponSlot = (WeaponSlot)i;
}
}

if (range < _ConVarHolder->CVarBotWeaponMiddleRangeDist->GetFloat())
Expand All @@ -237,9 +244,13 @@ void Bot::_SwitchToFittingTeam()
{
TFTeam team = player.GetTeam();
if (team == TEAM_RED)
{
red++;
}
else if (team == TEAM_BLUE)
{
blue++;
}
}

_IPlayerInfo->ChangeTeam(blue < red ? TEAM_BLUE : TEAM_RED);
Expand Down Expand Up @@ -282,7 +293,7 @@ void Bot::_UpdateBotBrain()
Util::DebugLog("Created new bot brain (%s) for bot %s (Edict Index: %d)", _TFClassToJoinName(GetClass()), Name, GetEdict()->m_iIndex);
}

const char *Bot::_TFClassToJoinName(TFClass tfClass) const
const char* Bot::_TFClassToJoinName(TFClass tfClass) const
{
switch (tfClass) {
case SCOUT:
Expand Down
22 changes: 11 additions & 11 deletions Pongbot/Bot.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ struct edict_t;
class Bot
{
public:
Bot(Player player, const char *name);
Bot(Player player, const char* name);
~Bot();

public:
const char* Name;

void Think();
const Player GetPlayer() const;
edict_t *GetEdict() const;
edict_t* GetEdict() const;
bool Exists() const;
Vector GetPos() const;
Vector GetEarPos() const;
Expand All @@ -35,29 +35,29 @@ class Bot
void SetPressedButtons(int pressedButtons);
WeaponSlot GetSelectedWeaponSlot() const;
void SetSelectedWeapon(WeaponSlot weapon);
BotVisibles *GetBotVisibles() const;
BotVisibles* GetBotVisibles() const;
bool IsDead() const;
void ChangeClass(TFClass tfClass);
void ExecClientCommand(const char *command, ...) const;
void ExecClientCommand(const char* command, ...) const;
WeaponSlot GetIdealWeaponForRange(float range) const;

private:
const Player _Player;
edict_t *_Edict;
IPlayerInfo *_IPlayerInfo;
IBotController *_IBotController;
BotBrain *_BotBrain;
BotVisibles *_BotVisibles;
edict_t* _Edict;
IPlayerInfo* _IPlayerInfo;
IBotController* _IBotController;
BotBrain* _BotBrain;
BotVisibles* _BotVisibles;
TFClass _CurrentClass;
QAngle _TargetViewAngle;
Vector2D _Movement;
int _PressedButtons;
TFClassInfo *_ClassInfo;
TFClassInfo* _ClassInfo;
WeaponSlot _SelectedWeaponSlot;

void _SwitchToFittingTeam();
void _UpdateBotBrain();
const char *_TFClassToJoinName(TFClass tfClass) const;
const char* _TFClassToJoinName(TFClass tfClass) const;
void _RandomClass();
};

30 changes: 19 additions & 11 deletions Pongbot/BotBrain.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "stdafx.h"
#include "BotBrain.h"
#include "BotTaskGoto.h"
#include "BotTaskAggressiveCombat.h"
Expand All @@ -13,23 +14,20 @@
#include <metamod/ISmmAPI.h>
#include <stdint.h> // uint8_t for Linux

extern IVEngineServer *Engine;

Bot *_ABot;
BotTask *_BotTask;
float _ThinkTime;
unsigned int _States;
bool _IsBotDead;
bool _IsBotInMeleeFight;
extern IVEngineServer* Engine;

void BotBrain::OnThink()
{
if (_GetBot()->IsDead())
{
_IsBotDead = true;
}
else
{
if (_IsBotDead)
{
OnSpawn();
}

float engineTime = Engine->Time();
if (_ThinkTime < engineTime)
Expand All @@ -40,13 +38,15 @@ void BotBrain::OnThink()
}

if (_HasBotTask() && _BotTask->OnThink())
{
_ClearTask();
}
}
}

void BotBrain::_DefaultThink()
{
Bot *bot = _GetBot();
Bot* bot = _GetBot();
Vector botPos = _ABot->GetPos();

/* Tasks which should be able to override current ones */
Expand All @@ -62,7 +62,9 @@ void BotBrain::_DefaultThink()
}
}
else
{
_IsBotInMeleeFight = false;
}

/* Filler Tasks in case the bot has nothing to do */

Expand Down Expand Up @@ -92,23 +94,29 @@ void BotBrain::_DefaultThink()
{
CTFFlagStatusType itemFlagStatus = (CTFFlagStatusType) closestObjective->Status;
if (itemFlagStatus == CTF_UNTOUCHED || itemFlagStatus == CTF_DROPPED) // The flag should be picked up
{
_SetBotTask(new BotTaskGoto(bot, closestObjective->Pos, false));
}
else if (CTFFlag(closestObjective->Edict).GetOwner() == bot->GetEdict()->m_iIndex)
{
// I'm carrying the flag
WaypointNode *targetNode = _WaypointManager->GetClosestWaypointNode(botPos,
WaypointNode* targetNode = _WaypointManager->GetClosestWaypointNode(botPos,
-1, bot->GetTeam() == TEAM_RED ? NODE_ITEMFLAG_RED : NODE_ITEMFLAG_BLUE);
if (targetNode) // Map doesn't have a ITEMFLAG_RED/ITEMFLAG_BLUE node!
{
_SetBotTask(new BotTaskGoto(bot, targetNode->Pos, true, NODE_SPAWN_RED | NODE_SPAWN_BLUE)); // Don't walk through spawns
}
}
}

delete closestObjective;

// Free Roam if still no task
if (!_HasBotTask())
{
_SetBotTask(new BotTaskGoto(bot, _WaypointManager->GetRandomWaypointNode(
_WaypointNodeFlagsProvider->GetInaccessibleNodeFlagsForBot(_ABot))->Pos, false));
}
}
}
}
Expand All @@ -131,7 +139,7 @@ Bot *BotBrain::_GetBot() const
return _ABot;
}

void BotBrain::_SetBotTask(BotTask *task)
void BotBrain::_SetBotTask(BotTask* task)
{
_ClearTask();
_BotTask = task;
Expand Down
10 changes: 5 additions & 5 deletions Pongbot/BotBrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum BotState
class BotBrain : public IEventHooker
{
public:
BotBrain(Bot *bot) : _ABot(bot), _IsBotDead(true) /* To invoke OnSpawn() */
BotBrain(Bot* bot) : _ABot(bot), _IsBotDead(true) /* To invoke OnSpawn() */
{}

public:
Expand All @@ -21,16 +21,16 @@ class BotBrain : public IEventHooker
virtual void OnObjectiveUpdate();

protected:
Bot *_GetBot() const;
void _SetBotTask(BotTask *task);
Bot* _GetBot() const;
void _SetBotTask(BotTask* task);
bool _HasBotTask() const;
void _AddState(BotState state);
void _RemoveState(BotState state);
bool _HasState(BotState state) const;

private:
Bot *_ABot;
BotTask *_BotTask;
Bot* _ABot;
BotTask* _BotTask;
float _ThinkTime;
unsigned int _States;
bool _IsBotDead;
Expand Down
1 change: 1 addition & 0 deletions Pongbot/BotBrainDemo.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "stdafx.h"
#include "BotBrainDemo.h"

void BotBrainDemo::_OnThink()
Expand Down
2 changes: 1 addition & 1 deletion Pongbot/BotBrainDemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class BotBrainDemo : public BotBrain
{
public:
BotBrainDemo(Bot *bot) : BotBrain(bot)
BotBrainDemo(Bot* bot) : BotBrain(bot)
{}

private:
Expand Down
1 change: 1 addition & 0 deletions Pongbot/BotBrainEngi.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "stdafx.h"
#include "BotBrainEngi.h"

void BotBrainEngi::_OnThink()
Expand Down
2 changes: 1 addition & 1 deletion Pongbot/BotBrainEngi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class BotBrainEngi : public BotBrain
{
public:
BotBrainEngi(Bot *bot) : BotBrain(bot)
BotBrainEngi(Bot* bot) : BotBrain(bot)
{}

private:
Expand Down
1 change: 1 addition & 0 deletions Pongbot/BotBrainHeavy.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "stdafx.h"
#include "BotBrainHeavy.h"

void BotBrainHeavy::_OnThink()
Expand Down
2 changes: 1 addition & 1 deletion Pongbot/BotBrainHeavy.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class BotBrainHeavy : public BotBrain
{
public:
BotBrainHeavy(Bot *bot) : BotBrain(bot)
BotBrainHeavy(Bot* bot) : BotBrain(bot)
{}

private:
Expand Down
11 changes: 6 additions & 5 deletions Pongbot/BotBrainMed.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
#include "BotBrainMed.h"
#include "BotVisibles.h"
#include "BotTaskMedHealTarget.h"
#include "stdafx.h"
#include "Util.h"
#include "ConVarHolder.h"
#include "Player.h"
#include <hlsdk/public/edict.h>

edict_t *_CurrentHealTarget;

void BotBrainMed::_OnThink()
{
Bot *bot = _GetBot();
Bot* bot = _GetBot();

BotVisibles *botVisibles = bot->GetBotVisibles();
BotVisibles* botVisibles = bot->GetBotVisibles();
if (_CurrentHealTarget && !botVisibles->IsEntityVisible(_CurrentHealTarget))
{
_CurrentHealTarget = nullptr;
}

if (!_CurrentHealTarget)
{
Vector botPos = bot->GetPos();
std::vector<BotVisibleTarget*> botVisibleTargets = botVisibles->GetVisibleTargets();
// TODO: Target most important target for healing instead of first one
for (BotVisibleTarget *visibleTarget : botVisibleTargets)
for (BotVisibleTarget* visibleTarget : botVisibleTargets)
{
Entity visibleEntity = visibleTarget->GetEntity();
if (visibleEntity.Exists() && visibleEntity.IsPlayer() && visibleTarget->Priority == PRIORITY_FRIENDLY
Expand Down
4 changes: 2 additions & 2 deletions Pongbot/BotBrainMed.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class Player;
class BotBrainMed : public BotBrain
{
public:
BotBrainMed(Bot *bot) : BotBrain(bot)
BotBrainMed(Bot* bot) : BotBrain(bot)
{}

private:
edict_t *_CurrentHealTarget;
edict_t* _CurrentHealTarget;

virtual void _OnThink();
virtual void _OnSpawn();
Expand Down
9 changes: 5 additions & 4 deletions Pongbot/BotBrainPyro.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#include "stdafx.h"
#include "BotBrainPyro.h"
#include "BotVisibles.h"
#include "BotTaskAggressiveCombat.h"
#include "Entity.h"

bool _IsRushingEnemy = false;

void BotBrainPyro::_OnThink()
{
Bot *bot = _GetBot();
Bot* bot = _GetBot();

BotVisibleTarget *currentTarget = bot->GetBotVisibles()->GetMostImportantTarget();
BotVisibleTarget* currentTarget = bot->GetBotVisibles()->GetMostImportantTarget();
if (currentTarget && bot->GetSelectedWeaponSlot() == WEAPON_PRIMARY)
{
if (!_IsRushingEnemy)
Expand All @@ -19,7 +18,9 @@ void BotBrainPyro::_OnThink()
}
}
else
{
_IsRushingEnemy = false;
}
}

void BotBrainPyro::_OnSpawn()
Expand Down
Loading

0 comments on commit eee7e24

Please sign in to comment.