Skip to content

Commit

Permalink
Add bot visibility LOS check
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Aug 13, 2019
1 parent 93fcf3e commit 4a81f0f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
6 changes: 6 additions & 0 deletions Pongbot/Bot/Brain/BotBrainSniper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ void BotBrainSniper::_OnThink()
{
Bot* bot = _GetBot();

if (!_IsCurrentBotTaskOfType(typeid(BotTaskSniperSnipe)) && bot->GetPlayer().IsSniperZoomedIn())
{
bot->SetPressedButtons(IN_ATTACK2);
return;
}

BotVisibleTarget visibleTarget = bot->GetBotVisibles()->GetMostImportantTarget();
if (visibleTarget.IsValid()
&& Util::DistanceToNoZ(bot->GetPos(), visibleTarget.GetPos()) > _ConVarHolder->CVarBotWeaponLongRangeDist->GetFloat()
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 @@ -44,7 +44,7 @@ bool BotTaskSniperSnipe::_OnThink()
float engineTime = Engine->Time();
if (engineTime > _ShootTime)
{
_ShootTime = engineTime + Util::RandomFloat(3.f, 10.f);
_ShootTime = engineTime + Util::RandomFloat(20.f, 40.f);
_AddBotPressedButton(IN_ATTACK);
}
}
Expand Down
5 changes: 4 additions & 1 deletion Pongbot/Bot/Brain/Tasks/BotTaskSniperSnipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
class BotTaskSniperSnipe : public BotTask
{
public:
BotTaskSniperSnipe(Bot *bot) : BotTask(bot), _ShootTime(0.f) {}
BotTaskSniperSnipe(Bot *bot) : BotTask(bot), _ShootTime(0.f)
{
_DoStuckPosPanicHandling = false;
}

private:
float _ShootTime;
Expand Down
10 changes: 6 additions & 4 deletions Pongbot/Bot/Visibles/BotVisibles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ void BotVisibles::_AddEntity(Entity entity, Vector edictPos, uint8_t insertIndex

bool BotVisibles::_IsTargetInSight(Vector targetPos) const
{
/* Thanks to rcbot2 */
Vector vectorForward;
AngleVectors(_MBot->GetViewAngle(), &vectorForward);
float dot = vectorForward.x * targetPos.x + vectorForward.y * targetPos.y + vectorForward.z * targetPos.z;
float angle = std::acos(dot / (vectorForward.Length() * targetPos.Length()));

// TODOOOOOOOOOOOOOOO!
return true;
Vector vectorLOS = targetPos - _MBot->GetEarPos();
vectorLOS /= vectorLOS.Length();

float dot = DotProduct(vectorLOS, vectorForward);
return dot > 0.1f;
}

bool BotVisibles::_HasClearLineToTarget(IServerEntity* targetEntity, Vector targetPos) const
Expand Down
7 changes: 1 addition & 6 deletions Pongbot/TF2/Entity/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ bool Entity::Exists() const

const char* Entity::GetEdictClassName() const
{
if (!Exists())
{
return nullptr;
}

return _MEdict->GetClassName();
return Exists() ? _MEdict->GetClassName() : nullptr;
}

IServerEntity* Entity::GetIServerEntity() const
Expand Down
1 change: 0 additions & 1 deletion Pongbot/TF2/Entity/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ Vector Player::GetHeadPos() const

Vector headPos;
IIServerGameClients->ClientEarPosition(GetEdict(), &headPos);

return headPos;
}

Expand Down

0 comments on commit 4a81f0f

Please sign in to comment.