diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/server/tf/halloween/headless_hatman_body.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'game/server/tf/halloween/headless_hatman_body.cpp')
| -rw-r--r-- | game/server/tf/halloween/headless_hatman_body.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/game/server/tf/halloween/headless_hatman_body.cpp b/game/server/tf/halloween/headless_hatman_body.cpp new file mode 100644 index 0000000..a7ac031 --- /dev/null +++ b/game/server/tf/halloween/headless_hatman_body.cpp @@ -0,0 +1,114 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +#include "cbase.h" + +#include "NextBot.h" +#include "headless_hatman.h" +#include "headless_hatman_body.h" + + +//------------------------------------------------------------------------------------------- +CHeadlessHatmanBody::CHeadlessHatmanBody( INextBot *bot ) : IBody( bot ) +{ + m_moveXPoseParameter = -1; + m_moveYPoseParameter = -1; + m_currentActivity = -1; +} + + +//------------------------------------------------------------------------------------------- +bool CHeadlessHatmanBody::StartActivity( Activity act, unsigned int flags ) +{ + CBaseCombatCharacter *me = (CBaseCombatCharacter *)GetBot()->GetEntity(); + + int animSequence = ::SelectWeightedSequence( me->GetModelPtr(), act, me->GetSequence() ); + + if ( animSequence ) + { + m_currentActivity = act; + me->SetSequence( animSequence ); + me->SetPlaybackRate( 1.0f ); + me->SetCycle( 0 ); + me->ResetSequenceInfo(); + + return true; + } + + return false; +} + + +//------------------------------------------------------------------------------------------- +void CHeadlessHatmanBody::Update( void ) +{ + CBaseCombatCharacter *me = (CBaseCombatCharacter *)GetBot()->GetEntity(); + + if ( m_moveXPoseParameter < 0 ) + { + m_moveXPoseParameter = me->LookupPoseParameter( "move_x" ); + } + + if ( m_moveYPoseParameter < 0 ) + { + m_moveYPoseParameter = me->LookupPoseParameter( "move_y" ); + } + + + // Update the pose parameters + float speed = GetBot()->GetLocomotionInterface()->GetGroundSpeed(); // me->GetAbsVelocity().Length(); + + if ( speed < 0.01f ) + { + // stopped + if ( m_moveXPoseParameter >= 0 ) + { + me->SetPoseParameter( m_moveXPoseParameter, 0.0f ); + } + + if ( m_moveYPoseParameter >= 0 ) + { + me->SetPoseParameter( m_moveYPoseParameter, 0.0f ); + } + } + else + { + Vector forward, right, up; + me->GetVectors( &forward, &right, &up ); + + const Vector &motionVector = GetBot()->GetLocomotionInterface()->GetGroundMotionVector(); + + // move_x == 1.0 at full forward motion and -1.0 in full reverse + if ( m_moveXPoseParameter >= 0 ) + { + float forwardVel = DotProduct( motionVector, forward ); + + me->SetPoseParameter( m_moveXPoseParameter, forwardVel ); + } + + if ( m_moveYPoseParameter >= 0 ) + { + float sideVel = DotProduct( motionVector, right ); + + me->SetPoseParameter( m_moveYPoseParameter, sideVel ); + } + } + + // adjust animation speed to actual movement speed + if ( me->m_flGroundSpeed > 0.0f ) + { + // Clamp playback rate to avoid datatable warnings. Anything faster would look silly, anyway. + float playbackRate = clamp( speed / me->m_flGroundSpeed, -4.f, 12.f ); + me->SetPlaybackRate( playbackRate ); + } + + // move the animation ahead in time + me->StudioFrameAdvance(); + me->DispatchAnimEvents( me ); +} + + +//--------------------------------------------------------------------------------------------- +// return the bot's collision mask (hack until we get a general hull trace abstraction here or in the locomotion interface) +unsigned int CHeadlessHatmanBody::GetSolidMask( void ) const +{ + return MASK_NPCSOLID | CONTENTS_PLAYERCLIP; +} |