Skip to content

Commit 97e65e6

Browse files
authored
Bots drop weapon when used if commanding disabled (#1778)
1 parent 5fcc803 commit 97e65e6

5 files changed

Lines changed: 84 additions & 23 deletions

File tree

src/game/server/neo/bot/behavior/neo_bot_scenario_monitor.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
#include "bot/behavior/nav_entities/neo_bot_nav_ent_destroy_entity.h"
1010
#include "bot/behavior/nav_entities/neo_bot_nav_ent_move_to.h"
1111
#include "bot/behavior/nav_entities/neo_bot_nav_ent_wait.h"
12-
#include "bot/behavior/neo_bot_tactical_monitor.h"
13-
#include "bot/behavior/neo_bot_retreat_to_cover.h"
14-
#include "bot/behavior/neo_bot_get_health.h"
15-
#include "bot/behavior/neo_bot_get_ammo.h"
12+
#include "bot/behavior/neo_bot_attack.h"
1613
#include "bot/behavior/neo_bot_command_follow.h"
14+
#include "bot/behavior/neo_bot_get_ammo.h"
15+
#include "bot/behavior/neo_bot_get_health.h"
1716
#include "bot/behavior/neo_bot_pause.h"
18-
19-
#include "bot/behavior/neo_bot_attack.h"
17+
#include "bot/behavior/neo_bot_retreat_to_cover.h"
2018
#include "bot/behavior/neo_bot_seek_and_destroy.h"
19+
#include "bot/behavior/neo_bot_tactical_monitor.h"
20+
#include "bot/behavior/neo_bot_throw_weapon_at_user.h"
2121

2222
#include "bot/behavior/neo_bot_scenario_monitor.h"
2323

@@ -85,6 +85,18 @@ ActionResult< CNEOBot > CNEOBotScenarioMonitor::Update( CNEOBot *me, float inter
8585
return SuspendFor(new CNEOBotPause, "Paused by debug convar sv_neo_bot_cmdr_debug_pause_uncommanded");
8686
}
8787
}
88+
else
89+
{
90+
if (me->m_hCommandingPlayer.Get())
91+
{
92+
CNEO_Player* pCommander = me->m_hCommandingPlayer.Get();
93+
94+
if (CNEOBotThrowWeaponAtUser::ReadyAimToThrowWeapon(me, pCommander))
95+
{
96+
return SuspendFor(new CNEOBotThrowWeaponAtUser(pCommander), "Throwing primary weapon to user");
97+
}
98+
}
99+
}
88100

89101
return Continue();
90102
}

src/game/server/neo/bot/behavior/neo_bot_throw_weapon_at_player.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ ActionResult< CNEOBot > CNEOBotThrowWeaponAtPlayer::OnStart( CNEOBot *me, Action
2020
return Done( "No target player to throw weapon at" );
2121
}
2222

23+
m_expirationTimer.Start( 5.0f );
24+
2325
return Continue();
2426
}
2527

2628
//---------------------------------------------------------------------------------------------
2729
ActionResult< CNEOBot > CNEOBotThrowWeaponAtPlayer::Update( CNEOBot *me, float interval )
2830
{
31+
if ( m_expirationTimer.IsElapsed() )
32+
{
33+
return Done( "Expiration timer elapsed" );
34+
}
35+
2936
CNEO_Player *pTarget = m_hTargetPlayer.Get();
3037
if ( !pTarget || !pTarget->IsAlive() )
3138
{

src/game/server/neo/bot/behavior/neo_bot_throw_weapon_at_player.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class CNEOBotThrowWeaponAtPlayer : public Action< CNEOBot >
1919

2020
virtual const char *GetName( void ) const override { return "ThrowWeaponAtPlayer"; };
2121

22+
protected:
23+
CountdownTimer m_expirationTimer;
24+
2225
private:
2326
CHandle<CNEO_Player> m_hTargetPlayer;
2427
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef NEO_BOT_THROW_WEAPON_AT_USER_H
2+
#define NEO_BOT_THROW_WEAPON_AT_USER_H
3+
#pragma once
4+
5+
#include "bot/behavior/neo_bot_throw_weapon_at_player.h"
6+
#include "bot/neo_bot.h"
7+
#include "neo_player.h"
8+
9+
//-----------------------------------------------------------------------------------------
10+
// If the bot command system is disabled, bots simply drop their weapon for the user
11+
class CNEOBotThrowWeaponAtUser : public CNEOBotThrowWeaponAtPlayer
12+
{
13+
public:
14+
CNEOBotThrowWeaponAtUser(CNEO_Player* pTargetPlayer) : CNEOBotThrowWeaponAtPlayer(pTargetPlayer) {}
15+
16+
virtual void OnEnd(CNEOBot* me, Action< CNEOBot >* nextAction) override
17+
{
18+
me->m_hCommandingPlayer = nullptr;
19+
CNEOBotThrowWeaponAtPlayer::OnEnd(me, nextAction);
20+
}
21+
22+
virtual const char* GetName(void) const override { return "ThrowWeaponAtUser"; };
23+
24+
static bool ReadyAimToThrowWeapon(CNEOBot* me, CNEO_Player* pCommander)
25+
{
26+
me->GetBodyInterface()->AimHeadTowards(pCommander->GetAbsOrigin(), IBody::MANDATORY, 0.2f, nullptr, "Aiming at user's feet to throw weapon");
27+
28+
Vector vecToUserFeet = pCommander->GetAbsOrigin() - me->EyePosition();
29+
vecToUserFeet.NormalizeInPlace();
30+
31+
Vector vecBotFacing;
32+
me->EyeVectors(&vecBotFacing);
33+
34+
return (vecBotFacing.Dot(vecToUserFeet) > 0.95f);
35+
}
36+
};
37+
38+
#endif // NEO_BOT_THROW_WEAPON_AT_USER_H

src/game/server/neo/neo_player.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3481,16 +3481,13 @@ void CNEO_Player::SetTestMessageVisible(bool visible)
34813481

34823482
void CNEO_Player::ResetBotCommandState()
34833483
{
3484-
if (sv_neo_bot_cmdr_enable.GetBool())
3484+
m_hLeadingPlayer = nullptr;
3485+
m_hCommandingPlayer = nullptr;
3486+
m_tBotPlayerPingCooldown.Invalidate();
3487+
m_flBotDynamicFollowDistanceSq = 0.0f;
3488+
for (int i = 0; i < STAR__TOTAL; ++i)
34853489
{
3486-
m_hLeadingPlayer = nullptr;
3487-
m_hCommandingPlayer = nullptr;
3488-
m_tBotPlayerPingCooldown.Invalidate();
3489-
m_flBotDynamicFollowDistanceSq = 0.0f;
3490-
for (int i = 0; i < STAR__TOTAL; ++i)
3491-
{
3492-
m_vLastPingByStar.GetForModify(i) = VECTOR_INVALID_WAYPOINT;
3493-
}
3490+
m_vLastPingByStar.GetForModify(i) = VECTOR_INVALID_WAYPOINT;
34943491
}
34953492
}
34963493

@@ -3563,11 +3560,6 @@ void CNEO_Player::PlayerUse( void )
35633560
{
35643561
BaseClass::PlayerUse();
35653562

3566-
if (!sv_neo_bot_cmdr_enable.GetBool())
3567-
{
3568-
return;
3569-
}
3570-
35713563
if ( (m_afButtonPressed & IN_USE) && !FindUseEntity() )
35723564
{
35733565
// Select bot under cursor to follow/unfollow.
@@ -3585,9 +3577,18 @@ void CNEO_Player::PlayerUse( void )
35853577
CNEO_Player* pTargetPlayer = ToNEOPlayer(tr.m_pEnt);
35863578
if ( pTargetPlayer && pTargetPlayer->IsBot())
35873579
{
3588-
// The hit entity is a bot! Now, toggle its follow state.
3589-
pTargetPlayer->ToggleBotFollowCommander( this );
3590-
// TODO: Do we want to allow using players for some kind of communication?
3580+
if (sv_neo_bot_cmdr_enable.GetBool())
3581+
{
3582+
// The hit entity is a bot! Now, toggle its follow state.
3583+
pTargetPlayer->ToggleBotFollowCommander( this );
3584+
// TODO: Do we want to allow using players for some kind of communication?
3585+
}
3586+
else if (NEORules()->IsTeamplay() && pTargetPlayer->GetTeamNumber() == GetTeamNumber())
3587+
{
3588+
// Alt: Triggers throwing primary weapon to user
3589+
// see neo_bot_scenario_monitor for behavior transition
3590+
pTargetPlayer->m_hCommandingPlayer = this;
3591+
}
35913592
}
35923593
}
35933594
}

0 commit comments

Comments
 (0)