Skip to content

Commit acdb36b

Browse files
committed
Bots drop weapon when used if commanding disabled
1 parent 1f1b424 commit acdb36b

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
@@ -3280,16 +3280,13 @@ void CNEO_Player::SetTestMessageVisible(bool visible)
32803280

32813281
void CNEO_Player::ResetBotCommandState()
32823282
{
3283-
if (sv_neo_bot_cmdr_enable.GetBool())
3283+
m_hLeadingPlayer = nullptr;
3284+
m_hCommandingPlayer = nullptr;
3285+
m_tBotPlayerPingCooldown.Invalidate();
3286+
m_flBotDynamicFollowDistanceSq = 0.0f;
3287+
for (int i = 0; i < STAR__TOTAL; ++i)
32843288
{
3285-
m_hLeadingPlayer = nullptr;
3286-
m_hCommandingPlayer = nullptr;
3287-
m_tBotPlayerPingCooldown.Invalidate();
3288-
m_flBotDynamicFollowDistanceSq = 0.0f;
3289-
for (int i = 0; i < STAR__TOTAL; ++i)
3290-
{
3291-
m_vLastPingByStar.GetForModify(i) = VECTOR_INVALID_WAYPOINT;
3292-
}
3289+
m_vLastPingByStar.GetForModify(i) = VECTOR_INVALID_WAYPOINT;
32933290
}
32943291
}
32953292

@@ -3362,11 +3359,6 @@ void CNEO_Player::PlayerUse( void )
33623359
{
33633360
BaseClass::PlayerUse();
33643361

3365-
if (!sv_neo_bot_cmdr_enable.GetBool())
3366-
{
3367-
return;
3368-
}
3369-
33703362
if ( (m_afButtonPressed & IN_USE) && !FindUseEntity() )
33713363
{
33723364
// Select bot under cursor to follow/unfollow.
@@ -3384,9 +3376,18 @@ void CNEO_Player::PlayerUse( void )
33843376
CNEO_Player* pTargetPlayer = ToNEOPlayer(tr.m_pEnt);
33853377
if ( pTargetPlayer && pTargetPlayer->IsBot())
33863378
{
3387-
// The hit entity is a bot! Now, toggle its follow state.
3388-
pTargetPlayer->ToggleBotFollowCommander( this );
3389-
// TODO: Do we want to allow using players for some kind of communication?
3379+
if (sv_neo_bot_cmdr_enable.GetBool())
3380+
{
3381+
// The hit entity is a bot! Now, toggle its follow state.
3382+
pTargetPlayer->ToggleBotFollowCommander( this );
3383+
// TODO: Do we want to allow using players for some kind of communication?
3384+
}
3385+
else if (NEORules()->IsTeamplay() && pTargetPlayer->GetTeamNumber() == GetTeamNumber())
3386+
{
3387+
// Alt: Triggers throwing primary weapon to user
3388+
// see neo_bot_scenario_monitor for behavior transition
3389+
pTargetPlayer->m_hCommandingPlayer = this;
3390+
}
33903391
}
33913392
}
33923393
}

0 commit comments

Comments
 (0)