From 4a81f0fc7699fa84b19835b66c5100141f2a0752 Mon Sep 17 00:00:00 2001 From: pongo1231 Date: Tue, 13 Aug 2019 21:20:18 +0200 Subject: [PATCH] Add bot visibility LOS check --- Pongbot/Bot/Brain/BotBrainSniper.cpp | 6 ++++++ Pongbot/Bot/Brain/Tasks/BotTaskSniperSnipe.cpp | 2 +- Pongbot/Bot/Brain/Tasks/BotTaskSniperSnipe.h | 5 ++++- Pongbot/Bot/Visibles/BotVisibles.cpp | 10 ++++++---- Pongbot/TF2/Entity/Entity.cpp | 7 +------ Pongbot/TF2/Entity/Player.cpp | 1 - 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Pongbot/Bot/Brain/BotBrainSniper.cpp b/Pongbot/Bot/Brain/BotBrainSniper.cpp index 395e98c..226f68f 100644 --- a/Pongbot/Bot/Brain/BotBrainSniper.cpp +++ b/Pongbot/Bot/Brain/BotBrainSniper.cpp @@ -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() diff --git a/Pongbot/Bot/Brain/Tasks/BotTaskSniperSnipe.cpp b/Pongbot/Bot/Brain/Tasks/BotTaskSniperSnipe.cpp index bd36619..9fff91f 100644 --- a/Pongbot/Bot/Brain/Tasks/BotTaskSniperSnipe.cpp +++ b/Pongbot/Bot/Brain/Tasks/BotTaskSniperSnipe.cpp @@ -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); } } diff --git a/Pongbot/Bot/Brain/Tasks/BotTaskSniperSnipe.h b/Pongbot/Bot/Brain/Tasks/BotTaskSniperSnipe.h index 5834736..efa3a0b 100644 --- a/Pongbot/Bot/Brain/Tasks/BotTaskSniperSnipe.h +++ b/Pongbot/Bot/Brain/Tasks/BotTaskSniperSnipe.h @@ -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; diff --git a/Pongbot/Bot/Visibles/BotVisibles.cpp b/Pongbot/Bot/Visibles/BotVisibles.cpp index 9c3c2eb..1ff46ff 100644 --- a/Pongbot/Bot/Visibles/BotVisibles.cpp +++ b/Pongbot/Bot/Visibles/BotVisibles.cpp @@ -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 diff --git a/Pongbot/TF2/Entity/Entity.cpp b/Pongbot/TF2/Entity/Entity.cpp index 5b993c0..5fab950 100644 --- a/Pongbot/TF2/Entity/Entity.cpp +++ b/Pongbot/TF2/Entity/Entity.cpp @@ -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 diff --git a/Pongbot/TF2/Entity/Player.cpp b/Pongbot/TF2/Entity/Player.cpp index d5ceb52..805d363 100644 --- a/Pongbot/TF2/Entity/Player.cpp +++ b/Pongbot/TF2/Entity/Player.cpp @@ -49,7 +49,6 @@ Vector Player::GetHeadPos() const Vector headPos; IIServerGameClients->ClientEarPosition(GetEdict(), &headPos); - return headPos; }