Counter Strike : Global Offensive Source Code
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.

182 lines
5.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "player_pickup.h"
  10. #include "portal_player_shared.h"
  11. #include "igameevents.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. // player pickup utility routine
  15. void Pickup_ForcePlayerToDropThisObject( CBaseEntity *pTarget )
  16. {
  17. Warning ( "Failing to force player to drop object.\n" );
  18. AssertMsg( 0, "This function is assumed to not be needed in portal 2, if this assert fires we need to fix it." );
  19. #if 0
  20. if ( pTarget == NULL )
  21. return;
  22. IPhysicsObject *pPhysics = pTarget->VPhysicsGetObject();
  23. if ( pPhysics == NULL )
  24. return;
  25. if ( pPhysics->GetGameFlags() & FVPHYSICS_PLAYER_HELD )
  26. {
  27. CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
  28. pPlayer->ForceDropOfCarriedPhysObjects( pTarget );
  29. }
  30. #endif
  31. }
  32. void Pickup_OnPhysGunDrop( CBaseEntity *pDroppedObject, CBasePlayer *pPlayer, PhysGunDrop_t Reason )
  33. {
  34. IPlayerPickupVPhysics *pPickup = dynamic_cast<IPlayerPickupVPhysics *>(pDroppedObject);
  35. if ( pPickup )
  36. {
  37. pPickup->OnPhysGunDrop( pPlayer, Reason );
  38. }
  39. }
  40. void Pickup_OnPhysGunPickup( CBaseEntity *pPickedUpObject, CBasePlayer *pPlayer, PhysGunPickup_t reason )
  41. {
  42. IPlayerPickupVPhysics *pPickup = dynamic_cast<IPlayerPickupVPhysics *>(pPickedUpObject);
  43. if ( pPickup )
  44. {
  45. pPickup->OnPhysGunPickup( pPlayer, reason );
  46. }
  47. // send phys gun pickup item event, but only in single player
  48. if ( !g_pGameRules->IsMultiplayer() )
  49. {
  50. IGameEvent *event = gameeventmanager->CreateEvent( "physgun_pickup" );
  51. if ( event )
  52. {
  53. event->SetInt( "entindex", pPickedUpObject->entindex() );
  54. gameeventmanager->FireEvent( event );
  55. }
  56. }
  57. }
  58. bool Pickup_OnAttemptPhysGunPickup( CBaseEntity *pPickedUpObject, CBasePlayer *pPlayer, PhysGunPickup_t reason )
  59. {
  60. IPlayerPickupVPhysics *pPickup = dynamic_cast<IPlayerPickupVPhysics *>(pPickedUpObject);
  61. if ( pPickup )
  62. {
  63. return pPickup->OnAttemptPhysGunPickup( pPlayer, reason );
  64. }
  65. return true;
  66. }
  67. CBaseEntity *Pickup_OnFailedPhysGunPickup( CBaseEntity *pPickedUpObject, Vector vPhysgunPos )
  68. {
  69. IPlayerPickupVPhysics *pPickup = dynamic_cast<IPlayerPickupVPhysics *>(pPickedUpObject);
  70. if ( pPickup )
  71. {
  72. return pPickup->OnFailedPhysGunPickup( vPhysgunPos );
  73. }
  74. return NULL;
  75. }
  76. bool Pickup_GetPreferredCarryAngles( CBaseEntity *pObject, CBasePlayer *pPlayer, matrix3x4_t &localToWorld, QAngle &outputAnglesWorldSpace )
  77. {
  78. IPlayerPickupVPhysics *pPickup = dynamic_cast<IPlayerPickupVPhysics *>(pObject);
  79. if ( pPickup )
  80. {
  81. if ( pPickup->HasPreferredCarryAnglesForPlayer( pPlayer ) )
  82. {
  83. outputAnglesWorldSpace = TransformAnglesToWorldSpace( pPickup->PreferredCarryAngles(), localToWorld );
  84. return true;
  85. }
  86. }
  87. return false;
  88. }
  89. bool Pickup_ForcePhysGunOpen( CBaseEntity *pObject, CBasePlayer *pPlayer )
  90. {
  91. IPlayerPickupVPhysics *pPickup = dynamic_cast<IPlayerPickupVPhysics *>(pObject);
  92. if ( pPickup )
  93. {
  94. return pPickup->ForcePhysgunOpen( pPlayer );
  95. }
  96. return false;
  97. }
  98. AngularImpulse Pickup_PhysGunLaunchAngularImpulse( CBaseEntity *pObject, PhysGunForce_t reason )
  99. {
  100. IPlayerPickupVPhysics *pPickup = dynamic_cast<IPlayerPickupVPhysics *>(pObject);
  101. if ( pPickup != NULL && pPickup->ShouldPuntUseLaunchForces( reason ) )
  102. {
  103. return pPickup->PhysGunLaunchAngularImpulse();
  104. }
  105. return RandomAngularImpulse( -600, 600 );
  106. }
  107. Vector Pickup_DefaultPhysGunLaunchVelocity( const Vector &vecForward, float flMass )
  108. {
  109. #ifdef HL2_DLL
  110. // Calculate the velocity based on physcannon rules
  111. float flForceMax = physcannon_maxforce.GetFloat();
  112. float flForce = flForceMax;
  113. float mass = flMass;
  114. if ( mass > 100 )
  115. {
  116. mass = MIN( mass, 1000 );
  117. float flForceMin = physcannon_minforce.GetFloat();
  118. flForce = SimpleSplineRemapValClamped( mass, 100, 600, flForceMax, flForceMin );
  119. }
  120. return ( vecForward * flForce );
  121. #endif
  122. // Do the simple calculation
  123. return ( vecForward * flMass );
  124. }
  125. Vector Pickup_PhysGunLaunchVelocity( CBaseEntity *pObject, const Vector &vecForward, PhysGunForce_t reason )
  126. {
  127. // The object must be valid
  128. if ( pObject == NULL )
  129. {
  130. Assert( 0 );
  131. return vec3_origin;
  132. }
  133. // Shouldn't ever get here with a non-vphysics object.
  134. IPhysicsObject *pPhysicsObject = pObject->VPhysicsGetObject();
  135. if ( pPhysicsObject == NULL )
  136. {
  137. Assert( 0 );
  138. return vec3_origin;
  139. }
  140. // Call the pickup entity's callback
  141. IPlayerPickupVPhysics *pPickup = dynamic_cast<IPlayerPickupVPhysics *>(pObject);
  142. if ( pPickup != NULL && pPickup->ShouldPuntUseLaunchForces( reason ) )
  143. return pPickup->PhysGunLaunchVelocity( vecForward, pPhysicsObject->GetMass() );
  144. // Do our default behavior
  145. return Pickup_DefaultPhysGunLaunchVelocity( vecForward, pPhysicsObject->GetMass() );
  146. }
  147. bool Pickup_ShouldPuntUseLaunchForces( CBaseEntity *pObject, PhysGunForce_t reason )
  148. {
  149. IPlayerPickupVPhysics *pPickup = dynamic_cast<IPlayerPickupVPhysics *>(pObject);
  150. if ( pPickup )
  151. {
  152. return pPickup->ShouldPuntUseLaunchForces( reason );
  153. }
  154. return false;
  155. }