From f4f681e8d41907513df4dc212eddde3f283d6154 Mon Sep 17 00:00:00 2001 From: Kenzzer Date: Sat, 12 Oct 2024 22:17:30 +0200 Subject: [PATCH 1/5] Enable locomotion interface --- .../sourcesdk/NextBot/NextBotInterface.cpp | 4 +- .../sourcesdk/NextBot/NextBotInterface.h | 7 +- .../NextBot/NextBotLocomotionInterface.cpp | 316 ++++++++++++++++++ .../NextBot/NextBotLocomotionInterface.h | 243 +++++++++++--- extension/toolsnextbot.h | 1 - 5 files changed, 518 insertions(+), 53 deletions(-) diff --git a/extension/sourcesdk/NextBot/NextBotInterface.cpp b/extension/sourcesdk/NextBot/NextBotInterface.cpp index df91c88..144ea04 100644 --- a/extension/sourcesdk/NextBot/NextBotInterface.cpp +++ b/extension/sourcesdk/NextBot/NextBotInterface.cpp @@ -39,8 +39,8 @@ INextBot::~INextBot() if (m_IntentionInterface) delete m_IntentionInterface; - /*if (m_LocoInterface) - delete m_LocoInterface;*/ + if (m_LocoInterface) + delete m_LocoInterface; if (m_BodyInterface) delete m_BodyInterface; diff --git a/extension/sourcesdk/NextBot/NextBotInterface.h b/extension/sourcesdk/NextBot/NextBotInterface.h index 9b90664..f818340 100644 --- a/extension/sourcesdk/NextBot/NextBotInterface.h +++ b/extension/sourcesdk/NextBot/NextBotInterface.h @@ -8,6 +8,7 @@ #include "NextBotDebug.h" #include "NextBotBodyInterface.h" #include "NextBotIntentionInterface.h" +#include "NextBotLocomotionInterface.h" #include "sourcesdk/tracefilter_simple.h" #include "sourcesdk/basecombatcharacter.h" #include @@ -51,7 +52,7 @@ class INextBot : public INextBotEventResponder virtual CBaseCombatCharacter* GetEntity() const = 0; virtual NextBotCombatCharacter *GetNextBotCombatCharacter() const { return nullptr; }; - virtual ILocomotion *GetLocomotionInterface() const = 0; + virtual ILocomotion *GetLocomotionInterface() const; virtual IBody *GetBodyInterface() const; virtual IIntention *GetIntentionInterface() const; virtual IVision *GetVisionInterface() const = 0; @@ -189,7 +190,7 @@ inline void INextBot::NotifyPathDestruction( const PathFollower *path ) m_CurrentPath = nullptr; } -/*inline ILocomotion *INextBot::GetLocomotionInterface( void ) const +inline ILocomotion *INextBot::GetLocomotionInterface( void ) const { if ( m_LocoInterface == nullptr ) { @@ -197,7 +198,7 @@ inline void INextBot::NotifyPathDestruction( const PathFollower *path ) } return m_LocoInterface; -}*/ +} inline IBody *INextBot::GetBodyInterface( void ) const { diff --git a/extension/sourcesdk/NextBot/NextBotLocomotionInterface.cpp b/extension/sourcesdk/NextBot/NextBotLocomotionInterface.cpp index 80e8b51..8f70644 100644 --- a/extension/sourcesdk/NextBot/NextBotLocomotionInterface.cpp +++ b/extension/sourcesdk/NextBot/NextBotLocomotionInterface.cpp @@ -42,4 +42,320 @@ bool ILocomotion::Init(SourceMod::IGameConfig* config, char* error, size_t maxle } return true; +} + +ILocomotion::ILocomotion( INextBot *bot ) : INextBotComponent( bot ) +{ + Reset(); +} + +ILocomotion::~ILocomotion() +{ +} + +void ILocomotion::Reset( void ) +{ + INextBotComponent::Reset(); + + m_motionVector = Vector( 1.0f, 0.0f, 0.0f ); + m_speed = 0.0f; + m_groundMotionVector = m_motionVector; + m_groundSpeed = m_speed; + + m_moveRequestTimer.Invalidate(); + + m_isStuck = false; + m_stuckTimer.Invalidate(); + m_stuckPos = vec3_origin; +} + +void ILocomotion::Update( void ) +{ + StuckMonitor(); + + // maintain motion vector and speed values + const Vector &vel = GetVelocity(); + m_speed = vel.Length(); + m_groundSpeed = vel.AsVector2D().Length(); + + const float velocityThreshold = 10.0f; + if ( m_speed > velocityThreshold ) + { + m_motionVector = vel / m_speed; + } + + if ( m_groundSpeed > velocityThreshold ) + { + m_groundMotionVector.x = vel.x / m_groundSpeed; + m_groundMotionVector.y = vel.y / m_groundSpeed; + m_groundMotionVector.z = 0.0f; + } +} + +void ILocomotion::AdjustPosture( const Vector &moveGoal ) +{ + IBody *body = GetBot()->GetBodyInterface(); + if ( !body->IsActualPosture( IBody::STAND ) && !body->IsActualPosture( IBody::CROUCH ) ) + return; + + const Vector &mins = body->GetHullMins() + Vector( 0, 0, GetStepHeight() ); + + const float halfSize = body->GetHullWidth()/2.0f; + Vector standMaxs( halfSize, halfSize, body->GetStandHullHeight() ); + + trace_t trace; + NextBotTraversableTraceFilter filter( GetBot(), ILocomotion::IMMEDIATELY ); + + // snap forward movement vector along floor + const Vector &groundNormal = GetGroundNormal(); + const Vector &feet = GetFeet(); + Vector moveDir = moveGoal - feet; + float moveLength = moveDir.NormalizeInPlace(); + Vector left( -moveDir.y, moveDir.x, 0.0f ); + Vector goal = feet + moveLength * CrossProduct( left, groundNormal ).Normalized(); + + TraceHull( feet, goal, mins, standMaxs, body->GetSolidMask(), &filter, &trace ); + + if ( trace.fraction >= 1.0f && !trace.startsolid ) + { + // no collision while standing + if ( body->IsActualPosture( IBody::CROUCH ) ) + { + body->SetDesiredPosture( IBody::STAND ); + } + return; + } + + if ( body->IsActualPosture( IBody::CROUCH ) ) + return; + + // crouch hull check + Vector crouchMaxs( halfSize, halfSize, body->GetCrouchHullHeight() ); + + TraceHull( feet, goal, mins, crouchMaxs, body->GetSolidMask(), &filter, &trace ); + + if ( trace.fraction >= 1.0f && !trace.startsolid ) + { + // no collision while crouching + body->SetDesiredPosture( IBody::CROUCH ); + } +} + +void ILocomotion::Approach( const Vector &goalPos, float goalWeight ) +{ + m_moveRequestTimer.Start(); +} + +void ILocomotion::DriveTo( const Vector &pos ) +{ + m_moveRequestTimer.Start(); +} + +bool ILocomotion::IsPotentiallyTraversable( const Vector &from, const Vector &to, TraverseWhenType when, float *fraction ) const +{ + VPROF_BUDGET( "Locomotion::IsPotentiallyTraversable", "NextBotExpensive" ); + + if ( ( to.z - from.z ) > GetMaxJumpHeight() + 0.1f ) + { + Vector along = to - from; + along.NormalizeInPlace(); + if ( along.z > GetTraversableSlopeLimit() ) + { + if ( fraction ) + { + *fraction = 0.0f; + } + return false; + } + } + + trace_t result; + NextBotTraversableTraceFilter filter( GetBot(), when ); + + const float probeSize = 0.25f * GetBot()->GetBodyInterface()->GetHullWidth(); + const float probeZ = GetStepHeight(); + + Vector hullMin( -probeSize, -probeSize, probeZ ); + Vector hullMax( probeSize, probeSize, GetBot()->GetBodyInterface()->GetCrouchHullHeight() ); + TraceHull( from, to, hullMin, hullMax, GetBot()->GetBodyInterface()->GetSolidMask(), &filter, &result ); + + if ( fraction ) + { + *fraction = result.fraction; + } + + return ( result.fraction >= 1.0f ) && ( !result.startsolid ); +} + +bool ILocomotion::HasPotentialGap( const Vector &from, const Vector &desiredTo, float *fraction ) const +{ + VPROF_BUDGET( "Locomotion::HasPotentialGap", "NextBot" ); + + float traversableFraction; + IsPotentiallyTraversable( from, desiredTo, IMMEDIATELY, &traversableFraction ); + + // compute end of traversable ray + Vector to = from + ( desiredTo - from ) * traversableFraction; + + Vector forward = to - from; + float length = forward.NormalizeInPlace(); + + IBody *body = GetBot()->GetBodyInterface(); + + float step = body->GetHullWidth()/2.0f; + + Vector pos = from; + Vector delta = step * forward; + for( float t = 0.0f; t < (length + step); t += step ) + { + if ( IsGap( pos, forward ) ) + { + if ( fraction ) + { + *fraction = ( t - step ) / ( length + step ); + } + + return true; + } + + pos += delta; + } + + if ( fraction ) + { + *fraction = 1.0f; + } + + return false; +} + +bool ILocomotion::IsGap( const Vector &pos, const Vector &forward ) const +{ + VPROF_BUDGET( "Locomotion::IsGap", "NextBotSpiky" ); + + IBody *body = GetBot()->GetBodyInterface(); + + const float halfWidth = 1.0f; + const float hullHeight = 1.0f; + + unsigned int mask = ( body ) ? body->GetSolidMask() : MASK_PLAYERSOLID; + + trace_t ground; + + NextBotTraceFilterIgnoreActors filter( GetBot()->GetEntity(), COLLISION_GROUP_NONE ); + + TraceHull( pos + Vector( 0, 0, GetStepHeight() ), // start up a bit to handle rough terrain + pos + Vector( 0, 0, -GetMaxJumpHeight() ), + Vector( -halfWidth, -halfWidth, 0 ), Vector( halfWidth, halfWidth, hullHeight ), + mask, &filter, &ground ); + return ( ground.fraction >= 1.0f && !ground.startsolid ); +} + +bool ILocomotion::IsEntityTraversable( CBaseEntity *obstacle, TraverseWhenType when ) const +{ + if ( obstacle->IsWorld() ) + return false; + + if ( FClassnameIs( obstacle, "prop_door*" ) || FClassnameIs( obstacle, "func_door*" ) ) + { + CBasePropDoor *door = dynamic_cast< CBasePropDoor * >( obstacle ); + + if ( door && door->IsDoorOpen() ) + { + // open doors are obstacles + return false; + } + + return true; + } + + if ( FClassnameIs( obstacle, "func_brush" ) ) + { + CFuncBrush *brush = (CFuncBrush *)obstacle; + + switch ( brush->m_iSolidity ) + { + case CFuncBrush::BRUSHSOLID_ALWAYS: + return false; + case CFuncBrush::BRUSHSOLID_NEVER: + return true; + case CFuncBrush::BRUSHSOLID_TOGGLE: + return true; + } + } + + if ( when == IMMEDIATELY ) + { + return false; + } + + return GetBot()->IsAbleToBreak( obstacle ); +} + +bool ILocomotion::IsAreaTraversable( const CNavArea *baseArea ) const +{ + return !baseArea->IsBlocked( GetBot()->GetEntity()->GetTeamNumber() ); +} + +void ILocomotion::ClearStuckStatus( const char *reason ) +{ + if ( IsStuck() ) + { + m_isStuck = false; + GetBot()->OnUnStuck(); + } + + m_stuckPos = GetFeet(); + m_stuckTimer.Start(); +} + +void ILocomotion::StuckMonitor( void ) +{ + const float idleTime = 0.25f; + if ( m_moveRequestTimer.IsGreaterThen( idleTime ) ) + { + m_stuckPos = GetFeet(); + m_stuckTimer.Start(); + + return; + } + + if ( IsStuck() ) + { + if ( GetBot()->IsRangeGreaterThan( m_stuckPos, STUCK_RADIUS ) ) + { + ClearStuckStatus( "UN-STUCK" ); + } + else + { + if ( m_stillStuckTimer.IsElapsed() ) + { + m_stillStuckTimer.Start( 1.0f ); + GetBot()->OnStuck(); + } + } + } + else + { + if ( GetBot()->IsRangeGreaterThan( m_stuckPos, STUCK_RADIUS ) ) + { + m_stuckPos = GetFeet(); + m_stuckTimer.Start(); + } + else + { + float minMoveSpeed = 0.1f * GetDesiredSpeed() + 0.1f; + float escapeTime = STUCK_RADIUS / minMoveSpeed; + if ( m_stuckTimer.IsGreaterThen( escapeTime ) ) + { + m_isStuck = true; + GetBot()->OnStuck(); + } + } + } +} + +const Vector &ILocomotion::GetFeet( void ) const +{ + return GetBot()->GetEntity()->GetAbsOrigin(); } \ No newline at end of file diff --git a/extension/sourcesdk/NextBot/NextBotLocomotionInterface.h b/extension/sourcesdk/NextBot/NextBotLocomotionInterface.h index 8d42392..f43e362 100644 --- a/extension/sourcesdk/NextBot/NextBotLocomotionInterface.h +++ b/extension/sourcesdk/NextBot/NextBotLocomotionInterface.h @@ -12,91 +12,90 @@ class ILocomotion : public INextBotComponent public: static bool Init(SourceMod::IGameConfig* config, char* error, size_t maxlength); - virtual ~ILocomotion() {}; + ILocomotion(INextBot* bot); + virtual ~ILocomotion(); - virtual void Reset(void) = 0; - virtual void Update(void) = 0; - virtual void Approach(const Vector& goalPos, float goalWeight = 1.0f) = 0; - virtual void DriveTo(const Vector& pos) = 0; + virtual void Reset(void); + virtual void Update(void); + virtual void Approach(const Vector& goalPos, float goalWeight = 1.0f); + virtual void DriveTo(const Vector& pos); virtual bool ClimbUpToLedge(const Vector& landingGoal, const Vector& landingForward, const CBaseEntity* obstacle) { return true; } virtual void JumpAcrossGap(const Vector& landingGoal, const Vector& landingForward) { } virtual void Jump(void) { }; - virtual bool IsClimbingOrJumping(void) const = 0; - virtual bool IsClimbingUpToLedge(void) const = 0; - virtual bool IsJumpingAcrossGap(void) const = 0; - virtual bool IsScrambling(void) const = 0; + virtual bool IsClimbingOrJumping(void) const; + virtual bool IsClimbingUpToLedge(void) const; + virtual bool IsJumpingAcrossGap(void) const; + virtual bool IsScrambling(void) const; virtual void Run(void) { }; virtual void Walk(void) { }; virtual void Stop(void) { }; - virtual bool IsRunning(void) const = 0; + virtual bool IsRunning(void) const; virtual void SetDesiredSpeed(float speed) { }; - virtual float GetDesiredSpeed(void) const = 0; + virtual float GetDesiredSpeed(void) const; virtual void SetSpeedLimit(float speed) { }; virtual float GetSpeedLimit(void) const { return 1000.0f; }; - virtual bool IsOnGround(void) const = 0; + virtual bool IsOnGround(void) const; virtual void OnLeaveGround(CBaseEntity* ground) { }; virtual void OnLandOnGround(CBaseEntity* ground) { }; - virtual CBaseEntity* GetGround(void) const = 0; - virtual const Vector& GetGroundNormal(void) const = 0; - virtual float GetGroundSpeed(void) const = 0; - virtual const Vector& GetGroundMotionVector(void) const = 0; + virtual CBaseEntity* GetGround(void) const; + virtual const Vector& GetGroundNormal(void) const; + virtual float GetGroundSpeed(void) const; + virtual const Vector& GetGroundMotionVector(void) const; virtual void ClimbLadder(const CNavLadder* ladder, const CNavArea* dismountGoal) { }; virtual void DescendLadder(const CNavLadder* ladder, const CNavArea* dismountGoal) { }; - virtual bool IsUsingLadder(void) const = 0; - virtual bool IsAscendingOrDescendingLadder(void) const = 0; + virtual bool IsUsingLadder(void) const; + virtual bool IsAscendingOrDescendingLadder(void) const; virtual bool IsAbleToAutoCenterOnLadder(void) const { return false; }; virtual void FaceTowards(const Vector& target) { }; virtual void SetDesiredLean(const QAngle& lean) { }; - virtual const QAngle& GetDesiredLean(void) const = 0; - virtual bool IsAbleToJumpAcrossGaps(void) const = 0; - virtual bool IsAbleToClimb(void) const = 0; + virtual const QAngle& GetDesiredLean(void) const; + virtual bool IsAbleToJumpAcrossGaps(void) const; + virtual bool IsAbleToClimb(void) const; - virtual const Vector& GetFeet(void) const = 0; + virtual const Vector& GetFeet(void) const; - virtual float GetStepHeight(void) const = 0; - virtual float GetMaxJumpHeight(void) const = 0; - virtual float GetDeathDropHeight(void) const = 0; + virtual float GetStepHeight(void) const; + virtual float GetMaxJumpHeight(void) const; + virtual float GetDeathDropHeight(void) const; - virtual float GetRunSpeed(void) const = 0; - virtual float GetWalkSpeed(void) const = 0; + virtual float GetRunSpeed(void) const; + virtual float GetWalkSpeed(void) const; - virtual float GetMaxAcceleration(void) const = 0; - virtual float GetMaxDeceleration(void) const = 0; + virtual float GetMaxAcceleration(void) const; + virtual float GetMaxDeceleration(void) const; - virtual const Vector& GetVelocity(void) const = 0; - virtual float GetSpeed(void) const = 0; - virtual const Vector& GetMotionVector(void) const = 0; + virtual const Vector& GetVelocity(void) const; + virtual float GetSpeed(void) const; + virtual const Vector& GetMotionVector(void) const; - virtual bool IsAreaTraversable(const CNavArea* baseArea) const = 0; + virtual bool IsAreaTraversable(const CNavArea* baseArea) const; - virtual float GetTraversableSlopeLimit(void) const = 0; + virtual float GetTraversableSlopeLimit(void) const; enum TraverseWhenType { IMMEDIATELY, EVENTUALLY }; - virtual bool IsPotentiallyTraversable(const Vector& from, const Vector& to, TraverseWhenType when = EVENTUALLY, float* fraction = NULL) const = 0; - virtual bool HasPotentialGap(const Vector& from, const Vector& to, float* fraction = NULL) const = 0; - virtual bool IsGap(const Vector& pos, const Vector& forward) const = 0; - virtual bool IsEntityTraversable(CBaseEntity* obstacle, TraverseWhenType when = EVENTUALLY) const = 0; - virtual bool IsStuck(void) const = 0; - virtual float GetStuckDuration(void) const = 0; - virtual void ClearStuckStatus(const char* reason = "") = 0; + virtual bool IsPotentiallyTraversable(const Vector& from, const Vector& to, TraverseWhenType when = EVENTUALLY, float* fraction = NULL) const; + virtual bool HasPotentialGap(const Vector& from, const Vector& to, float* fraction = NULL) const; + virtual bool IsGap(const Vector& pos, const Vector& forward) const; + virtual bool IsEntityTraversable(CBaseEntity* obstacle, TraverseWhenType when = EVENTUALLY) const; + virtual bool IsStuck(void) const; + virtual float GetStuckDuration(void) const; + virtual void ClearStuckStatus(const char* reason = ""); - virtual bool IsAttemptingToMove(void) const = 0; + virtual bool IsAttemptingToMove(void) const; void TraceHull(const Vector& start, const Vector& end, const Vector& mins, const Vector& maxs, unsigned int fMask, ITraceFilter* pFilter, trace_t* pTrace) const; - virtual bool ShouldCollideWith(const CBaseEntity* object) const = 0; + virtual bool ShouldCollideWith(const CBaseEntity* object) const; - - //protected: they should be protected but we need to expose them to our natives - virtual void AdjustPosture(const Vector& moveGoal) = 0; - virtual void StuckMonitor(void) = 0; + virtual void AdjustPosture(const Vector& moveGoal); + virtual void StuckMonitor(void); protected: Vector m_motionVector; @@ -127,6 +126,156 @@ class ILocomotion : public INextBotComponent static VCall vShouldCollideWith; }; +inline bool ILocomotion::IsAbleToJumpAcrossGaps( void ) const +{ + return true; +} + +inline bool ILocomotion::IsAbleToClimb( void ) const +{ + return true; +} + +inline bool ILocomotion::IsAttemptingToMove( void ) const +{ + return m_moveRequestTimer.HasStarted() && m_moveRequestTimer.GetElapsedTime() < 0.25f; +} + +inline bool ILocomotion::IsScrambling( void ) const +{ + return !IsOnGround() || IsClimbingOrJumping() || IsAscendingOrDescendingLadder(); +} + +inline bool ILocomotion::IsClimbingOrJumping( void ) const +{ + return false; +} + +inline bool ILocomotion::IsClimbingUpToLedge( void ) const +{ + return false; +} + +inline bool ILocomotion::IsJumpingAcrossGap( void ) const +{ + return false; +} + +inline bool ILocomotion::IsRunning( void ) const +{ + return false; +} + +inline float ILocomotion::GetDesiredSpeed( void ) const +{ + return 0.0f; +} + +inline bool ILocomotion::IsOnGround( void ) const +{ + return false; +} + +inline CBaseEntity *ILocomotion::GetGround( void ) const +{ + return NULL; +} + +inline const Vector &ILocomotion::GetGroundNormal( void ) const +{ + return vec3_origin; +} + +inline float ILocomotion::GetGroundSpeed( void ) const +{ + return m_groundSpeed; +} + +inline const Vector & ILocomotion::GetGroundMotionVector( void ) const +{ + return m_groundMotionVector; +} + +inline bool ILocomotion::IsUsingLadder( void ) const +{ + return false; +} + +inline bool ILocomotion::IsAscendingOrDescendingLadder( void ) const +{ + return false; +} + +inline const QAngle &ILocomotion::GetDesiredLean( void ) const +{ + return vec3_angle; +} + +inline float ILocomotion::GetStepHeight( void ) const +{ + return 0.0f; +} + +inline float ILocomotion::GetMaxJumpHeight( void ) const +{ + return 0.0f; +} + +inline float ILocomotion::GetDeathDropHeight( void ) const +{ + return 0.0f; +} + +inline float ILocomotion::GetRunSpeed( void ) const +{ + return 0.0f; +} + +inline float ILocomotion::GetWalkSpeed( void ) const +{ + return 0.0f; +} + +inline float ILocomotion::GetMaxAcceleration( void ) const +{ + return 0.0f; +} + +inline float ILocomotion::GetMaxDeceleration( void ) const +{ + return 0.0f; +} + +inline const Vector &ILocomotion::GetVelocity( void ) const +{ + return vec3_origin; +} + +inline float ILocomotion::GetSpeed( void ) const +{ + return m_speed; +} + +inline const Vector & ILocomotion::GetMotionVector( void ) const +{ + return m_motionVector; +} + +inline float ILocomotion::GetTraversableSlopeLimit( void ) const +{ + return 0.6; +} + +inline bool ILocomotion::IsStuck( void ) const +{ + return m_isStuck; +} + +inline float ILocomotion::GetStuckDuration( void ) const +{ + return ( IsStuck() ) ? m_stuckTimer.GetElapsedTime() : 0.0f; +} + inline void ILocomotion::TraceHull(const Vector& start, const Vector& end, const Vector& mins, const Vector& maxs, unsigned int fMask, ITraceFilter* pFilter, trace_t* pTrace) const { Ray_t ray; diff --git a/extension/toolsnextbot.h b/extension/toolsnextbot.h index 488987f..1fa3a6a 100644 --- a/extension/toolsnextbot.h +++ b/extension/toolsnextbot.h @@ -16,7 +16,6 @@ class ToolsNextBot : public INextBot virtual CBaseCombatCharacter* GetEntity() const override { return m_linkedEntity; } virtual NextBotCombatCharacter* GetNextBotCombatCharacter() const override { return nullptr; }; - virtual ILocomotion *GetLocomotionInterface() const override { return nullptr; }; virtual IVision *GetVisionInterface() const override { return nullptr; }; protected: From cf931c54030263a79caf9535950a9ad7c39301bd Mon Sep 17 00:00:00 2001 From: Kenzzer Date: Sat, 12 Oct 2024 22:18:26 +0200 Subject: [PATCH 2/5] bump version --- product.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/product.version b/product.version index 1b1bfae..32bd932 100644 --- a/product.version +++ b/product.version @@ -1 +1 @@ -1.11.3 \ No newline at end of file +1.12.0 \ No newline at end of file From 3382ac346ba7ff56e2fd9fd1fe598335e66fee2e Mon Sep 17 00:00:00 2001 From: Kenzzer Date: Sat, 12 Oct 2024 22:24:05 +0200 Subject: [PATCH 3/5] add missing vprof --- extension/sourcesdk/NextBot/NextBotLocomotionInterface.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/extension/sourcesdk/NextBot/NextBotLocomotionInterface.cpp b/extension/sourcesdk/NextBot/NextBotLocomotionInterface.cpp index 8f70644..7c64727 100644 --- a/extension/sourcesdk/NextBot/NextBotLocomotionInterface.cpp +++ b/extension/sourcesdk/NextBot/NextBotLocomotionInterface.cpp @@ -1,5 +1,6 @@ #include "sourcesdk/NextBot/NextBotLocomotionInterface.h" +#include "tier0/vprof.h" VCall ILocomotion::vClimbUpToLedge; VCall ILocomotion::vJumpAcrossGap; From 04e199bbd0846e733db1ee2aa5acad6e482a7b80 Mon Sep 17 00:00:00 2001 From: Kenzzer Date: Sat, 12 Oct 2024 22:38:53 +0200 Subject: [PATCH 4/5] Add missing includes --- .../NextBot/NextBotLocomotionInterface.cpp | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/extension/sourcesdk/NextBot/NextBotLocomotionInterface.cpp b/extension/sourcesdk/NextBot/NextBotLocomotionInterface.cpp index 7c64727..727a68a 100644 --- a/extension/sourcesdk/NextBot/NextBotLocomotionInterface.cpp +++ b/extension/sourcesdk/NextBot/NextBotLocomotionInterface.cpp @@ -1,7 +1,14 @@ #include "sourcesdk/NextBot/NextBotLocomotionInterface.h" +#include "sourcesdk/NextBot/NextBotBodyInterface.h" +#include "sourcesdk/NextBot/NextBotInterface.h" +#include "sourcesdk/funcbrush.h" +#include "sourcesdk/nav_area.h" +#include "sourcesdk/tracefilter_simple.h" #include "tier0/vprof.h" +#define STUCK_RADIUS 100.0f + VCall ILocomotion::vClimbUpToLedge; VCall ILocomotion::vJumpAcrossGap; VCall ILocomotion::vIsClimbingUpToLedge; @@ -45,6 +52,37 @@ bool ILocomotion::Init(SourceMod::IGameConfig* config, char* error, size_t maxle return true; } +class NextBotTraversableTraceFilter : public ToolsTraceFilterSimple +{ +public: + NextBotTraversableTraceFilter( INextBot *bot, ILocomotion::TraverseWhenType when = ILocomotion::EVENTUALLY ) : ToolsTraceFilterSimple( bot->GetEntity(), COLLISION_GROUP_NONE ) + { + m_bot = bot; + m_when = when; + } + + virtual bool ShouldHitEntity( IHandleEntity *pServerEntity, int contentsMask ) + { + CBaseEntity *entity = EntityFromEntityHandle( pServerEntity ); + + if ( m_bot->IsSelf( entity ) ) + { + return false; + } + + if ( ToolsTraceFilterSimple::ShouldHitEntity( pServerEntity, contentsMask ) ) + { + return !m_bot->GetLocomotionInterface()->IsEntityTraversable( entity, m_when ); + } + + return false; + } + +private: + INextBot *m_bot; + ILocomotion::TraverseWhenType m_when; +}; + ILocomotion::ILocomotion( INextBot *bot ) : INextBotComponent( bot ) { Reset(); @@ -261,11 +299,11 @@ bool ILocomotion::IsEntityTraversable( CBaseEntity *obstacle, TraverseWhenType w { CBasePropDoor *door = dynamic_cast< CBasePropDoor * >( obstacle ); - if ( door && door->IsDoorOpen() ) + /*if ( door && door->IsDoorOpen() ) { // open doors are obstacles return false; - } + }*/ return true; } @@ -274,7 +312,7 @@ bool ILocomotion::IsEntityTraversable( CBaseEntity *obstacle, TraverseWhenType w { CFuncBrush *brush = (CFuncBrush *)obstacle; - switch ( brush->m_iSolidity ) + switch ( brush->GetSolidity() ) { case CFuncBrush::BRUSHSOLID_ALWAYS: return false; From 9dc4f72a7ae2a9e93bef2bcc67a4cd694ad45c53 Mon Sep 17 00:00:00 2001 From: Kenzzer Date: Sat, 12 Oct 2024 22:46:22 +0200 Subject: [PATCH 5/5] thanks msvc --- extension/sourcesdk/NextBot/NextBotLocomotionInterface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/sourcesdk/NextBot/NextBotLocomotionInterface.h b/extension/sourcesdk/NextBot/NextBotLocomotionInterface.h index f43e362..f94ce38 100644 --- a/extension/sourcesdk/NextBot/NextBotLocomotionInterface.h +++ b/extension/sourcesdk/NextBot/NextBotLocomotionInterface.h @@ -92,7 +92,7 @@ class ILocomotion : public INextBotComponent void TraceHull(const Vector& start, const Vector& end, const Vector& mins, const Vector& maxs, unsigned int fMask, ITraceFilter* pFilter, trace_t* pTrace) const; - virtual bool ShouldCollideWith(const CBaseEntity* object) const; + virtual bool ShouldCollideWith(const CBaseEntity* object) const { return true; }; virtual void AdjustPosture(const Vector& moveGoal); virtual void StuckMonitor(void);