-
Notifications
You must be signed in to change notification settings - Fork 21
Bots throw grenades from cover #1651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sunzenshen
merged 13 commits into
NeotokyoRebuild:master
from
sunzenshen:bot_attack_with_grenades
Feb 28, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9bfb569
Bots throw grenades from cover
sunzenshen 2dbdcab
ConVar options to disable bots throwing nades
sunzenshen c03030a
Fix jump to case label error caused by variable initialization in switch
sunzenshen 9c350c4
Safety related tweaks
sunzenshen 5dedd55
Weekend self review session
sunzenshen f670a9b
Debug overlay for throw targeting
sunzenshen 479bca9
Reduce team obstructing use of smokes
sunzenshen a21f604
Code review feedback
sunzenshen 9925e47
Tweaks after more testing
sunzenshen 304711e
More grenade safety checks
sunzenshen ff9fc69
Code review feedback pass
sunzenshen 7646704
Trigger retreat from grenade after throw
sunzenshen 96d8dba
Rebase fixes
sunzenshen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/game/server/neo/bot/behavior/neo_bot_grenade_dispatch.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| #include "cbase.h" | ||
| #include "neo_gamerules.h" | ||
| #include "neo_player.h" | ||
| #include "bot/neo_bot.h" | ||
| #include "bot/behavior/neo_bot_grenade_dispatch.h" | ||
| #include "bot/behavior/neo_bot_grenade_throw_frag.h" | ||
| #include "bot/behavior/neo_bot_grenade_throw_smoke.h" | ||
| #include "weapon_neobasecombatweapon.h" | ||
| #include "weapon_grenade.h" | ||
| #include "weapon_smokegrenade.h" | ||
|
|
||
| ConVar sv_neo_bot_grenade_use_frag("sv_neo_bot_grenade_use_frag", "1", FCVAR_NONE, "Allow bots to use frag grenades", true, 0, true, 1); | ||
| ConVar sv_neo_bot_grenade_use_smoke("sv_neo_bot_grenade_use_smoke", "1", FCVAR_NONE, "Allow bots to use smoke grenades", true, 0, true, 1); | ||
| ConVar sv_neo_bot_grenade_throw_cooldown("sv_neo_bot_grenade_throw_cooldown", "10", FCVAR_NONE, "Cooldown in seconds between grenade throws for bots"); | ||
|
|
||
| //--------------------------------------------------------------------------------------------- | ||
| Action< CNEOBot > *CNEOBotGrenadeDispatch::ChooseGrenadeThrowBehavior( const CNEOBot *me, const CKnownEntity *threat ) | ||
| { | ||
| if (!sv_neo_bot_grenade_use_frag.GetBool() && !sv_neo_bot_grenade_use_smoke.GetBool()) | ||
| { | ||
| return nullptr; | ||
| } | ||
|
|
||
| if ( !threat || !threat->GetEntity() || !threat->GetEntity()->IsPlayer() || !threat->GetEntity()->IsAlive() ) | ||
| { | ||
| return nullptr; | ||
| } | ||
|
|
||
| // Prefer shooting if we have a clear line of fire | ||
| if ( me->IsLineOfFireClear( threat->GetEntity(), CNEOBot::LINE_OF_FIRE_FLAGS_DEFAULT ) ) | ||
| { | ||
| return nullptr; | ||
| } | ||
|
|
||
| CWeaponGrenade *pFragGrenade = nullptr; | ||
| CWeaponSmokeGrenade *pSmokeGrenade = nullptr; | ||
|
|
||
| int iWeaponCount = me->WeaponCount(); | ||
| for ( int i=0; i<iWeaponCount; ++i ) | ||
| { | ||
| CBaseCombatWeapon *pWep = me->GetWeapon( i ); | ||
| if ( !pWep ) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| CNEOBaseCombatWeapon *pNeoWep = static_cast< CNEOBaseCombatWeapon * >( pWep ); | ||
|
|
||
| if ( !pNeoWep->HasPrimaryAmmo() ) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| auto bits = pNeoWep->GetNeoWepBits(); | ||
| if ( sv_neo_bot_grenade_use_frag.GetBool() && (bits & NEO_WEP_FRAG_GRENADE) ) | ||
| { | ||
| pFragGrenade = static_cast< CWeaponGrenade * >( pNeoWep ); | ||
| if ( pSmokeGrenade ) | ||
| { | ||
| break; // found both | ||
| } | ||
| } | ||
| else if ( sv_neo_bot_grenade_use_smoke.GetBool() && (bits & NEO_WEP_SMOKE_GRENADE) ) | ||
| { | ||
| pSmokeGrenade = static_cast< CWeaponSmokeGrenade * >( pNeoWep ); | ||
| if ( pFragGrenade ) | ||
| { | ||
| break; // found both | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if ( !pFragGrenade && !pSmokeGrenade ) | ||
| { | ||
| return nullptr; | ||
| } | ||
|
|
||
| // Should I toss a smoke grenade? | ||
| if ( pSmokeGrenade ) | ||
| { | ||
| for ( int i = 1; i <= gpGlobals->maxClients; i++ ) | ||
| { | ||
| CNEO_Player *pPlayer = ToNEOPlayer( UTIL_PlayerByIndex( i ) ); | ||
| if ( !pPlayer || !pPlayer->IsAlive() || pPlayer == me ) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| if ( pPlayer->InSameTeam( me ) ) | ||
| { | ||
| if ( !pPlayer->IsBot() && pPlayer->GetClass() != NEO_CLASS_SUPPORT ) | ||
| { | ||
| // Avoid blocking the vision of a friendly human | ||
| // (Bots benefit from concealment without the disorientation) | ||
| return nullptr; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if ( pPlayer->GetClass() == NEO_CLASS_SUPPORT ) | ||
| { | ||
| // Avoid giving an enemy with thermal vision a free smoke screen | ||
| return nullptr; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return new CNEOBotGrenadeThrowSmoke( pSmokeGrenade, threat ); | ||
| } | ||
|
|
||
| // Should I toss a frag grenade? | ||
| if ( pFragGrenade ) | ||
| { | ||
| if ( !CNEOBotGrenadeThrowFrag::IsFragSafe( me, threat->GetLastKnownPosition() ) ) | ||
| { | ||
| return nullptr; | ||
| } | ||
|
|
||
| return new CNEOBotGrenadeThrowFrag( pFragGrenade, threat ); | ||
| } | ||
|
|
||
| return nullptr; | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
src/game/server/neo/bot/behavior/neo_bot_grenade_dispatch.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #ifndef NEO_BOT_GRENADE_DISPATCH_H | ||
| #define NEO_BOT_GRENADE_DISPATCH_H | ||
| #ifdef _WIN32 | ||
| #pragma once | ||
| #endif | ||
|
|
||
| #include "neo_bot_behavior.h" | ||
|
|
||
| class CNEOBot; | ||
| class CKnownEntity; | ||
|
|
||
| extern ConVar sv_neo_bot_grenade_throw_cooldown; | ||
|
|
||
| class CNEOBotGrenadeDispatch | ||
| { | ||
| public: | ||
| static Action< CNEOBot > *ChooseGrenadeThrowBehavior( const CNEOBot *me, const CKnownEntity *threat ); | ||
| }; | ||
|
|
||
| #endif // NEO_BOT_GRENADE_DISPATCH_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.