-
Notifications
You must be signed in to change notification settings - Fork 20
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
Open
sunzenshen
wants to merge
7
commits into
NeotokyoRebuild:master
Choose a base branch
from
sunzenshen:bot_attack_with_grenades
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
82a0401
Bots throw grenades from cover
sunzenshen 1a7e290
ConVar options to disable bots throwing nades
sunzenshen 961bf0a
Fix jump to case label error caused by variable initialization in switch
sunzenshen 63f3f0b
Safety related tweaks
sunzenshen 8834cd9
Weekend self review session
sunzenshen db218d4
Debug overlay for throw targeting
sunzenshen d0d9fc1
Reduce team obstructing use of smokes
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
126 changes: 126 additions & 0 deletions
126
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,126 @@ | ||
| #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( 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; | ||
| } | ||
|
|
||
| CNEO_Player *pNEOPlayer = ToNEOPlayer( me->GetEntity() ); | ||
| if ( !pNEOPlayer ) | ||
| { | ||
| return nullptr; | ||
| } | ||
|
|
||
| CWeaponGrenade *pFragGrenade = nullptr; | ||
| CWeaponSmokeGrenade *pSmokeGrenade = nullptr; | ||
|
|
||
| int iWeaponCount = pNEOPlayer->WeaponCount(); | ||
| for ( int i=0; i<iWeaponCount; ++i ) | ||
| { | ||
| CBaseCombatWeapon *pWep = pNEOPlayer->GetWeapon( i ); | ||
| if ( !pWep ) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| CNEOBaseCombatWeapon *pNeoWep = static_cast< CNEOBaseCombatWeapon * >( pWep ); | ||
| if ( pNeoWep ) | ||
| { | ||
| 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 == pNEOPlayer ) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| if ( pPlayer->InSameTeam( pNEOPlayer ) ) | ||
| { | ||
| 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( 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To start the conversation, I wonder if we should check if there are any human non-support players on the bot's team before throwing smoke. Bots don't have too much trouble navigating smoked areas, but I imagine humans could struggle to navigate on maps with fewer routes like bullet.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One fuzzy measure could be calculating a numeric value for how "useful" the smoke would be, based on number of nearby supports, and whether they are friendly/enemy or bot/human, and try to make it such that smokes that may hinder human friendlies are to be avoided, even if they were marginally useful for some bots. And likewise avoid smokes that give advantage to human enemies based on some metric like that.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After watching a friend try the game the other evening, I decided that for the scope of this review, I'd like to make the use of smokes somewhat conservative, avoiding disoriented humans and enemies that could exploit the smoke screen. (As one may guess, the very first thing they did was walk into a smoke cloud and then immediately became lost for the duration. 🥲 )
Then another PR could explore a more sophisticated handling of smokes. For example, maybe we could calculate a path to the smoke target, estimate the movement time needed, and figure out if a player could realistically reach and view the smoke based on their class movement.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've definitely entered the bikeshed, but: it might be interesting to try a kind of VR Chaperone style effect inside smokes, to represent the in-smoke fumbling player having tactile feedback of physically hitting/brushing against the wall (it's basically solving for the same thing IRL):
I imagine this might be able to reuse the friendly HUD X-ray shader stuff, but I'm not too familiar with that code.
Definitely, I think we should implement some kind of code to calculate the full flight path of a grenade ahead of time, and that could be used for stuff like these bot throws, but also for training modes to practice nade throws etc like in CS (the smaller PiP screens show where that nade is going to land):