Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. #include "cbase.h"
  3. #include "NextBot.h"
  4. #include "headless_hatman.h"
  5. #include "headless_hatman_body.h"
  6. //-------------------------------------------------------------------------------------------
  7. CHeadlessHatmanBody::CHeadlessHatmanBody( INextBot *bot ) : IBody( bot )
  8. {
  9. m_moveXPoseParameter = -1;
  10. m_moveYPoseParameter = -1;
  11. m_currentActivity = -1;
  12. }
  13. //-------------------------------------------------------------------------------------------
  14. bool CHeadlessHatmanBody::StartActivity( Activity act, unsigned int flags )
  15. {
  16. CBaseCombatCharacter *me = (CBaseCombatCharacter *)GetBot()->GetEntity();
  17. int animSequence = ::SelectWeightedSequence( me->GetModelPtr(), act, me->GetSequence() );
  18. if ( animSequence )
  19. {
  20. m_currentActivity = act;
  21. me->SetSequence( animSequence );
  22. me->SetPlaybackRate( 1.0f );
  23. me->SetCycle( 0 );
  24. me->ResetSequenceInfo();
  25. return true;
  26. }
  27. return false;
  28. }
  29. //-------------------------------------------------------------------------------------------
  30. void CHeadlessHatmanBody::Update( void )
  31. {
  32. CBaseCombatCharacter *me = (CBaseCombatCharacter *)GetBot()->GetEntity();
  33. if ( m_moveXPoseParameter < 0 )
  34. {
  35. m_moveXPoseParameter = me->LookupPoseParameter( "move_x" );
  36. }
  37. if ( m_moveYPoseParameter < 0 )
  38. {
  39. m_moveYPoseParameter = me->LookupPoseParameter( "move_y" );
  40. }
  41. // Update the pose parameters
  42. float speed = GetBot()->GetLocomotionInterface()->GetGroundSpeed(); // me->GetAbsVelocity().Length();
  43. if ( speed < 0.01f )
  44. {
  45. // stopped
  46. if ( m_moveXPoseParameter >= 0 )
  47. {
  48. me->SetPoseParameter( m_moveXPoseParameter, 0.0f );
  49. }
  50. if ( m_moveYPoseParameter >= 0 )
  51. {
  52. me->SetPoseParameter( m_moveYPoseParameter, 0.0f );
  53. }
  54. }
  55. else
  56. {
  57. Vector forward, right, up;
  58. me->GetVectors( &forward, &right, &up );
  59. const Vector &motionVector = GetBot()->GetLocomotionInterface()->GetGroundMotionVector();
  60. // move_x == 1.0 at full forward motion and -1.0 in full reverse
  61. if ( m_moveXPoseParameter >= 0 )
  62. {
  63. float forwardVel = DotProduct( motionVector, forward );
  64. me->SetPoseParameter( m_moveXPoseParameter, forwardVel );
  65. }
  66. if ( m_moveYPoseParameter >= 0 )
  67. {
  68. float sideVel = DotProduct( motionVector, right );
  69. me->SetPoseParameter( m_moveYPoseParameter, sideVel );
  70. }
  71. }
  72. // adjust animation speed to actual movement speed
  73. if ( me->m_flGroundSpeed > 0.0f )
  74. {
  75. // Clamp playback rate to avoid datatable warnings. Anything faster would look silly, anyway.
  76. float playbackRate = clamp( speed / me->m_flGroundSpeed, -4.f, 12.f );
  77. me->SetPlaybackRate( playbackRate );
  78. }
  79. // move the animation ahead in time
  80. me->StudioFrameAdvance();
  81. me->DispatchAnimEvents( me );
  82. }
  83. //---------------------------------------------------------------------------------------------
  84. // return the bot's collision mask (hack until we get a general hull trace abstraction here or in the locomotion interface)
  85. unsigned int CHeadlessHatmanBody::GetSolidMask( void ) const
  86. {
  87. return MASK_NPCSOLID | CONTENTS_PLAYERCLIP;
  88. }