22#include " bot/neo_bot.h"
33#include " bot/behavior/neo_bot_seek_weapon.h"
44#include " bot/neo_bot_path_compute.h"
5- #include " tier1/utlstringmap.h"
65#include " weapon_neobasecombatweapon.h"
76#include " neo_player_shared.h"
87#include " nav_mesh.h"
9- #include < bit>
108
119// ---------------------------------------------------------------------------------------------
1210// Mask of non-identity "tag" bits that GetNeoWepBits() may include
@@ -19,7 +17,12 @@ static constexpr int BOT_WEP_PREF_RANK_EMPTY = -2;
1917// ---------------------------------------------------------------------------------------------
2018bool IsUndroppablePrimary ( CBaseCombatWeapon *pPrimary )
2119{
22- CNEOBaseCombatWeapon *pNeoWep = assert_cast<CNEOBaseCombatWeapon*>( pPrimary );
20+ if ( !pPrimary )
21+ {
22+ return false ;
23+ }
24+
25+ CNEOBaseCombatWeapon *pNeoWep = ToNEOWeapon ( pPrimary );
2326 if ( !pNeoWep )
2427 {
2528 return false ;
@@ -128,7 +131,7 @@ CBaseEntity *FindNearestPrimaryWeapon( CNEOBot *me, bool bAllowDropGhost, CNEOIg
128131 {
129132 myPrefRank = BOT_WEP_PREF_RANK_UNPREFERRED;
130133 bHasReserveAmmo = pPrimary->GetPrimaryAmmoCount () > 0 ;
131- CNEOBaseCombatWeapon *pMyNeoWep = assert_cast<CNEOBaseCombatWeapon*> ( pPrimary-> MyCombatWeaponPointer () );
134+ CNEOBaseCombatWeapon *pMyNeoWep = ToNEOWeapon ( pPrimary );
132135 if ( pMyNeoWep )
133136 {
134137 myPrefRank = GetBotWeaponPreferenceRank ( me, pMyNeoWep->GetNeoWepBits () );
@@ -159,7 +162,7 @@ CBaseEntity *FindNearestPrimaryWeapon( CNEOBot *me, bool bAllowDropGhost, CNEOIg
159162 continue ;
160163 }
161164
162- CNEOBaseCombatWeapon *pNeoWeapon = assert_cast<CNEOBaseCombatWeapon*>( pWeapon);
165+ CNEOBaseCombatWeapon *pNeoWeapon = ToNEOWeapon ( pWeapon );
163166 if ( !pNeoWeapon )
164167 {
165168 continue ;
@@ -249,11 +252,11 @@ ActionResult< CNEOBot > CNEOBotSeekWeapon::OnStart( CNEOBot *me, Action< CNEOBot
249252 CBaseCombatWeapon *pPrimary = me->Weapon_GetSlot ( 0 );
250253 if ( IsUndroppablePrimary ( pPrimary ) )
251254 {
252- // Don't scavenge if we have an weapon like the balc or smac
255+ // Don't scavenge if we have a weapon like the balc or smac
253256 return Done (" Equipped with an un-droppable weapon, will not seek" );
254257 }
255258
256- if ( !m_hTargetWeapon || m_hTargetWeapon. Get () == nullptr )
259+ if ( !m_hTargetWeapon )
257260 {
258261 m_hTargetWeapon = FindNearestPrimaryWeapon ( me, false , m_pIgnoredWeapons );
259262 }
@@ -276,7 +279,7 @@ ActionResult< CNEOBot > CNEOBotSeekWeapon::OnStart( CNEOBot *me, Action< CNEOBot
276279// ---------------------------------------------------------------------------------------------
277280ActionResult< CNEOBot > CNEOBotSeekWeapon::Update ( CNEOBot *me, float interval )
278281{
279- if (!m_hTargetWeapon || m_hTargetWeapon. Get () == nullptr )
282+ if ( !m_hTargetWeapon )
280283 {
281284 return Done (" No weapon to seek" );
282285 }
@@ -317,13 +320,18 @@ ActionResult< CNEOBot > CNEOBotSeekWeapon::Update( CNEOBot *me, float interval )
317320 if ( pPrimary )
318321 {
319322 int myPrefRank = BOT_WEP_PREF_RANK_UNPREFERRED;
320- CNEOBaseCombatWeapon *pMyNeoWep = assert_cast<CNEOBaseCombatWeapon*> ( pPrimary-> MyCombatWeaponPointer () );
323+ CNEOBaseCombatWeapon *pMyNeoWep = ToNEOWeapon ( pPrimary );
321324 if ( pMyNeoWep )
322325 {
323326 myPrefRank = GetBotWeaponPreferenceRank ( me, pMyNeoWep->GetNeoWepBits () );
324327 }
325328
326- CNEOBaseCombatWeapon *pTargetNeoWep = assert_cast<CNEOBaseCombatWeapon*>( m_hTargetWeapon->MyCombatWeaponPointer () );
329+ CNEOBaseCombatWeapon *pTargetNeoWep = ToNEOWeapon ( m_hTargetWeapon.Get () );
330+ if ( !pTargetNeoWep )
331+ {
332+ return Done ( " Target weapon is invalid or not a NEO weapon" );
333+ }
334+
327335 const bool bIsUpgrade = IsWeaponPreferenceUpgrade ( me, pTargetNeoWep, myPrefRank, pPrimary->GetPrimaryAmmoCount () > 0 );
328336
329337 if ( bIsUpgrade )
@@ -352,7 +360,10 @@ ActionResult< CNEOBot > CNEOBotSeekWeapon::OnResume( CNEOBot *me, Action< CNEOBo
352360{
353361 m_hTargetWeapon = nullptr ;
354362 m_repathTimer.Invalidate ();
355- FindAndPathToWeapon (me);
363+ if ( !FindAndPathToWeapon ( me ) )
364+ {
365+ return Done ( " No weapon found on resume" );
366+ }
356367 return Continue ();
357368}
358369
@@ -368,7 +379,7 @@ EventDesiredResult< CNEOBot > CNEOBotSeekWeapon::OnStuck( CNEOBot *me )
368379// ---------------------------------------------------------------------------------------------
369380EventDesiredResult< CNEOBot > CNEOBotSeekWeapon::OnMoveToSuccess ( CNEOBot *me, const Path *path )
370381{
371- return TryContinue ();
382+ return TryDone ();
372383}
373384
374385// ---------------------------------------------------------------------------------------------
0 commit comments