Skip to content

Commit

Permalink
Sniper bots camping (bugged rn) and more function inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Sep 5, 2019
1 parent 0ba2218 commit daa8b04
Show file tree
Hide file tree
Showing 17 changed files with 191 additions and 171 deletions.
60 changes: 0 additions & 60 deletions Pongbot/Bot/Bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,6 @@ void Bot::Think()
_IBotController->RunPlayerMove(&cmd);
}

Player Bot::GetPlayer() const
{
return _Player;
}

edict_t *Bot::GetEdict() const
{
return _Edict;
}

bool Bot::Exists() const
{
return _Player.Exists();
}

Vector Bot::GetPos() const
{
return _Player.GetPos();
}

Vector Bot::GetEarPos() const
{
return _Player.GetHeadPos();
}

QAngle Bot::GetViewAngle() const
{
return _IBotController->GetLocalAngles();
Expand All @@ -116,16 +91,6 @@ void Bot::SetViewAngle(QAngle angle)
_TargetViewAngle = angle;
}

TFClass Bot::GetClass() const
{
return _CurrentClass;
}

TFTeam Bot::GetTeam() const
{
return _Player.GetTeam();
}

BotVisibles* Bot::GetBotVisibles() const
{
return _BotVisibles;
Expand All @@ -142,26 +107,11 @@ void Bot::SetMovement(Vector2D movement)
_Movement = movement;
}

Vector2D Bot::GetMovement() const
{
return _Movement;
}

void Bot::SetPressedButtons(int pressedButtons)
{
_PressedButtons = pressedButtons;
}

int Bot::GetPressedButtons() const
{
return _PressedButtons;
}

WeaponSlot Bot::GetSelectedWeaponSlot() const
{
return _SelectedWeaponSlot;
}

void Bot::SetSelectedWeapon(WeaponSlot weapon)
{
const char *weaponName = nullptr;
Expand All @@ -185,11 +135,6 @@ void Bot::SetSelectedWeapon(WeaponSlot weapon)
}
}

bool Bot::IsDead() const
{
return _Player.IsDead();
}

void Bot::ChangeClass(TFClass tfClass)
{
ExecClientCommand("joinclass %s", _TFClassToJoinName(tfClass));
Expand Down Expand Up @@ -254,11 +199,6 @@ WeaponSlot Bot::GetIdealWeaponForRange(float range) const
}
}

IServerEntity* Bot::GetIServerEntity() const
{
return _Edict->GetIServerEntity();
}

void Bot::_SwitchToFittingTeam()
{
uint8_t red = 0;
Expand Down
60 changes: 48 additions & 12 deletions Pongbot/Bot/Bot.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,63 @@ class Bot
const char* Name;

void Think();
Player GetPlayer() const;
edict_t* GetEdict() const;
bool Exists() const;
Vector GetPos() const;
Vector GetEarPos() const;
inline Player GetPlayer() const
{
return _Player;
}
inline edict_t* GetEdict() const
{
return _Edict;
}
inline bool Exists() const
{
return _Player.Exists();
}
inline Vector GetPos() const
{
return _Player.GetPos();
}
inline Vector GetEarPos() const
{
return _Player.GetHeadPos();
}
QAngle GetViewAngle() const;
void SetViewAngle(QAngle angle);
TFClass GetClass() const;
TFTeam GetTeam() const;
inline TFClass GetClass() const
{
return _CurrentClass;
}
inline TFTeam GetTeam() const
{
return _Player.GetTeam();
}
void SetMovement(Vector2D movement);
Vector2D GetMovement() const;
inline Vector2D GetMovement() const
{
return _Movement;
}
void SetPressedButtons(int pressedButtons);
int GetPressedButtons() const;
WeaponSlot GetSelectedWeaponSlot() const;
inline int GetPressedButtons() const
{
return _PressedButtons;
}
inline WeaponSlot GetSelectedWeaponSlot() const
{
return _SelectedWeaponSlot;
}
void SetSelectedWeapon(WeaponSlot weapon);
BotVisibles* GetBotVisibles() const;
bool IsDead() const;
inline bool IsDead() const
{
return _Player.IsDead();
}
void ChangeClass(TFClass tfClass);
void ExecClientCommand(const char* command, ...) const;
WeaponSlot GetIdealWeaponForRange(float range) const;
IServerEntity* GetIServerEntity() const;
inline IServerEntity* GetIServerEntity() const
{
return _Edict->GetIServerEntity();
}

private:
Player _Player;
Expand Down
5 changes: 0 additions & 5 deletions Pongbot/Bot/Brain/BotBrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ void BotBrain::OnObjectiveUpdate()
_ClearTask();
}

Bot *BotBrain::_GetBot() const
{
return _ABot;
}

void BotBrain::_SetBotTask(BotTask* task)
{
_ClearTask();
Expand Down
5 changes: 4 additions & 1 deletion Pongbot/Bot/Brain/BotBrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class BotBrain : public IEventHooker
virtual void OnObjectiveUpdate();

protected:
Bot* _GetBot() const;
inline Bot* _GetBot() const
{
return _ABot;
}
void _SetBotTask(BotTask* task);
bool _HasBotTask() const;
bool _IsCurrentBotTaskOfType(const std::type_info& type) const;
Expand Down
27 changes: 26 additions & 1 deletion Pongbot/Bot/Brain/BotBrainSniper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
#include "../../ConVarHolder.h"
#include "Tasks/BotTaskSniperSnipe.h"
#include "../../Util.h"
#include "../../Waypoint/WaypointManager.h"
#include "../../Waypoint/WaypointNodeFlagTypes.h"
#include "Tasks/BotTaskGoto.h"

extern WaypointManager* _WaypointManager;

void BotBrainSniper::_OnThink()
{
Bot* bot = _GetBot();
Vector botPos = bot->GetPos();
TFTeam botTeam = bot->GetTeam();

if (!_IsCurrentBotTaskOfType(typeid(BotTaskSniperSnipe)) && bot->GetPlayer().IsSniperZoomedIn())
{
Expand All @@ -17,9 +24,27 @@ void BotBrainSniper::_OnThink()

BotVisibleTarget visibleTarget = bot->GetBotVisibles()->GetMostImportantTarget();
if (visibleTarget.IsValid()
&& Util::DistanceToNoZ(bot->GetPos(), visibleTarget.GetPos()) > _ConVarHolder->CVarBotWeaponLongRangeDist->GetFloat()
&& Util::DistanceToNoZ(botPos, visibleTarget.GetPos()) > _ConVarHolder->CVarBotWeaponLongRangeDist->GetFloat()
&& !_IsCurrentBotTaskOfType(typeid(BotTaskSniperSnipe)))
{
_SetBotTask(new BotTaskSniperSnipe(bot));
}

if (!_HasBotTask())
{
WaypointNode* node = _WaypointManager->GetClosestWaypointNode(botPos, -1, botTeam == TEAM_RED ? NODE_SNIPER_CAMP_RED
: NODE_SNIPER_CAMP_BLUE);
if (node)
{
_SetBotTask(new BotTaskSniperSnipe(bot, _ConVarHolder->CVarBotSniperCampTime->GetInt(), node->OptimalViewAngle));
}
else
{
node = _WaypointManager->GetRandomWaypointNode(botTeam == TEAM_RED ? ~NODE_SNIPER_CAMP_RED : ~NODE_SNIPER_CAMP_BLUE);
if (node)
{
_SetBotTask(new BotTaskGoto(bot, node->GetPos()));
}
}
}
}
46 changes: 15 additions & 31 deletions Pongbot/Bot/Brain/Tasks/BotTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
bool BotTask::OnThink()
{
_BotTargetPos.Zero();
_BotTargetAngle = {0.f, 0.f, 0.f};
_IsBotViewAngleOverriden = false;
_BotPressedButtons = 0;

Expand Down Expand Up @@ -41,7 +42,20 @@ bool BotTask::OnThink()
{
_Bot->SetMovement(Util::GetIdealMoveSpeedsToPos(_Bot, _BotTargetPos));
}
_Bot->SetViewAngle(Util::GetLookAtAngleForPos(_Bot, _BotTargetLookAt));

if (!_BotTargetLookAt.IsZero())
{
_Bot->SetViewAngle(Util::GetLookAtAngleForPos(_Bot, _BotTargetLookAt));
}
else if (_BotTargetAngle != QAngle(0.f, 0.f, 0.f))
{
_Bot->SetViewAngle(_BotTargetAngle);
}
else
{
_Bot->SetViewAngle({0.f, 0.f, 0.f});
}

_Bot->SetPressedButtons(_BotPressedButtons);
_Bot->SetSelectedWeapon(_WeaponSlot);

Expand Down Expand Up @@ -99,34 +113,4 @@ void BotTask::_CheckIfStuckInPos()
_PosStuckTries = 0;
_LastPos = currentPos;
}
}

void BotTask::_BotMoveTo(Vector pos)
{
_BotTargetPos = pos;
}

void BotTask::_SetBotLookAt(Vector pos)
{
_BotTargetLookAt = pos;
}

void BotTask::_OverrideBotViewAngle()
{
_IsBotViewAngleOverriden = true;
}

void BotTask::_AddBotPressedButton(int button)
{
_BotPressedButtons |= button;
}

void BotTask::_SetBotWeaponSlot(WeaponSlot weaponSlot)
{
_WeaponSlot = weaponSlot;
}

Bot* BotTask::_GetBot() const
{
return _Bot;
}
37 changes: 31 additions & 6 deletions Pongbot/Bot/Brain/Tasks/BotTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,42 @@ class BotTask
bool _AbortTask;
bool _DoStuckPosPanicHandling;

void _BotMoveTo(Vector pos);
void _SetBotLookAt(Vector pos);
void _OverrideBotViewAngle();
void _AddBotPressedButton(int button);
void _SetBotWeaponSlot(WeaponSlot weaponSlot);
Bot* _GetBot() const;
inline void _BotMoveTo(Vector pos)
{
_BotTargetPos = pos;
}
inline void _SetBotLookAt(Vector pos)
{
_BotTargetAngle = {0.f, 0.f, 0.f};
_BotTargetLookAt = pos;
}
inline void _SetBotAngle(QAngle angle)
{
_BotTargetLookAt = {0.f, 0.f, 0.f};
_BotTargetAngle = angle;
}
inline void _OverrideBotViewAngle()
{
_IsBotViewAngleOverriden = true;
}
inline void _AddBotPressedButton(int button)
{
_BotPressedButtons |= button;
}
inline void _SetBotWeaponSlot(WeaponSlot weaponSlot)
{
_WeaponSlot = weaponSlot;
}
inline Bot* _GetBot() const
{
return _Bot;
}

private:
Bot* _Bot;
Vector _BotTargetPos;
Vector _BotTargetLookAt;
QAngle _BotTargetAngle;
bool _IsBotViewAngleOverriden;
int _BotPressedButtons;
WeaponSlot _WeaponSlot;
Expand Down
Loading

0 comments on commit daa8b04

Please sign in to comment.