Skip to content

Commit d3d12db

Browse files
committed
Move bot recon superjump from TacticalMonitor to CNEOBotMainAction
1 parent 8cfdc9f commit d3d12db

4 files changed

Lines changed: 137 additions & 136 deletions

File tree

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

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ ConVar neo_bot_fire_weapon_allowed( "neo_bot_fire_weapon_allowed", "1", FCVAR_CH
3636

3737
ConVar neo_bot_allow_retreat( "neo_bot_allow_retreat", "1", FCVAR_CHEAT, "If zero, bots will not attempt to retreat if they are are in a bad situation." );
3838

39+
ConVar neo_bot_recon_superjump_min_dist( "neo_bot_recon_superjump_min_dist", "1000", FCVAR_NONE,
40+
"Minimum straight-line path distance required for a Recon bot to super jump while moving", true, 0, false, 0 );
41+
42+
ConVar neo_bot_recon_superjump_min_accuracy( "neo_bot_recon_superjump_min_accuracy", "0.95", FCVAR_NONE,
43+
"Minimum directional alignment with path required for a Recon bot to super jump while moving", true, 0.1f, false, 1.0f );
44+
3945
//---------------------------------------------------------------------------------------------
4046
Action< CNEOBot > *CNEOBotMainAction::InitialContainedAction( CNEOBot *me )
4147
{
@@ -176,6 +182,8 @@ ActionResult< CNEOBot > CNEOBotMainAction::Update( CNEOBot *me, float interval )
176182

177183
me->RepathIfFriendlyBlockingLineOfFire();
178184

185+
ReconConsiderSuperJump( me );
186+
179187
return Continue();
180188
}
181189

@@ -359,6 +367,133 @@ Vector CNEOBotMainAction::SelectTargetPoint( const INextBot *meBot, const CBaseC
359367
}
360368

361369

370+
//-----------------------------------------------------------------------------------------
371+
void CNEOBotMainAction::ReconConsiderSuperJump( CNEOBot *me )
372+
{
373+
CNEO_Player *pNeoMe = ToNEOPlayer(me);
374+
if ( !pNeoMe || pNeoMe->GetClass() != NEO_CLASS_RECON )
375+
{
376+
return;
377+
}
378+
379+
// Check that bot isn't only moving sideways which wastes aux power
380+
// Also determines a direction to jump towards
381+
// NEO Jank: We don't check sprint here because bots don't anticipate using sprint in a smart manner
382+
if ( ( pNeoMe->m_nButtons & ( IN_FORWARD | IN_BACK ) ) == 0 )
383+
{
384+
// Remove this check if we add sideways super jump in the future
385+
return;
386+
}
387+
388+
if (!pNeoMe->IsAllowedToSuperJump())
389+
{
390+
return;
391+
}
392+
393+
bool bImmediateDanger = gpGlobals->curtime - pNeoMe->GetLastDamageTime() <= 2.0f;
394+
395+
if (!bImmediateDanger
396+
&& (pNeoMe->m_nButtons & IN_FORWARD)
397+
&& (neo_bot_recon_superjump_min_dist.GetFloat() > 1))
398+
{
399+
if (!m_reconSuperJumpPathCheckTimer.IsElapsed())
400+
{
401+
return;
402+
}
403+
m_reconSuperJumpPathCheckTimer.Start(1.0f);
404+
405+
const PathFollower *path = me->GetCurrentPath();
406+
if (!path || !path->IsValid())
407+
{
408+
return;
409+
}
410+
411+
const Path::Segment *seg = path->GetCurrentGoal();
412+
if (!seg)
413+
{
414+
return;
415+
}
416+
417+
// Get the bot motion to know which direction the jump will be boosted
418+
Vector vecMovement = me->GetLocomotionInterface()->GetGroundMotionVector();
419+
vecMovement.z = 0.0f;
420+
vecMovement.NormalizeInPlace();
421+
422+
// Get the bot's facing direction
423+
Vector vecFacing;
424+
pNeoMe->EyeVectors( &vecFacing );
425+
vecFacing.z = 0.0f;
426+
vecFacing.NormalizeInPlace();
427+
428+
if (vecMovement.Dot(vecFacing) < neo_bot_recon_superjump_min_accuracy.GetFloat())
429+
{
430+
return;
431+
}
432+
433+
// Check that upcoming path is in line of a jump
434+
bool bCanJump = false;
435+
while (seg)
436+
{
437+
constexpr int maskAttributesToStopPathEval = (
438+
NAV_MESH_AVOID |
439+
NAV_MESH_CLIFF |
440+
NAV_MESH_CROUCH |
441+
NAV_MESH_HAS_ELEVATOR |
442+
NAV_MESH_JUMP | // likely to interrupt superjump trajectory
443+
NAV_MESH_NAV_BLOCKER |
444+
NAV_MESH_NO_JUMP |
445+
NAV_MESH_OBSTACLE_TOP |
446+
NAV_MESH_PRECISE |
447+
NAV_MESH_STAIRS |
448+
NAV_MESH_STOP |
449+
NAV_MESH_TRANSIENT
450+
);
451+
452+
if (seg->area && seg->area->HasAttributes( maskAttributesToStopPathEval ))
453+
{
454+
return; // Don't superjump toward areas with potentially problematic attributes
455+
}
456+
457+
// Sanity check that each waypoint is relatively aligned with our jump direction
458+
Vector vecToWaypoint = seg->pos - pNeoMe->GetAbsOrigin();
459+
vecToWaypoint.z = 0.0f;
460+
461+
float flDist = vecToWaypoint.NormalizeInPlace();
462+
463+
if (vecMovement.Dot(vecToWaypoint) < neo_bot_recon_superjump_min_accuracy.GetFloat())
464+
{
465+
return; // Diverges too much from trajectory
466+
}
467+
468+
if (flDist >= neo_bot_recon_superjump_min_dist.GetFloat())
469+
{
470+
bCanJump = true;
471+
break;
472+
}
473+
else if (flDist < 0)
474+
{
475+
return; // Just in case of a bad value
476+
}
477+
478+
seg = path->NextSegment(seg);
479+
}
480+
481+
if (!bCanJump)
482+
{
483+
return;
484+
}
485+
}
486+
487+
// NEO Jank: We allow bots to super jump even if they didn't perform the prerequisite inputs
488+
// For example, they don't consistently hold sprint when it's appropriate so we just boost their speed
489+
me->GetLocomotionInterface()->Run();
490+
me->PressRunButton();
491+
me->GetLocomotionInterface()->Jump();
492+
me->PressJumpButton();
493+
me->SuperJump();
494+
}
495+
496+
362497
//---------------------------------------------------------------------------------------------
363498
/**
364499
* Allow bot to approve of positions game movement tries to put him into.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class CNEOBotMainAction : public Action< CNEOBot >, public CNEOBotContextualQuer
4040

4141
private:
4242
CountdownTimer m_reloadTimer;
43+
CountdownTimer m_reconSuperJumpPathCheckTimer;
4344
mutable CountdownTimer m_aimAdjustTimer;
4445
mutable float m_aimErrorRadius;
4546
mutable float m_aimErrorAngle;
@@ -67,6 +68,7 @@ class CNEOBotMainAction : public Action< CNEOBot >, public CNEOBotContextualQuer
6768

6869

6970
void Dodge( CNEOBot *me );
71+
void ReconConsiderSuperJump(CNEOBot *me);
7072

7173
IntervalTimer m_undergroundTimer;
7274

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

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -177,138 +177,6 @@ void CNEOBotTacticalMonitor::AvoidBumpingFriends( CNEOBot *me )
177177
}
178178

179179

180-
ConVar neo_bot_recon_superjump_min_dist( "neo_bot_recon_superjump_min_dist", "1000", FCVAR_NONE,
181-
"Minimum straight-line path distance required for a Recon bot to super jump while moving", true, 0, false, 0 );
182-
183-
ConVar neo_bot_recon_superjump_min_accuracy( "neo_bot_recon_superjump_min_accuracy", "0.95", FCVAR_NONE,
184-
"Minimum directional alignment with path required for a Recon bot to super jump while moving", true, 0.1f, false, 1.0f );
185-
186-
//-----------------------------------------------------------------------------------------
187-
void CNEOBotTacticalMonitor::ReconConsiderSuperJump( CNEOBot *me )
188-
{
189-
CNEO_Player *pNeoMe = ToNEOPlayer(me);
190-
if ( !pNeoMe || pNeoMe->GetClass() != NEO_CLASS_RECON )
191-
{
192-
return;
193-
}
194-
195-
// Check that bot isn't only moving sideways which wastes aux power
196-
// Also determines a direction to jump towards
197-
// NEO Jank: We don't check sprint here because bots don't anticipate using sprint in a smart manner
198-
if ( ( pNeoMe->m_nButtons & ( IN_FORWARD | IN_BACK ) ) == 0 )
199-
{
200-
// Remove this check if we add sideways super jump in the future
201-
return;
202-
}
203-
204-
if (!pNeoMe->IsAllowedToSuperJump())
205-
{
206-
return;
207-
}
208-
209-
bool bImmediateDanger = gpGlobals->curtime - pNeoMe->GetLastDamageTime() <= 2.0f;
210-
211-
if (!bImmediateDanger
212-
&& (pNeoMe->m_nButtons & IN_FORWARD)
213-
&& (neo_bot_recon_superjump_min_dist.GetFloat() > 1))
214-
{
215-
if (!m_reconSuperJumpPathCheckTimer.IsElapsed())
216-
{
217-
return;
218-
}
219-
m_reconSuperJumpPathCheckTimer.Start(1.0f);
220-
221-
const PathFollower *path = me->GetCurrentPath();
222-
if (!path || !path->IsValid())
223-
{
224-
return;
225-
}
226-
227-
const Path::Segment *seg = path->GetCurrentGoal();
228-
if (!seg)
229-
{
230-
return;
231-
}
232-
233-
// Get the bot motion to know which direction the jump will be boosted
234-
Vector vecMovement = me->GetLocomotionInterface()->GetGroundMotionVector();
235-
vecMovement.z = 0.0f;
236-
vecMovement.NormalizeInPlace();
237-
238-
// Get the bot's facing direction
239-
Vector vecFacing;
240-
pNeoMe->EyeVectors( &vecFacing );
241-
vecFacing.z = 0.0f;
242-
vecFacing.NormalizeInPlace();
243-
244-
if (vecMovement.Dot(vecFacing) < neo_bot_recon_superjump_min_accuracy.GetFloat())
245-
{
246-
return;
247-
}
248-
249-
// Check that upcoming path is in line of a jump
250-
bool bCanJump = false;
251-
while (seg)
252-
{
253-
constexpr int maskAttributesToStopPathEval = (
254-
NAV_MESH_AVOID |
255-
NAV_MESH_CLIFF |
256-
NAV_MESH_CROUCH |
257-
NAV_MESH_HAS_ELEVATOR |
258-
NAV_MESH_JUMP | // likely to interrupt superjump trajectory
259-
NAV_MESH_NAV_BLOCKER |
260-
NAV_MESH_NO_JUMP |
261-
NAV_MESH_OBSTACLE_TOP |
262-
NAV_MESH_PRECISE |
263-
NAV_MESH_STAIRS |
264-
NAV_MESH_STOP |
265-
NAV_MESH_TRANSIENT
266-
);
267-
268-
if (seg->area && seg->area->HasAttributes( maskAttributesToStopPathEval ))
269-
{
270-
return; // Don't superjump toward areas with potentially problematic attributes
271-
}
272-
273-
// Sanity check that each waypoint is relatively aligned with our jump direction
274-
Vector vecToWaypoint = seg->pos - pNeoMe->GetAbsOrigin();
275-
vecToWaypoint.z = 0.0f;
276-
277-
float flDist = vecToWaypoint.NormalizeInPlace();
278-
279-
if (vecMovement.Dot(vecToWaypoint) < neo_bot_recon_superjump_min_accuracy.GetFloat())
280-
{
281-
return; // Diverges too much from trajectory
282-
}
283-
284-
if (flDist >= neo_bot_recon_superjump_min_dist.GetFloat())
285-
{
286-
bCanJump = true;
287-
break;
288-
}
289-
else if (flDist < 0)
290-
{
291-
return; // Just in case of a bad value
292-
}
293-
294-
seg = path->NextSegment(seg);
295-
}
296-
297-
if (!bCanJump)
298-
{
299-
return;
300-
}
301-
}
302-
303-
// NEO Jank: We allow bots to super jump even if they didn't perform the prerequisite inputs
304-
// For example, they don't consistently hold sprint when it's appropriate so we just boost their speed
305-
me->GetLocomotionInterface()->Run();
306-
me->PressRunButton();
307-
me->GetLocomotionInterface()->Jump();
308-
me->PressJumpButton();
309-
me->SuperJump();
310-
}
311-
312180

313181
//-----------------------------------------------------------------------------------------
314182
ActionResult< CNEOBot > CNEOBotTacticalMonitor::WatchForLadders( CNEOBot *me )
@@ -363,8 +231,6 @@ ActionResult< CNEOBot > CNEOBotTacticalMonitor::Update( CNEOBot *me, float inter
363231
}
364232
}
365233

366-
ReconConsiderSuperJump( me );
367-
368234
CBaseEntity *dangerousGrenade = CNEOBotRetreatFromGrenade::FindDangerousGrenade( me );
369235
if ( dangerousGrenade )
370236
{

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class CNEOBotTacticalMonitor : public Action< CNEOBot >
2121

2222
private:
2323
CountdownTimer m_maintainTimer;
24-
CountdownTimer m_reconSuperJumpPathCheckTimer;
2524

2625
CountdownTimer m_acknowledgeAttentionTimer;
2726
CountdownTimer m_acknowledgeRetryTimer;
@@ -35,6 +34,5 @@ class CNEOBotTacticalMonitor : public Action< CNEOBot >
3534
ActionResult< CNEOBot > ScavengeForPrimaryWeapon(CNEOBot* me);
3635

3736
void AvoidBumpingFriends(CNEOBot* me);
38-
void ReconConsiderSuperJump(CNEOBot *me);
3937
ActionResult< CNEOBot > WatchForLadders(CNEOBot* me);
4038
};

0 commit comments

Comments
 (0)