Skip to content

Commit 8cfdc9f

Browse files
authored
Refine bot proactive reload criteria (#1768)
* Consolidate and refactor reload logic into ReloadIfLowClip * Check if firearm in IsLineOfFirePenetrationClear
1 parent 97e65e6 commit 8cfdc9f

8 files changed

Lines changed: 77 additions & 37 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ ActionResult< CNEOBot > CNEOBotAttack::Update( CNEOBot *me, float interval )
7171
// SUPA7 reload can be interrupted so proactively reload
7272
if (myWeapon && (myWeapon->GetNeoWepBits() & NEO_WEP_SUPA7) && (myWeapon->Clip1() < myWeapon->GetMaxClip1()))
7373
{
74-
me->ReleaseFireButton();
75-
me->PressReloadButton();
74+
me->ReloadIfLowClip(true);
7675
}
7776

7877
if ( threat->IsVisibleRecently() )

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,9 @@ void CNEOBotMainAction::FireWeaponAtEnemy( CNEOBot *me )
622622
{
623623
if ( myWeapon->Clip1() <= 0 )
624624
{
625-
me->ReleaseFireButton();
626625
me->EnableCloak(3.0f);
627626
m_isWaitingForFullReload = true;
628-
me->PressReloadButton();
627+
me->ReloadIfLowClip(true);
629628
}
630629

631630
if ( m_isWaitingForFullReload )
@@ -670,8 +669,7 @@ void CNEOBotMainAction::FireWeaponAtEnemy( CNEOBot *me )
670669

671670
if (myWeapon->Clip1() <= 0)
672671
{
673-
me->ReleaseFireButton();
674-
me->PressReloadButton();
672+
me->ReloadIfLowClip(true);
675673
m_isWaitingForFullReload = true;
676674
}
677675

@@ -849,8 +847,7 @@ void CNEOBotMainAction::FireWeaponAtEnemy( CNEOBot *me )
849847
}
850848
else
851849
{
852-
me->ReleaseFireButton();
853-
me->PressReloadButton();
850+
me->ReloadIfLowClip(true);
854851
m_isWaitingForFullReload = true;
855852
}
856853
return;

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,10 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolf::Update( CNEOBot *me, float interval
4747
const CKnownEntity *threat = me->GetVisionInterface()->GetPrimaryKnownThreat( true );
4848

4949
CBaseCombatWeapon *pWeapon = me->GetActiveWeapon();
50-
if ( !threat && pWeapon && pWeapon->UsesClipsForAmmo1() )
50+
if ( !threat && pWeapon )
5151
{
52-
if ( pWeapon->Clip1() < pWeapon->GetMaxClip1() && me->GetAmmoCount( pWeapon->GetPrimaryAmmoType() ) > 0 )
53-
{
54-
// Aggressively reload due to lack of backup
55-
me->PressReloadButton();
56-
}
52+
// Aggressively reload due to lack of backup
53+
me->ReloadIfLowClip(true); // force reload true
5754
}
5855

5956
// We dropped the ghost to hunt a threat.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ ActionResult<CNEOBot> CNEOBotJgrCapture::OnStart( CNEOBot *me, Action<CNEOBot> *
3535

3636
// Ignore enemies while capturing juggernaut
3737
me->StopLookingAroundForEnemies();
38+
me->ReloadIfLowClip(); // might as well as we're preoccupied
3839
return Continue();
3940
}
4041

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ ActionResult< CNEOBot > CNEOBotRetreatToCover::Update( CNEOBot *me, float interv
205205
{
206206
const CKnownEntity *threat = me->GetVisionInterface()->GetPrimaryKnownThreat( true );
207207

208-
if ( threat && threat->GetEntity() && threat->GetEntity()->IsPlayer() )
208+
if (!threat)
209+
{
210+
me->ReloadIfLowClip();
211+
}
212+
else if ( threat->GetEntity() && threat->GetEntity()->IsPlayer() )
209213
{
210214
CNEO_Player *pThreatPlayer = ToNEOPlayer( threat->GetEntity() );
211215
if ( pThreatPlayer && pThreatPlayer->IsCarryingGhost() )

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,12 @@ ActionResult< CNEOBot > CNEOBotTacticalMonitor::Update( CNEOBot *me, float inter
435435
AvoidBumpingFriends( me );
436436
}
437437

438+
const CKnownEntity *threat = me->GetVisionInterface()->GetPrimaryKnownThreat();
439+
if ( !threat )
440+
{
441+
me->ReloadIfLowClip();
442+
}
443+
438444
me->UpdateDelayedThreatNotices();
439445

440446
return Continue();

src/game/server/neo/bot/neo_bot.cpp

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,40 +1573,76 @@ void CNEOBot::EquipBestWeaponForThreat(const CKnownEntity* threat, const bool bN
15731573

15741574
//-----------------------------------------------------------------------------------------------------
15751575
// Reload the active weapon if it makes sense for the situation
1576-
void CNEOBot::ReloadIfLowClip(void)
1576+
void CNEOBot::ReloadIfLowClip(bool bForceReload)
15771577
{
15781578
CNEOBaseCombatWeapon* myWeapon = static_cast<CNEOBaseCombatWeapon*>(GetActiveWeapon());
1579-
if (myWeapon && myWeapon->GetPrimaryAmmoCount() > 0)
1579+
1580+
if (!myWeapon)
1581+
{
1582+
return;
1583+
}
1584+
1585+
if (myWeapon->GetPrimaryAmmoCount() <= 0)
1586+
{
1587+
return;
1588+
}
1589+
1590+
if (myWeapon->Clip1() >= myWeapon->GetMaxClip1())
15801591
{
1581-
bool shouldReload = false;
1582-
// SUPA7 reload doesn't discard ammo
1583-
if ((myWeapon->GetNeoWepBits() & NEO_WEP_SUPA7) && (myWeapon->Clip1() < myWeapon->GetMaxClip1()))
1592+
return;
1593+
}
1594+
1595+
if (!(myWeapon->GetNeoWepBits() & NEO_WEP_FIREARM))
1596+
{
1597+
return;
1598+
}
1599+
1600+
if (myWeapon->GetNeoWepBits() & NEO_WEP_BALC)
1601+
{
1602+
return;
1603+
}
1604+
1605+
if (myWeapon->GetNeoWepBits() & NEO_WEP_SMAC)
1606+
{
1607+
return;
1608+
}
1609+
1610+
if (myWeapon->GetNeoWepBits() & NEO_WEP_SUPA7)
1611+
{
1612+
// Consider loading slug
1613+
if ( (myWeapon->m_iSecondaryAmmoCount > 0) && (myWeapon->Clip1() == myWeapon->GetMaxClip1() - 1))
15841614
{
1585-
shouldReload = true;
1615+
ReleaseFireButton();
1616+
PressAltFireButton();
1617+
return; // attempt to load slug
15861618
}
1587-
else
1619+
// SUPA7 reload doesn't discard ammo, continue
1620+
}
1621+
else if (myWeapon->Clip1() > 0)
1622+
{
1623+
auto* pPlayer = ToNEOPlayer(this);
1624+
if ( pPlayer->GetTimeSinceWeaponFired() < 3.0f)
15881625
{
1589-
int maxClip = myWeapon->GetMaxClip1();
1590-
bool isBarrage = IsBarrageAndReloadWeapon(myWeapon);
1626+
return; // still in the middle of a fight
1627+
}
15911628

1592-
int baseThreshold = isBarrage ? (maxClip / 3) : (maxClip / 2);
1629+
int maxClip = myWeapon->GetMaxClip1();
1630+
bool isBarrage = IsBarrageAndReloadWeapon(myWeapon);
15931631

1594-
float aggressionFactor = 1.0f - HealthFraction();
1632+
int baseThreshold = isBarrage ? (maxClip / 3) : (maxClip / 2);
15951633

1596-
float dynamicThreshold = baseThreshold + aggressionFactor * (maxClip - baseThreshold);
1634+
float aggressionFactor = 1.0f - HealthFraction();
15971635

1598-
if (myWeapon->Clip1() < static_cast<int>(dynamicThreshold))
1599-
{
1600-
shouldReload = true;
1601-
}
1602-
}
1636+
float dynamicThreshold = baseThreshold + aggressionFactor * (maxClip - baseThreshold);
16031637

1604-
if (shouldReload)
1638+
if (!bForceReload && myWeapon->Clip1() > static_cast<int>(dynamicThreshold))
16051639
{
1606-
ReleaseFireButton();
1607-
PressReloadButton();
1640+
return; // reloads drop ammo, still have enough in clip
16081641
}
16091642
}
1643+
1644+
ReleaseFireButton();
1645+
PressReloadButton();
16101646
}
16111647

16121648

@@ -1757,7 +1793,7 @@ bool CNEOBot::IsLineOfFirePenetrationClear(const trace_t &tr, const Vector &from
17571793

17581794
// Only bother with fire penetration in short distance
17591795
auto *neoWeapon = static_cast<CNEOBaseCombatWeapon *>(GetActiveWeapon());
1760-
if (!neoWeapon)
1796+
if (!neoWeapon || !(neoWeapon->GetNeoWepBits() & NEO_WEP_FIREARM))
17611797
{
17621798
return false;
17631799
}

src/game/server/neo/bot/neo_bot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class CNEOBot : public NextBotPlayer< CNEO_Player >, public CGameEventListener
156156

157157
bool EquipRequiredWeapon(void); // if we're required to equip a specific weapon, do it.
158158
void EquipBestWeaponForThreat(const CKnownEntity* threat, const bool bNotPrimary = false); // equip the best weapon we have to attack the given threat
159-
void ReloadIfLowClip(void);
159+
void ReloadIfLowClip(bool bForceReload = false);
160160

161161
void PushRequiredWeapon(CNEOBaseCombatWeapon* weapon); // force us to equip and use this weapon until popped off the required stack
162162
void PopRequiredWeapon(void); // pop top required weapon off of stack and discard

0 commit comments

Comments
 (0)