Skip to content

Commit 853d630

Browse files
committed
Abandon compile-time weapon profiles experiment
1 parent 517bb3c commit 853d630

File tree

5 files changed

+77
-62
lines changed

5 files changed

+77
-62
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ CNEOBotCtgLoneWolf::CNEOBotCtgLoneWolf( void )
2323
m_pIgnoredWeapons = std::make_unique<CNEOIgnoredWeaponsCache>();
2424
}
2525

26+
//---------------------------------------------------------------------------------------------
27+
CNEOBotCtgLoneWolf::~CNEOBotCtgLoneWolf() = default;
28+
2629
//---------------------------------------------------------------------------------------------
2730
ActionResult< CNEOBot > CNEOBotCtgLoneWolf::OnStart( CNEOBot *me, Action< CNEOBot > *priorAction )
2831
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class CNEOBotCtgLoneWolf : public Action< CNEOBot >
1010
{
1111
public:
1212
CNEOBotCtgLoneWolf( void );
13+
virtual ~CNEOBotCtgLoneWolf();
1314

1415
virtual ActionResult< CNEOBot > OnStart( CNEOBot *me, Action< CNEOBot > *priorAction ) override;
1516
virtual ActionResult< CNEOBot > Update( CNEOBot *me, float interval ) override;

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
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
//---------------------------------------------------------------------------------------------
2018
bool 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
//---------------------------------------------------------------------------------------------
277280
ActionResult< 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
//---------------------------------------------------------------------------------------------
369380
EventDesiredResult< CNEOBot > CNEOBotSeekWeapon::OnMoveToSuccess( CNEOBot *me, const Path *path )
370381
{
371-
return TryContinue();
382+
return TryDone();
372383
}
373384

374385
//---------------------------------------------------------------------------------------------

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

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -26,59 +26,45 @@ static inline CThreadMutex g_vbBotUsedMutex;
2626

2727
ConVar neo_bot_prefix_name_with_difficulty("neo_bot_prefix_name_with_difficulty", "0", FCVAR_GAMEDLL, "Append the skill level of the bot to the bot's name", true, 0.0f, true, 1.0f);
2828

29-
static constexpr CNEOBotProfile InitFixedDefaultProfile()
30-
{
31-
CNEOBotProfile profile = {
32-
// GCC 10 (Steam RT 3.0) designated initalizer bug: Cannot place = string here, fixed in 11+
29+
inline const CNEOBotProfile FIXED_DEFAULT_PROFILE = {
30+
// GCC 10 (Steam RT 3.0) designated initalizer bug: Cannot place = string here, fixed in 11+
3331
#ifdef WIN32
34-
.szName = BOT_DEFAULT_NAME,
32+
.szName = BOT_DEFAULT_NAME,
3533
#endif
36-
.flagDifficulty = BOT_DIFFICULTY_FLAG_ALL,
37-
.iDifficultyForced = -1,
38-
.flagClass = BOT_CLASS_FLAG_ALL,
39-
.flagsWepPrefs = {
40-
{
41-
// Recon
42-
NEO_WEP_SRM, // Private
43-
NEO_WEP_JITTE_S, // Corporal
44-
NEO_WEP_ZR68_C, // Sergeant
45-
NEO_WEP_SUPA7, // Lieutenant
46-
},
47-
{
48-
// Assault
49-
NEO_WEP_ZR68_S, // Private
50-
NEO_WEP_ZR68_S | NEO_WEP_M41_S, // Corporal
51-
NEO_WEP_MX, // Sergeant
52-
NEO_WEP_AA13 | NEO_WEP_SRS, // Lieutenant
53-
},
54-
{
55-
// Support
56-
NEO_WEP_ZR68_C | NEO_WEP_SUPA7, // Private
57-
NEO_WEP_MX, // Corporal
58-
NEO_WEP_MX | NEO_WEP_MX_S, // Sergeant
59-
NEO_WEP_MX | NEO_WEP_MX_S | NEO_WEP_PZ, // Lieutenant
60-
},
61-
{
62-
// VIP
63-
NEO_WEP_SMAC, // Private
64-
NEO_WEP_SRM, // Corporal
65-
NEO_WEP_SRM | NEO_WEP_JITTE, // Sergeant
66-
NEO_WEP_ZR68_C | NEO_WEP_SUPA7, // Lieutenant
67-
},
34+
.flagDifficulty = BOT_DIFFICULTY_FLAG_ALL,
35+
.iDifficultyForced = -1,
36+
.flagClass = BOT_CLASS_FLAG_ALL,
37+
.flagsWepPrefs = {
38+
{
39+
// Recon
40+
NEO_WEP_SRM, // Private
41+
NEO_WEP_JITTE_S, // Corporal
42+
NEO_WEP_ZR68_C, // Sergeant
43+
NEO_WEP_SUPA7, // Lieutenant
6844
},
69-
};
70-
71-
#ifndef WIN32
72-
const char* defName = BOT_DEFAULT_NAME;
73-
for (int i = 0; i < sizeof(profile.szName) - 1 && defName[i] != '\0'; ++i) {
74-
profile.szName[i] = defName[i];
75-
}
76-
#endif
77-
78-
return profile;
79-
}
80-
81-
const CNEOBotProfile FIXED_DEFAULT_PROFILE = InitFixedDefaultProfile();
45+
{
46+
// Assault
47+
NEO_WEP_ZR68_S, // Private
48+
NEO_WEP_ZR68_S | NEO_WEP_M41_S, // Corporal
49+
NEO_WEP_MX, // Sergeant
50+
NEO_WEP_AA13 | NEO_WEP_SRS, // Lieutenant
51+
},
52+
{
53+
// Support
54+
NEO_WEP_ZR68_C | NEO_WEP_SUPA7, // Private
55+
NEO_WEP_MX, // Corporal
56+
NEO_WEP_MX | NEO_WEP_MX_S, // Sergeant
57+
NEO_WEP_MX | NEO_WEP_MX_S | NEO_WEP_PZ, // Lieutenant
58+
},
59+
{
60+
// VIP
61+
NEO_WEP_SMAC, // Private
62+
NEO_WEP_SRM, // Corporal
63+
NEO_WEP_SRM | NEO_WEP_JITTE, // Sergeant
64+
NEO_WEP_ZR68_C | NEO_WEP_SUPA7, // Lieutenant
65+
},
66+
},
67+
};
8268

8369
template <typename FLAG>
8470
struct FlagCmp

src/game/shared/neo/weapons/weapon_neobasecombatweapon.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,18 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon
255255

256256
};
257257

258+
inline CNEOBaseCombatWeapon *ToNEOWeapon( CBaseEntity *pEntity )
259+
{
260+
if ( !pEntity )
261+
{
262+
return nullptr;
263+
}
264+
return dynamic_cast< CNEOBaseCombatWeapon* >( pEntity->MyCombatWeaponPointer() );
265+
}
266+
267+
inline CNEOBaseCombatWeapon *ToNEOWeapon( CBaseCombatWeapon *pWeapon )
268+
{
269+
return dynamic_cast< CNEOBaseCombatWeapon* >( pWeapon );
270+
}
271+
258272
#endif // WEAPON_NEO_BASECOMBATWEAPON_SHARED_H

0 commit comments

Comments
 (0)