Skip to content

Commit

Permalink
Improved sniper bot camping behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Sep 8, 2019
1 parent daa8b04 commit 4266416
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 48 deletions.
6 changes: 3 additions & 3 deletions Pongbot/Bot/Brain/BotBrainSniper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ void BotBrainSniper::_OnThink()

if (!_HasBotTask())
{
WaypointNode* node = _WaypointManager->GetClosestWaypointNode(botPos, -1, botTeam == TEAM_RED ? NODE_SNIPER_CAMP_RED
: NODE_SNIPER_CAMP_BLUE);
if (node)
WaypointNode* node = _WaypointManager->GetClosestWaypointNode(botPos);
if (node && node->Flags & (botTeam == TEAM_RED ? NODE_SNIPER_CAMP_RED : NODE_SNIPER_CAMP_BLUE)
&& botPos.DistTo(node->GetPos()) < node->GetRange())
{
_SetBotTask(new BotTaskSniperSnipe(bot, _ConVarHolder->CVarBotSniperCampTime->GetInt(), node->OptimalViewAngle));
}
Expand Down
2 changes: 1 addition & 1 deletion Pongbot/Bot/Brain/Tasks/BotTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bool BotTask::OnThink()
{
_Bot->SetViewAngle(Util::GetLookAtAngleForPos(_Bot, _BotTargetLookAt));
}
else if (_BotTargetAngle != QAngle(0.f, 0.f, 0.f))
else if (_BotTargetAngle.Length() > 0.f)
{
_Bot->SetViewAngle(_BotTargetAngle);
}
Expand Down
2 changes: 1 addition & 1 deletion Pongbot/Bot/Brain/Tasks/BotTaskSniperSnipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool BotTaskSniperSnipe::_OnThink()
{
return true;
}
else if (_PrefAngle != QAngle(0.f, 0.f, 0.f))
else if (_PrefAngle.Length() > 0.f)
{
_SetBotAngle(_PrefAngle);
}
Expand Down
2 changes: 1 addition & 1 deletion Pongbot/ConVarHolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void ConVarHolder::Init()
_ConVarHolder->CVarBotEnableBrain = new ConVar("pongbot_bot_brain_enabled", "1", 0, "Bots should be able to think");
_ConVarHolder->CVarBotMedTargetDistance = new ConVar("pongbot_bot_med_targetdistance", "100.0", 0, "Distance med bots should have to heal target");
_ConVarHolder->CVarBotMovementIgnoreRadius = new ConVar("pongbot_bot_movement_ignoreradius", "5.0", 0, "Radius around bot where movement tasks should be ignored");
_ConVarHolder->CVarBotSniperCampTime = new ConVar("pongbot_bot_sniper_camp_time", "60", 0, "Time in seconds after which snipers might consider moving to another camping spot (if one exists)");
_ConVarHolder->CVarBotSniperCampTime = new ConVar("pongbot_bot_sniper_camp_time", "60", 0, "Time in seconds after which snipers might consider moving to another camping spot (if one exists)");
}
}

Expand Down
7 changes: 1 addition & 6 deletions Pongbot/TF2/Entity/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@ float Player::GetHealth() const
return Exists() ? _IIPlayerInfo->GetHealth() : -1;
}

float Player::GetFOV() const
{
return Exists() ? _EntityDataProvider->GetDataFromEntity<float>(*this, DATA_PLAYER_FOV) : -1;
}

bool Player::IsSniperZoomedIn() const
{
return Exists() ? GetFOV() <= 21.f : false;
return Exists() ? _EntityDataProvider->GetDataFromEntity<float>(*this, DATA_PLAYER_FOV) == 20.f : false;
}

Vector Player::GetHeadPos() const
Expand Down
1 change: 0 additions & 1 deletion Pongbot/TF2/Entity/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Player : public Entity

public:
float GetHealth() const;
float GetFOV() const;
bool IsSniperZoomedIn() const;
Vector GetHeadPos() const;
bool IsReloading() const;
Expand Down
2 changes: 1 addition & 1 deletion Pongbot/Waypoint/WaypointManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static Player _CheckCommandTargetPlayerExists(bool log = true)
Player foundPlayer;
for (Player player : Util::GetAllPlayers())
{
if (player.Exists())
if (player.Exists() && !player.IsBot())
{
foundPlayer = player;
break;
Expand Down
20 changes: 0 additions & 20 deletions Pongbot/Waypoint/WaypointNode.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
#include "stdafx.h"
#include "WaypointNode.h"

unsigned int WaypointNode::GetId() const
{
return _Id;
}

Vector WaypointNode::GetPos() const
{
return _Pos;
}

std::vector<WaypointNode*> WaypointNode::GetConnectedNodes() const
{
return _ConnectedNodes;
}

bool WaypointNode::ConnectToNode(WaypointNode* node, bool bidirectional)
{
if (!node || node == this)
Expand Down Expand Up @@ -99,9 +84,4 @@ bool WaypointNode::SetRange(float range)
}

return false;
}

float WaypointNode::GetRange() const
{
return _Range;
}
20 changes: 16 additions & 4 deletions Pongbot/Waypoint/WaypointNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,27 @@ class WaypointNode
unsigned int Flags;
QAngle OptimalViewAngle;

unsigned int GetId() const;
Vector GetPos() const;
std::vector<WaypointNode*> GetConnectedNodes() const;
inline unsigned int GetId() const
{
return _Id;
}
inline Vector GetPos() const
{
return _Pos;
}
inline std::vector<WaypointNode*> GetConnectedNodes() const
{
return _ConnectedNodes;
}
bool ConnectToNode(WaypointNode* node, bool bidirectional = false);
bool IsConnectedToNode(WaypointNode* node, bool directly = true);
void UnconnectNode(WaypointNode* node, bool bidirectional = false);
void UnconnectAllNodes(bool bidirectional = false);
bool SetRange(float range);
float GetRange() const;
inline float GetRange() const
{
return _Range;
}

private:
unsigned int _Id;
Expand Down
20 changes: 10 additions & 10 deletions waypoints/ctf_turbine.pbw
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
20:709.84:-89.1551:48.0312:0:30:0:0:0:19:21:115:\
21:681.026:39.1309:48.0312:0:40:0:0:0:20:22:115:\
22:680.148:181.022:48.0312:0:30:0:0:0:21:23:\
23:677.909:471.126:48.0312:256:40:0:0:0:22:24:\
23:677.909:471.126:48.0312:256:40:0:-178.784:0:22:24:\
24:671.323:643.121:48.0312:0:40:0:0:0:23:25:\
25:342.4:643.338:-72.7648:0:40:0:0:0:24:26:\
26:-26.427:639.328:-255.969:0:50:0:0:0:25:28:110:\
28:-475.595:488.307:-255.969:0:200:0:0:0:26:27:29:109:\
27:-724.119:449.657:-255.969:0:60:0:0:0:28:29:56:\
27:-724.119:449.657:-255.969:512:60:0:0:0:28:29:56:\
29:-611.526:-8.06373:-255.969:0:100:0:0:0:27:28:30:55:\
30:-616.383:-380.435:-255.969:0:100:0:0:0:29:31:54:55:\
31:-923.762:-388.133:-255.969:0:140:0:0:0:30:32:\
32:-1383.42:-418.854:-255.969:0:100:0:0:0:31:33:\
32:-1383.42:-418.854:-255.969:512:100:0:0:0:31:33:\
33:-1365.89:-801.811:-255.969:0:150:0:0:0:32:34:\
34:-1372.64:-1156.97:-255.969:0:100:0:0:0:33:35:\
35:-1775.3:-1168.8:-255.969:0:100:0:0:0:34:36:\
Expand All @@ -53,7 +53,7 @@
49:2972.17:918.322:-255.969:0:50:0:0:0:48:50:94:100:\
50:3080.09:1523.2:-281.818:4:30:0:0:0:49:100:\
51:850.499:-452.347:-255.969:0:70:0:0:0:13:52:\
52:707.852:-453.436:-255.969:0:50:0:0:0:51:53:113:114:\
52:707.852:-453.436:-255.969:256:50:0:179.384:0:51:53:113:114:\
53:260.852:-510.201:-255.969:0:100:0:0:0:52:54:91:114:\
54:-246.604:-476.083:-255.969:0:60:0:0:0:53:55:30:90:92:\
55:-430.168:-247.457:-255.969:0:100:0:0:0:54:30:29:\
Expand Down Expand Up @@ -89,7 +89,7 @@
85:-864.726:93.8542:56.0312:0:20:0:0:0:84:86:\
86:-679.366:84.4599:48.0312:0:30:0:0:0:85:87:118:\
87:-681.165:-193.825:48.0312:0:30:0:0:0:86:88:\
88:-681.823:-438.13:48.0312:512:40:0:0:0:87:89:\
88:-681.823:-438.13:48.0312:512:40:0:1.57219:0:87:89:\
89:-673.528:-641.093:48.0312:0:30:0:0:0:88:90:\
90:-416.271:-637.422:-35.8298:0:40:0:0:0:89:91:54:\
91:5.70471:-636.186:-246.817:0:40:0:0:0:90:53:92:\
Expand All @@ -107,7 +107,7 @@
103:1820.38:1144.14:-255.969:0:80:0:0:0:97:102:104:\
104:1391.44:1130.28:-255.969:0:100:0:0:0:103:105:\
105:1394.23:768.593:-255.969:0:100:0:0:0:104:106:\
106:1376.98:385.377:-255.969:0:100:0:0:0:105:107:\
106:1376.98:385.377:-255.969:256:100:0:178.68:0:105:107:\
107:977.336:381.577:-255.969:0:100:0:0:0:106:108:\
108:519.016:374.182:-255.969:0:170:0:0:0:107:111:112:\
109:2.87393:488.665:-255.969:0:30:0:0:0:28:110:111:\
Expand All @@ -117,8 +117,8 @@
113:564.103:-163.888:-255.969:0:100:0:0:0:112:52:114:\
114:473.963:-329.754:-255.969:0:70:0:0:0:113:53:52:\
115:681.104:-195.527:48.0312:0:30:0:0:0:116:21:20:\
116:682.984:-415.945:48.0312:256:30:0:0:0:117:115:\
117:678.294:-629.805:48.0312:256:30:0:0:0:116:\
116:682.984:-415.945:48.0312:256:30:0:175.548:0:117:115:\
117:678.294:-629.805:48.0312:256:30:0:169.476:0:116:\
118:-681.103:192.418:48.0312:0:30:0:0:0:86:119:\
119:-682.241:369.452:48.0312:512:30:0:0:0:120:118:\
120:-683.652:582.438:48.0312:512:30:0:0:0:119:\
119:-682.241:369.452:48.0312:512:30:0:0.648187:0:120:118:\
120:-683.652:582.438:48.0312:512:30:0:-7.35982:0:119:\

0 comments on commit 4266416

Please sign in to comment.