Skip to content

Commit 99fa667

Browse files
committed
Refactor ReloadIfLowClip
1 parent 50f0f85 commit 99fa667

4 files changed

Lines changed: 60 additions & 20 deletions

File tree

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
@@ -204,7 +204,11 @@ ActionResult< CNEOBot > CNEOBotRetreatToCover::Update( CNEOBot *me, float interv
204204
{
205205
const CKnownEntity *threat = me->GetVisionInterface()->GetPrimaryKnownThreat( true );
206206

207-
if ( threat && threat->GetEntity() && threat->GetEntity()->IsPlayer() )
207+
if (!threat)
208+
{
209+
me->ReloadIfLowClip();
210+
}
211+
else if ( threat->GetEntity() && threat->GetEntity()->IsPlayer() )
208212
{
209213
CNEO_Player *pThreatPlayer = ToNEOPlayer( threat->GetEntity() );
210214
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: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,37 +1600,66 @@ void CNEOBot::EquipBestWeaponForThreat(const CKnownEntity* threat, const bool bN
16001600
void CNEOBot::ReloadIfLowClip(void)
16011601
{
16021602
CNEOBaseCombatWeapon* myWeapon = static_cast<CNEOBaseCombatWeapon*>(GetActiveWeapon());
1603-
if (myWeapon && myWeapon->GetPrimaryAmmoCount() > 0)
1603+
1604+
if (!myWeapon)
1605+
{
1606+
return;
1607+
}
1608+
1609+
if (myWeapon->GetPrimaryAmmoCount() <= 0)
1610+
{
1611+
return;
1612+
}
1613+
1614+
if (myWeapon->Clip1() >= myWeapon->GetMaxClip1())
1615+
{
1616+
return;
1617+
}
1618+
1619+
if ((myWeapon->GetNeoWepBits() & NEO_WEP_BALC))
1620+
{
1621+
return;
1622+
}
1623+
else if ((myWeapon->GetNeoWepBits() & NEO_WEP_SMAC))
1624+
{
1625+
return;
1626+
}
1627+
else if ((myWeapon->GetNeoWepBits() & NEO_WEP_SUPA7))
16041628
{
1605-
bool shouldReload = false;
1606-
// SUPA7 reload doesn't discard ammo
1607-
if ((myWeapon->GetNeoWepBits() & NEO_WEP_SUPA7) && (myWeapon->Clip1() < myWeapon->GetMaxClip1()))
1629+
// Consider loading slug
1630+
if ( (myWeapon->m_iSecondaryAmmoCount > 0) && (myWeapon->Clip1() == myWeapon->GetMaxClip1() - 1))
16081631
{
1609-
shouldReload = true;
1632+
ReleaseFireButton();
1633+
PressAltFireButton();
1634+
return; // attempt to load slug
16101635
}
1611-
else
1636+
// SUPA7 reload doesn't discard ammo, continue
1637+
}
1638+
else if (myWeapon->Clip1() > 0)
1639+
{
1640+
auto* pPlayer = ToNEOPlayer(this);
1641+
if ( pPlayer->GetTimeSinceWeaponFired() < 3.0f)
16121642
{
1613-
int maxClip = myWeapon->GetMaxClip1();
1614-
bool isBarrage = IsBarrageAndReloadWeapon(myWeapon);
1643+
return; // still in the middle of a fight
1644+
}
16151645

1616-
int baseThreshold = isBarrage ? (maxClip / 3) : (maxClip / 2);
1646+
int maxClip = myWeapon->GetMaxClip1();
1647+
bool isBarrage = IsBarrageAndReloadWeapon(myWeapon);
16171648

1618-
float aggressionFactor = 1.0f - HealthFraction();
1649+
int baseThreshold = isBarrage ? (maxClip / 3) : (maxClip / 2);
16191650

1620-
float dynamicThreshold = baseThreshold + aggressionFactor * (maxClip - baseThreshold);
1651+
float aggressionFactor = 1.0f - HealthFraction();
16211652

1622-
if (myWeapon->Clip1() < static_cast<int>(dynamicThreshold))
1623-
{
1624-
shouldReload = true;
1625-
}
1626-
}
1653+
float dynamicThreshold = baseThreshold + aggressionFactor * (maxClip - baseThreshold);
16271654

1628-
if (shouldReload)
1655+
if (myWeapon->Clip1() > static_cast<int>(dynamicThreshold))
16291656
{
1630-
ReleaseFireButton();
1631-
PressReloadButton();
1657+
return; // reloads drop ammo, still have enough in clip
16321658
}
16331659
}
1660+
1661+
ReleaseFireButton();
1662+
PressReloadButton();
16341663
}
16351664

16361665

0 commit comments

Comments
 (0)