Skip to content

Commit 431cb92

Browse files
committed
Code review feedback pass
1 parent 4dba7f5 commit 431cb92

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed

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

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
//---------------------------------------------------------------------------------------------
1818
CNEOBotCtgLoneWolf::CNEOBotCtgLoneWolf( void )
1919
{
20-
m_hGhost = nullptr;
2120
m_bPursuingDropThreat = false;
2221
m_vecDropThreatPos = CNEO_Player::VECTOR_INVALID_WAYPOINT;
2322
m_closestCapturePoint = CNEO_Player::VECTOR_INVALID_WAYPOINT;
@@ -26,7 +25,6 @@ CNEOBotCtgLoneWolf::CNEOBotCtgLoneWolf( void )
2625
//---------------------------------------------------------------------------------------------
2726
ActionResult< CNEOBot > CNEOBotCtgLoneWolf::OnStart( CNEOBot *me, Action< CNEOBot > *priorAction )
2827
{
29-
m_hGhost = nullptr;
3028
m_hPursueTarget = nullptr;
3129
m_bPursuingDropThreat = false;
3230
m_useAttemptTimer.Invalidate();
@@ -84,7 +82,7 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolf::Update( CNEOBot *me, float interval
8482
}
8583

8684
// Always need to find the ghost to act on it
87-
if ( !UpdateGhostHandle( me ) )
85+
if ( !GetGhost() )
8886
{
8987
return Done( "Ghost not found" );
9088
}
@@ -99,7 +97,7 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolf::Update( CNEOBot *me, float interval
9997
float flDistGhostToGoal = FLT_MAX;
10098
if ( m_closestCapturePoint != CNEO_Player::VECTOR_INVALID_WAYPOINT )
10199
{
102-
const Vector& vecStart = me->IsCarryingGhost() ? me->GetAbsOrigin() : m_hGhost->GetAbsOrigin();
100+
const Vector& vecStart = GetGhostPosition( me );
103101
flDistGhostToGoal = vecStart.DistTo( m_closestCapturePoint );
104102
}
105103

@@ -112,7 +110,7 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolf::Update( CNEOBot *me, float interval
112110
float flMyTotalDist = flDistGhostToGoal;
113111
if ( !me->IsCarryingGhost() )
114112
{
115-
flMyTotalDist += me->GetAbsOrigin().DistTo( m_hGhost->GetAbsOrigin() );
113+
flMyTotalDist += me->GetAbsOrigin().DistTo( GetGhostPosition( me ) );
116114
}
117115

118116
// Count enemies and find if one is closer to our goal
@@ -150,7 +148,7 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolf::Update( CNEOBot *me, float interval
150148

151149
bool bSafeToCap = ((m_closestCapturePoint != CNEO_Player::VECTOR_INVALID_WAYPOINT) && (flMyTotalDistSq < flClosestEnemyDistToGoalSq));
152150

153-
CWeaponGhost *pGhostWeapon = m_hGhost.Get();
151+
CWeaponGhost *pGhostWeapon = GetGhost();
154152
CBaseCombatCharacter *pGhostOwner = pGhostWeapon ? pGhostWeapon->GetOwner() : nullptr;
155153
bool bGhostHeldByEnemy = (pGhostOwner && pGhostOwner->GetTeamNumber() != me->GetTeamNumber());
156154

@@ -249,7 +247,7 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolf::Update( CNEOBot *me, float interval
249247

250248
if ( !m_repathTimer.HasStarted() || m_repathTimer.IsElapsed() )
251249
{
252-
CNEOBotPathCompute(me, m_path, m_hGhost->GetAbsOrigin(), FASTEST_ROUTE);
250+
CNEOBotPathCompute(me, m_path, GetGhostPosition( me ), FASTEST_ROUTE);
253251
m_path.Update(me);
254252
m_repathTimer.Start( RandomFloat( 0.3f, 0.5f ) );
255253
}
@@ -264,7 +262,7 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolf::Update( CNEOBot *me, float interval
264262
// Ghost is free for taking
265263
if ( bSafeToCap || (bIs1v1 && m_stalemateTimer.HasStarted() && m_stalemateTimer.IsElapsed()) )
266264
{
267-
float flDistToGhostSq = me->GetAbsOrigin().DistToSqr(m_hGhost->GetAbsOrigin());
265+
float flDistToGhostSq = me->GetAbsOrigin().DistToSqr(GetGhostPosition( me ));
268266
float flAmbushDistSq = CNEOBotCtgLoneWolf::GetDetpackDeployDistanceSq( me );
269267

270268
if ( flDistToGhostSq < flAmbushDistSq)
@@ -276,13 +274,13 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolf::Update( CNEOBot *me, float interval
276274
else
277275
{
278276
// Try to cap before enemy can stop us.
279-
return SuspendFor(new CNEOBotCtgCapture(m_hGhost.Get()), "Picking up ghost to make a run for it!");
277+
return SuspendFor(new CNEOBotCtgCapture(GetGhost()), "Picking up ghost to make a run for it!");
280278
}
281279
}
282280

283281
if ( !m_repathTimer.HasStarted() || m_repathTimer.IsElapsed() )
284282
{
285-
CNEOBotPathCompute(me, m_path, m_hGhost->GetAbsOrigin(), FASTEST_ROUTE);
283+
CNEOBotPathCompute(me, m_path, GetGhostPosition( me ), FASTEST_ROUTE);
286284
m_path.Update(me);
287285
m_repathTimer.Start( RandomFloat( 0.2f, 0.5f ) );
288286
}
@@ -303,7 +301,7 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolf::Update( CNEOBot *me, float interval
303301
}
304302

305303
// Hide out of sight of ghost to ambush anyone that picks up the ghost
306-
float flDistToGhostSq = me->GetAbsOrigin().DistToSqr(m_hGhost->GetAbsOrigin());
304+
float flDistToGhostSq = me->GetAbsOrigin().DistToSqr(GetGhostPosition( me ));
307305
float flAmbushDistSq = CNEOBotCtgLoneWolf::GetDetpackDeployDistanceSq( me );
308306
if (flDistToGhostSq < flAmbushDistSq)
309307
{
@@ -314,7 +312,7 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolf::Update( CNEOBot *me, float interval
314312
// Get near the ghost first before surveying hiding spots
315313
if ( !m_repathTimer.HasStarted() || m_repathTimer.IsElapsed() )
316314
{
317-
CNEOBotPathCompute(me, m_path, m_hGhost->GetAbsOrigin(), FASTEST_ROUTE);
315+
CNEOBotPathCompute(me, m_path, GetGhostPosition( me ), FASTEST_ROUTE);
318316
m_path.Update(me);
319317
m_repathTimer.Start( RandomFloat( 0.5f, 1.0f ) );
320318
}
@@ -391,7 +389,7 @@ Vector CNEOBotCtgLoneWolf::GetNearestCapturePoint( CNEOBot *me, bool bEnemyCapPo
391389

392390
if ( NEORules()->m_pGhostCaps.Count() > 0 )
393391
{
394-
const Vector& vecStart = me->IsCarryingGhost() ? me->GetAbsOrigin() : ( m_hGhost.Get() ? m_hGhost->GetAbsOrigin() : me->GetAbsOrigin() );
392+
const Vector& vecStart = GetGhostPosition( me );
395393

396394
for( int i=0; i<NEORules()->m_pGhostCaps.Count(); ++i )
397395
{
@@ -446,14 +444,31 @@ class CCollectPotentiallyVisibleAreas
446444
};
447445

448446
//---------------------------------------------------------------------------------------------
449-
bool CNEOBotCtgLoneWolf::UpdateGhostHandle( CNEOBot *me )
447+
Vector CNEOBotCtgLoneWolf::GetGhostPosition( CNEOBot *me )
450448
{
451-
if ( !m_hGhost )
449+
if ( me->IsCarryingGhost() )
452450
{
453-
m_hGhost = dynamic_cast<CWeaponGhost*>( gEntList.FindEntityByClassname( nullptr, "weapon_ghost" ) );
451+
return me->GetAbsOrigin();
452+
}
453+
454+
CWeaponGhost *pGhost = GetGhost();
455+
if ( pGhost )
456+
{
457+
CBaseEntity *pParent = pGhost->GetMoveParent();
458+
if ( pParent )
459+
{
460+
return pParent->GetAbsOrigin();
461+
}
462+
return pGhost->GetAbsOrigin();
454463
}
455464

456-
return ( m_hGhost != nullptr );
465+
return me->GetAbsOrigin();
466+
}
467+
468+
//---------------------------------------------------------------------------------------------
469+
CWeaponGhost* CNEOBotCtgLoneWolf::GetGhost()
470+
{
471+
return NEORules()->m_pGhost;
457472
}
458473

459474
//---------------------------------------------------------------------------------------------

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class CNEOBotCtgLoneWolf : public Action< CNEOBot >
2222
protected:
2323
static float GetDetpackDeployDistanceSq( CNEOBot *me );
2424
Vector GetNearestCapturePoint( CNEOBot *me, bool bEnemyCapPoint );
25-
bool UpdateGhostHandle( CNEOBot *me );
25+
Vector GetGhostPosition( CNEOBot *me );
26+
CWeaponGhost* GetGhost();
2627
ActionResult< CNEOBot > UpdateLookAround( CNEOBot *me );
2728

28-
CHandle<CWeaponGhost> m_hGhost;
2929
CountdownTimer m_repathTimer;
3030
PathFollower m_path;
3131

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolfAmbush::OnStart( CNEOBot *me, Action<
5050
//---------------------------------------------------------------------------------------------
5151
ActionResult< CNEOBot > CNEOBotCtgLoneWolfAmbush::Update( CNEOBot *me, float interval )
5252
{
53-
if ( !UpdateGhostHandle( me ) )
53+
if ( !GetGhost() )
5454
{
5555
return Done( "Ghost not found" );
5656
}
@@ -63,7 +63,7 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolfAmbush::Update( CNEOBot *me, float int
6363
// For now, assume the bot is forgetful of exact detpack deploy location and uses ghost beacon as reference
6464
// We could trace line of sight to the detpack, but most of the time bot is hiding around a corner
6565
// Players could move ghost by shooting it, but ideally the bot would investigate the gunshot sources
66-
Vector myVecDetpackPosChoice = m_hGhost->GetAbsOrigin(); // ghost can be moved
66+
Vector myVecDetpackPosChoice = GetGhostPosition( me ); // ghost can be moved
6767
float myDistToDetpackPosChoiceSq = me->GetAbsOrigin().DistToSqr( myVecDetpackPosChoice );
6868

6969
const CKnownEntity *threat = me->GetVisionInterface()->GetPrimaryKnownThreat( true );
@@ -111,7 +111,7 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolfAmbush::Update( CNEOBot *me, float int
111111
// Move closer to ghost
112112
if ( !m_repathTimer.HasStarted() || m_repathTimer.IsElapsed() )
113113
{
114-
CNEOBotPathCompute( me, m_path, m_hGhost->GetAbsOrigin(), FASTEST_ROUTE );
114+
CNEOBotPathCompute( me, m_path, GetGhostPosition( me ), FASTEST_ROUTE );
115115
m_path.Update( me );
116116
m_repathTimer.Start( 0.5f );
117117

@@ -127,9 +127,9 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolfAmbush::Update( CNEOBot *me, float int
127127
else if ( me->IsCarryingGhost() )
128128
{
129129
// Drop ghost if accidentally picked it up and have set up ambush/detpack
130-
if (me->GetActiveWeapon() != m_hGhost )
130+
if (me->GetActiveWeapon() != GetGhost() )
131131
{
132-
me->Weapon_Switch( m_hGhost );
132+
me->Weapon_Switch( GetGhost() );
133133
}
134134
else
135135
{
@@ -198,7 +198,7 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolfAmbush::Update( CNEOBot *me, float int
198198

199199
// Detpack trigger condition checks
200200
bool bShouldDetonate = false;
201-
CBaseCombatCharacter *pGhostOwner = m_hGhost ? m_hGhost->GetOwner() : nullptr;
201+
CBaseCombatCharacter *pGhostOwner = GetGhost() ? GetGhost()->GetOwner() : nullptr;
202202

203203
if (!bIsDetpackDeployed)
204204
{
@@ -285,7 +285,7 @@ ActionResult< CNEOBot > CNEOBotCtgLoneWolfAmbush::Update( CNEOBot *me, float int
285285
}
286286

287287
// Check if the sound happened within the detpack radius around the ghost
288-
float distSqr = pSound->GetSoundOrigin().DistToSqr( m_hGhost->GetAbsOrigin() );
288+
float distSqr = pSound->GetSoundOrigin().DistToSqr( GetGhostPosition( me ) );
289289
if ( distSqr <= Square( NEO_DETPACK_DAMAGE_RADIUS * flThreshold ) )
290290
{
291291
bTriggerDetpack = true;

0 commit comments

Comments
 (0)