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.

110 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //
  4. //=============================================================================//
  5. #include "cbase.h"
  6. #include "tf_item.h"
  7. #include "tf_shareddefs.h"
  8. #ifdef CLIENT_DLL
  9. #include "c_tf_player.h"
  10. // NVNT haptics system interface
  11. #include "haptics/ihaptics.h"
  12. #else
  13. #include "tf_player.h"
  14. #endif
  15. IMPLEMENT_NETWORKCLASS_ALIASED( TFItem, DT_TFItem )
  16. BEGIN_NETWORK_TABLE( CTFItem, DT_TFItem )
  17. END_NETWORK_TABLE()
  18. //-----------------------------------------------------------------------------
  19. // Purpose: Identifier.
  20. //-----------------------------------------------------------------------------
  21. unsigned int CTFItem::GetItemID( void ) const
  22. {
  23. return TF_ITEM_UNDEFINED;
  24. }
  25. //-----------------------------------------------------------------------------
  26. // Purpose:
  27. //-----------------------------------------------------------------------------
  28. void CTFItem::PickUp( CTFPlayer *pPlayer, bool bInvisible )
  29. {
  30. // SetParent with attachment point - look it up later if need be!
  31. SetOwnerEntity( pPlayer );
  32. SetParent( pPlayer );
  33. SetLocalOrigin( vec3_origin );
  34. SetLocalAngles( vec3_angle );
  35. // Make invisible?
  36. if ( bInvisible )
  37. {
  38. AddEffects( EF_NODRAW );
  39. }
  40. // Add the item to the player's item inventory.
  41. pPlayer->SetItem( this );
  42. // NVNT if this is the client dll and the owner is the local
  43. // player notify the haptics system.
  44. #ifdef CLIENT_DLL
  45. if(pPlayer->IsLocalPlayer())
  46. haptics->ProcessHapticEvent(2,"Game","ctf_item_start");
  47. #endif
  48. }
  49. //-----------------------------------------------------------------------------
  50. // Purpose:
  51. //-----------------------------------------------------------------------------
  52. void CTFItem::Drop( CTFPlayer *pPlayer, bool bVisible, bool bThrown /*= false*/, bool bMessage /*= true*/ )
  53. {
  54. // Remove the item from the player's item inventory.
  55. pPlayer->SetItem( NULL );
  56. // Make visible?
  57. if ( bVisible )
  58. {
  59. RemoveEffects( EF_NODRAW );
  60. }
  61. // NVNT if this is the client dll and the owner is the local
  62. // player notify the haptics system we are dropping this item.
  63. #ifdef CLIENT_DLL
  64. if(pPlayer->IsLocalPlayer())
  65. haptics->ProcessHapticEvent(2,"Game","ctf_item_stop");
  66. #endif
  67. // Clear the parent.
  68. SetParent( NULL );
  69. SetOwnerEntity( NULL );
  70. }
  71. #ifdef CLIENT_DLL
  72. //-----------------------------------------------------------------------------
  73. // Purpose:
  74. //-----------------------------------------------------------------------------
  75. bool CTFItem::ShouldDraw()
  76. {
  77. // If I'm carrying the flag in 1st person, don't draw it
  78. if ( ToTFPlayer(GetMoveParent())->InFirstPersonView() )
  79. return false;
  80. return BaseClass::ShouldDraw();
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Should this object cast shadows?
  84. //-----------------------------------------------------------------------------
  85. ShadowType_t CTFItem::ShadowCastType()
  86. {
  87. if ( ToTFPlayer(GetMoveParent())->ShouldDrawThisPlayer() )
  88. {
  89. // Using the viewmodel.
  90. return SHADOWS_NONE;
  91. }
  92. return BaseClass::ShadowCastType();
  93. }
  94. #endif