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.

309 lines
8.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "tier0/vprof.h"
  8. #include "animation.h"
  9. #include "studio.h"
  10. #include "apparent_velocity_helper.h"
  11. #include "utldict.h"
  12. #include "portal_playeranimstate.h"
  13. #include "base_playeranimstate.h"
  14. #ifdef CLIENT_DLL
  15. #include "c_portal_player.h"
  16. #include "c_weapon_portalgun.h"
  17. #else
  18. #include "portal_player.h"
  19. #include "weapon_portalgun.h"
  20. #endif
  21. #define PORTAL_RUN_SPEED 320.0f
  22. #define PORTAL_CROUCHWALK_SPEED 110.0f
  23. //-----------------------------------------------------------------------------
  24. // Purpose:
  25. // Input : *pPlayer -
  26. // Output : CMultiPlayerAnimState*
  27. //-----------------------------------------------------------------------------
  28. CPortalPlayerAnimState* CreatePortalPlayerAnimState( CPortal_Player *pPlayer )
  29. {
  30. // Setup the movement data.
  31. MultiPlayerMovementData_t movementData;
  32. movementData.m_flBodyYawRate = 720.0f;
  33. movementData.m_flRunSpeed = PORTAL_RUN_SPEED;
  34. movementData.m_flWalkSpeed = -1;
  35. movementData.m_flSprintSpeed = -1.0f;
  36. // Create animation state for this player.
  37. CPortalPlayerAnimState *pRet = new CPortalPlayerAnimState( pPlayer, movementData );
  38. // Specific Portal player initialization.
  39. pRet->InitPortal( pPlayer );
  40. return pRet;
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose:
  44. // Input : -
  45. //-----------------------------------------------------------------------------
  46. CPortalPlayerAnimState::CPortalPlayerAnimState()
  47. {
  48. m_pPortalPlayer = NULL;
  49. // Don't initialize Portal specific variables here. Init them in InitPortal()
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Purpose:
  53. // Input : *pPlayer -
  54. // &movementData -
  55. //-----------------------------------------------------------------------------
  56. CPortalPlayerAnimState::CPortalPlayerAnimState( CBasePlayer *pPlayer, MultiPlayerMovementData_t &movementData )
  57. : CMultiPlayerAnimState( pPlayer, movementData )
  58. {
  59. m_pPortalPlayer = NULL;
  60. // Don't initialize Portal specific variables here. Init them in InitPortal()
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Purpose:
  64. // Input : -
  65. //-----------------------------------------------------------------------------
  66. CPortalPlayerAnimState::~CPortalPlayerAnimState()
  67. {
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose: Initialize Portal specific animation state.
  71. // Input : *pPlayer -
  72. //-----------------------------------------------------------------------------
  73. void CPortalPlayerAnimState::InitPortal( CPortal_Player *pPlayer )
  74. {
  75. m_pPortalPlayer = pPlayer;
  76. m_bInAirWalk = false;
  77. m_flHoldDeployedPoseUntilTime = 0.0f;
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Purpose:
  81. //-----------------------------------------------------------------------------
  82. void CPortalPlayerAnimState::ClearAnimationState( void )
  83. {
  84. m_bInAirWalk = false;
  85. BaseClass::ClearAnimationState();
  86. }
  87. //-----------------------------------------------------------------------------
  88. // Purpose:
  89. // Input : actDesired -
  90. // Output : Activity
  91. //-----------------------------------------------------------------------------
  92. Activity CPortalPlayerAnimState::TranslateActivity( Activity actDesired )
  93. {
  94. Activity translateActivity = BaseClass::TranslateActivity( actDesired );
  95. if ( GetPortalPlayer()->GetActiveWeapon() )
  96. {
  97. translateActivity = GetPortalPlayer()->GetActiveWeapon()->ActivityOverride( translateActivity, NULL );
  98. }
  99. return translateActivity;
  100. }
  101. //-----------------------------------------------------------------------------
  102. // Purpose:
  103. // Input : event -
  104. //-----------------------------------------------------------------------------
  105. void CPortalPlayerAnimState::DoAnimationEvent( PlayerAnimEvent_t event, int nData )
  106. {
  107. Activity iWeaponActivity = ACT_INVALID;
  108. switch( event )
  109. {
  110. case PLAYERANIMEVENT_ATTACK_PRIMARY:
  111. case PLAYERANIMEVENT_ATTACK_SECONDARY:
  112. {
  113. CPortal_Player *pPlayer = GetPortalPlayer();
  114. if ( !pPlayer )
  115. return;
  116. CWeaponPortalBase *pWpn = pPlayer->GetActivePortalWeapon();
  117. if ( pWpn )
  118. {
  119. // Weapon primary fire.
  120. if ( GetBasePlayer()->GetFlags() & FL_DUCKING )
  121. {
  122. RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_ATTACK_CROUCH_PRIMARYFIRE );
  123. }
  124. else
  125. {
  126. RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_ATTACK_STAND_PRIMARYFIRE );
  127. }
  128. iWeaponActivity = ACT_VM_PRIMARYATTACK;
  129. }
  130. else // unarmed player
  131. {
  132. }
  133. break;
  134. }
  135. default:
  136. {
  137. BaseClass::DoAnimationEvent( event, nData );
  138. break;
  139. }
  140. }
  141. #ifdef CLIENT_DLL
  142. // Make the weapon play the animation as well
  143. if ( iWeaponActivity != ACT_INVALID )
  144. {
  145. CBaseCombatWeapon *pWeapon = GetPortalPlayer()->GetActiveWeapon();
  146. if ( pWeapon )
  147. {
  148. pWeapon->SendWeaponAnim( iWeaponActivity );
  149. }
  150. }
  151. #endif
  152. }
  153. //-----------------------------------------------------------------------------
  154. // Purpose:
  155. //-----------------------------------------------------------------------------
  156. void CPortalPlayerAnimState::Teleport( const Vector *pNewOrigin, const QAngle *pNewAngles, CPortal_Player* pPlayer )
  157. {
  158. QAngle absangles = pPlayer->GetAbsAngles();
  159. m_angRender = absangles;
  160. m_angRender.x = m_angRender.z = 0.0f;
  161. if ( pPlayer )
  162. {
  163. // Snap the yaw pose parameter lerping variables to face new angles.
  164. m_flCurrentFeetYaw = m_flGoalFeetYaw = m_flEyeYaw = pPlayer->EyeAngles()[YAW];
  165. }
  166. }
  167. //-----------------------------------------------------------------------------
  168. // Purpose:
  169. // Input : *idealActivity -
  170. // Output : Returns true on success, false on failure.
  171. //-----------------------------------------------------------------------------
  172. bool CPortalPlayerAnimState::HandleMoving( Activity &idealActivity )
  173. {
  174. float flSpeed = GetOuterXYSpeed();
  175. // If we move, cancel the deployed anim hold
  176. if ( flSpeed > MOVING_MINIMUM_SPEED )
  177. {
  178. m_flHoldDeployedPoseUntilTime = 0.0;
  179. idealActivity = ACT_MP_RUN;
  180. }
  181. else if ( m_flHoldDeployedPoseUntilTime > gpGlobals->curtime )
  182. {
  183. // Unless we move, hold the deployed pose for a number of seconds after being deployed
  184. idealActivity = ACT_MP_DEPLOYED_IDLE;
  185. }
  186. else
  187. {
  188. return BaseClass::HandleMoving( idealActivity );
  189. }
  190. return true;
  191. }
  192. //-----------------------------------------------------------------------------
  193. // Purpose:
  194. // Input : *idealActivity -
  195. // Output : Returns true on success, false on failure.
  196. //-----------------------------------------------------------------------------
  197. bool CPortalPlayerAnimState::HandleDucking( Activity &idealActivity )
  198. {
  199. if ( GetBasePlayer()->m_Local.m_bDucking || GetBasePlayer()->m_Local.m_bDucked )
  200. {
  201. if ( GetOuterXYSpeed() < MOVING_MINIMUM_SPEED )
  202. {
  203. idealActivity = ACT_MP_CROUCH_IDLE;
  204. }
  205. else
  206. {
  207. idealActivity = ACT_MP_CROUCHWALK;
  208. }
  209. return true;
  210. }
  211. return false;
  212. }
  213. //-----------------------------------------------------------------------------
  214. // Purpose:
  215. bool CPortalPlayerAnimState::HandleJumping( Activity &idealActivity )
  216. {
  217. Vector vecVelocity;
  218. GetOuterAbsVelocity( vecVelocity );
  219. if ( ( vecVelocity.z > 300.0f || m_bInAirWalk ) )
  220. {
  221. // Check to see if we were in an airwalk and now we are basically on the ground.
  222. if ( GetBasePlayer()->GetFlags() & FL_ONGROUND )
  223. {
  224. m_bInAirWalk = false;
  225. RestartMainSequence();
  226. RestartGesture( GESTURE_SLOT_JUMP, ACT_MP_JUMP_LAND );
  227. }
  228. else
  229. {
  230. // In an air walk.
  231. idealActivity = ACT_MP_AIRWALK;
  232. m_bInAirWalk = true;
  233. }
  234. }
  235. // Jumping.
  236. else
  237. {
  238. if ( m_bJumping )
  239. {
  240. if ( m_bFirstJumpFrame )
  241. {
  242. m_bFirstJumpFrame = false;
  243. RestartMainSequence(); // Reset the animation.
  244. }
  245. // Don't check if he's on the ground for a sec.. sometimes the client still has the
  246. // on-ground flag set right when the message comes in.
  247. else if ( gpGlobals->curtime - m_flJumpStartTime > 0.2f )
  248. {
  249. if ( GetBasePlayer()->GetFlags() & FL_ONGROUND )
  250. {
  251. m_bJumping = false;
  252. RestartMainSequence();
  253. RestartGesture( GESTURE_SLOT_JUMP, ACT_MP_JUMP_LAND );
  254. }
  255. }
  256. // if we're still jumping
  257. if ( m_bJumping )
  258. {
  259. idealActivity = ACT_MP_JUMP_START;
  260. }
  261. }
  262. }
  263. if ( m_bJumping || m_bInAirWalk )
  264. return true;
  265. return false;
  266. }